aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs77
1 files changed, 15 insertions, 62 deletions
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index 14d68d3f3..b4a3d39c9 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -283,35 +283,11 @@ pub(super) fn element(
283 } 283 }
284} 284}
285fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) -> Highlight { 285fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) -> Highlight {
286 match def { 286 let mut h = match def {
287 Definition::Macro(m) => { 287 Definition::Macro(_) => Highlight::new(HlTag::Symbol(SymbolKind::Macro)),
288 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Macro)); 288 Definition::Field(_) => Highlight::new(HlTag::Symbol(SymbolKind::Field)),
289
290 if m.module(db).map(hir::Module::krate) != krate {
291 h |= HlMod::Library;
292 }
293
294 h
295 }
296 Definition::Field(field) => {
297 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Field));
298
299 if Some(field.parent_def(db).module(db).krate()) != krate {
300 h |= HlMod::Library;
301 }
302
303 h
304 }
305 Definition::ModuleDef(def) => match def { 289 Definition::ModuleDef(def) => match def {
306 hir::ModuleDef::Module(module) => { 290 hir::ModuleDef::Module(_) => Highlight::new(HlTag::Symbol(SymbolKind::Module)),
307 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Module));
308
309 if Some(module.krate()) != krate {
310 h |= HlMod::Library;
311 }
312
313 h
314 }
315 hir::ModuleDef::Function(func) => { 291 hir::ModuleDef::Function(func) => {
316 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function)); 292 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function));
317 if let Some(item) = func.as_assoc_item(db) { 293 if let Some(item) = func.as_assoc_item(db) {
@@ -343,9 +319,6 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
343 if func.is_async(db) { 319 if func.is_async(db) {
344 h |= HlMod::Async; 320 h |= HlMod::Async;
345 } 321 }
346 if Some(func.module(db).krate()) != krate {
347 h |= HlMod::Library;
348 }
349 322
350 h 323 h
351 } 324 }
@@ -355,23 +328,10 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
355 hir::Adt::Enum(_) => HlTag::Symbol(SymbolKind::Enum), 328 hir::Adt::Enum(_) => HlTag::Symbol(SymbolKind::Enum),
356 hir::Adt::Union(_) => HlTag::Symbol(SymbolKind::Union), 329 hir::Adt::Union(_) => HlTag::Symbol(SymbolKind::Union),
357 }; 330 };
358 let mut h = Highlight::new(h);
359
360 if Some(adt.module(db).krate()) != krate {
361 h |= HlMod::Library;
362 }
363 331
364 h 332 Highlight::new(h)
365 }
366 hir::ModuleDef::Variant(variant) => {
367 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Variant));
368
369 if Some(variant.module(db).krate()) != krate {
370 h |= HlMod::Library;
371 }
372
373 h
374 } 333 }
334 hir::ModuleDef::Variant(_) => Highlight::new(HlTag::Symbol(SymbolKind::Variant)),
375 hir::ModuleDef::Const(konst) => { 335 hir::ModuleDef::Const(konst) => {
376 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Const)); 336 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Const));
377 337
@@ -389,10 +349,6 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
389 } 349 }
390 } 350 }
391 351
392 if Some(konst.module(db).krate()) != krate {
393 h |= HlMod::Library;
394 }
395
396 h 352 h
397 } 353 }
398 hir::ModuleDef::Trait(trait_) => { 354 hir::ModuleDef::Trait(trait_) => {
@@ -402,10 +358,6 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
402 h |= HlMod::Unsafe; 358 h |= HlMod::Unsafe;
403 } 359 }
404 360
405 if Some(trait_.module(db).krate()) != krate {
406 h |= HlMod::Library;
407 }
408
409 h 361 h
410 } 362 }
411 hir::ModuleDef::TypeAlias(type_) => { 363 hir::ModuleDef::TypeAlias(type_) => {
@@ -425,10 +377,6 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
425 } 377 }
426 } 378 }
427 379
428 if Some(type_.module(db).krate()) != krate {
429 h |= HlMod::Library;
430 }
431
432 h 380 h
433 } 381 }
434 hir::ModuleDef::BuiltinType(_) => Highlight::new(HlTag::BuiltinType), 382 hir::ModuleDef::BuiltinType(_) => Highlight::new(HlTag::BuiltinType),
@@ -440,10 +388,6 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
440 h |= HlMod::Unsafe; 388 h |= HlMod::Unsafe;
441 } 389 }
442 390
443 if Some(s.module(db).krate()) != krate {
444 h |= HlMod::Library;
445 }
446
447 h 391 h
448 } 392 }
449 }, 393 },
@@ -476,7 +420,16 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
476 h 420 h
477 } 421 }
478 Definition::Label(_) => Highlight::new(HlTag::Symbol(SymbolKind::Label)), 422 Definition::Label(_) => Highlight::new(HlTag::Symbol(SymbolKind::Label)),
423 };
424
425 let is_from_other_crate = def.module(db).map(hir::Module::krate) != krate;
426 let is_builtin_type = matches!(def, Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)));
427
428 if is_from_other_crate && !is_builtin_type {
429 h |= HlMod::Library;
479 } 430 }
431
432 h
480} 433}
481 434
482fn highlight_func_by_name_ref( 435fn highlight_func_by_name_ref(