33use std:: ops:: ControlFlow ;
44
55use either:: Either ;
6- use hir:: { AsAssocItem , HasVisibility , Semantics } ;
6+ use hir:: { AsAssocItem , HasAttrs , HasVisibility , Semantics , sym } ;
77use ide_db:: {
88 FxHashMap , RootDatabase , SymbolKind ,
99 defs:: { Definition , IdentClass , NameClass , NameRefClass } ,
@@ -484,18 +484,38 @@ pub(super) fn highlight_def(
484484) -> Highlight {
485485 let db = sema. db ;
486486 let mut h = match def {
487- Definition :: Macro ( m) => Highlight :: new ( HlTag :: Symbol ( m. kind ( sema. db ) . into ( ) ) ) ,
488- Definition :: Field ( _) | Definition :: TupleField ( _) => {
489- Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Field ) )
487+ Definition :: Macro ( m) => {
488+ let mut h = Highlight :: new ( HlTag :: Symbol ( m. kind ( sema. db ) . into ( ) ) ) ;
489+ if m. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
490+ h |= HlMod :: Deprecated ;
491+ }
492+ h
490493 }
491- Definition :: Crate ( _) => {
492- Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Module ) ) | HlMod :: CrateRoot
494+ Definition :: Field ( field) => {
495+ let mut h = Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Field ) ) ;
496+ if field. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
497+ h |= HlMod :: Deprecated ;
498+ }
499+ h
500+ }
501+ Definition :: TupleField ( _) => Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Field ) ) ,
502+ Definition :: Crate ( krate) => {
503+ let mut h = Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Module ) ) | HlMod :: CrateRoot ;
504+ if krate. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
505+ h |= HlMod :: Deprecated ;
506+ }
507+
508+ h
493509 }
494510 Definition :: Module ( module) => {
495511 let mut h = Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Module ) ) ;
496512 if module. is_crate_root ( ) {
497513 h |= HlMod :: CrateRoot ;
498514 }
515+ if module. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
516+ h |= HlMod :: Deprecated ;
517+ }
518+
499519 h
500520 }
501521 Definition :: Function ( func) => {
@@ -543,19 +563,32 @@ pub(super) fn highlight_def(
543563 if func. is_const ( db) {
544564 h |= HlMod :: Const ;
545565 }
566+ if func. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
567+ h |= HlMod :: Deprecated ;
568+ }
546569
547570 h
548571 }
549572 Definition :: Adt ( adt) => {
550- let h = match adt {
573+ let mut h = Highlight :: new ( match adt {
551574 hir:: Adt :: Struct ( _) => HlTag :: Symbol ( SymbolKind :: Struct ) ,
552575 hir:: Adt :: Enum ( _) => HlTag :: Symbol ( SymbolKind :: Enum ) ,
553576 hir:: Adt :: Union ( _) => HlTag :: Symbol ( SymbolKind :: Union ) ,
554- } ;
577+ } ) ;
578+ if adt. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
579+ h |= HlMod :: Deprecated ;
580+ }
581+
582+ h
583+ }
584+ Definition :: Variant ( variant) => {
585+ let mut h = Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Variant ) ) ;
586+ if variant. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
587+ h |= HlMod :: Deprecated ;
588+ }
555589
556- Highlight :: new ( h )
590+ h
557591 }
558- Definition :: Variant ( _) => Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Variant ) ) ,
559592 Definition :: Const ( konst) => {
560593 let mut h = Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Const ) ) | HlMod :: Const ;
561594 if let Some ( item) = konst. as_assoc_item ( db) {
@@ -572,10 +605,20 @@ pub(super) fn highlight_def(
572605 }
573606 }
574607 }
608+ if konst. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
609+ h |= HlMod :: Deprecated ;
610+ }
611+
612+ h
613+ }
614+ Definition :: Trait ( trait_) => {
615+ let mut h = Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Trait ) ) ;
616+ if trait_. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
617+ h |= HlMod :: Deprecated ;
618+ }
575619
576620 h
577621 }
578- Definition :: Trait ( _) => Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Trait ) ) ,
579622 Definition :: TypeAlias ( type_) => {
580623 let mut h = Highlight :: new ( HlTag :: Symbol ( SymbolKind :: TypeAlias ) ) ;
581624
@@ -593,6 +636,9 @@ pub(super) fn highlight_def(
593636 }
594637 }
595638 }
639+ if type_. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
640+ h |= HlMod :: Deprecated ;
641+ }
596642
597643 h
598644 }
@@ -607,6 +653,9 @@ pub(super) fn highlight_def(
607653 h |= HlMod :: Unsafe ;
608654 }
609655 }
656+ if s. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) {
657+ h |= HlMod :: Deprecated ;
658+ }
610659
611660 h
612661 }
@@ -647,6 +696,9 @@ pub(super) fn highlight_def(
647696 if extern_crate. alias ( db) . is_none ( ) {
648697 highlight |= HlMod :: Library ;
649698 }
699+ if extern_crate. attrs ( db) . by_key ( sym:: deprecated) . exists ( ) {
700+ highlight |= HlMod :: Deprecated ;
701+ }
650702 highlight
651703 }
652704 Definition :: Label ( _) => Highlight :: new ( HlTag :: Symbol ( SymbolKind :: Label ) ) ,
@@ -721,6 +773,7 @@ fn highlight_method_call(
721773 let is_from_other_crate = krate. as_ref ( ) . map_or ( false , |krate| def_crate != * krate) ;
722774 let is_from_builtin_crate = def_crate. is_builtin ( sema. db ) ;
723775 let is_public = func. visibility ( sema. db ) == hir:: Visibility :: Public ;
776+ let is_deprecated = func. attrs ( sema. db ) . by_key ( sym:: deprecated) . exists ( ) ;
724777
725778 if is_from_other_crate {
726779 h |= HlMod :: Library ;
@@ -732,6 +785,10 @@ fn highlight_method_call(
732785 h |= HlMod :: DefaultLibrary ;
733786 }
734787
788+ if is_deprecated {
789+ h |= HlMod :: Deprecated ;
790+ }
791+
735792 if let Some ( self_param) = func. self_param ( sema. db ) {
736793 match self_param. access ( sema. db ) {
737794 hir:: Access :: Shared => h |= HlMod :: Reference ,
0 commit comments