3
3
use std:: ops:: ControlFlow ;
4
4
5
5
use either:: Either ;
6
- use hir:: { AsAssocItem , HasVisibility , MacroFileIdExt , Semantics } ;
6
+ use hir:: { AsAssocItem , HasVisibility , MacroFileIdExt , Semantics , SemanticsScope } ;
7
7
use ide_db:: {
8
8
FxHashMap , RootDatabase , SymbolKind ,
9
9
defs:: { Definition , IdentClass , NameClass , NameRefClass } ,
@@ -63,7 +63,7 @@ pub(super) fn token(
63
63
64
64
pub ( super ) fn name_like (
65
65
sema : & Semantics < ' _ , RootDatabase > ,
66
- krate : hir :: Crate ,
66
+ krate : Option < SemanticsScope < ' _ > > ,
67
67
bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
68
68
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
69
69
syntactic_name_ref_highlighting : bool ,
@@ -272,7 +272,7 @@ fn keyword(token: SyntaxToken, kind: SyntaxKind) -> Highlight {
272
272
273
273
fn highlight_name_ref (
274
274
sema : & Semantics < ' _ , RootDatabase > ,
275
- krate : hir :: Crate ,
275
+ krate : Option < SemanticsScope < ' _ > > ,
276
276
bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
277
277
binding_hash : & mut Option < u64 > ,
278
278
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
@@ -281,7 +281,9 @@ fn highlight_name_ref(
281
281
edition : Edition ,
282
282
) -> Highlight {
283
283
let db = sema. db ;
284
- if let Some ( res) = highlight_method_call_by_name_ref ( sema, krate, & name_ref, is_unsafe_node) {
284
+ if let Some ( res) =
285
+ highlight_method_call_by_name_ref ( sema, krate. clone ( ) , & name_ref, is_unsafe_node)
286
+ {
285
287
return res;
286
288
}
287
289
@@ -401,9 +403,11 @@ fn highlight_name_ref(
401
403
NameRefClass :: ExternCrateShorthand { decl, krate : resolved_krate } => {
402
404
let mut h = HlTag :: Symbol ( SymbolKind :: Module ) . into ( ) ;
403
405
404
- if resolved_krate != krate {
405
- h |= HlMod :: Library
406
+ if krate. as_ref ( ) . map ( |it| resolved_krate != it. krate ( ) ) . is_some_and ( |differs| differs)
407
+ {
408
+ h |= HlMod :: Library ;
406
409
}
410
+
407
411
let is_public = decl. visibility ( db) == hir:: Visibility :: Public ;
408
412
if is_public {
409
413
h |= HlMod :: Public
@@ -431,7 +435,7 @@ fn highlight_name(
431
435
bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
432
436
binding_hash : & mut Option < u64 > ,
433
437
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
434
- krate : hir :: Crate ,
438
+ krate : Option < SemanticsScope < ' _ > > ,
435
439
name : ast:: Name ,
436
440
edition : Edition ,
437
441
) -> Highlight {
@@ -476,7 +480,7 @@ fn calc_binding_hash(name: &hir::Name, shadow_count: u32) -> u64 {
476
480
477
481
pub ( super ) fn highlight_def (
478
482
sema : & Semantics < ' _ , RootDatabase > ,
479
- krate : hir :: Crate ,
483
+ krate : Option < SemanticsScope < ' _ > > ,
480
484
def : Definition ,
481
485
edition : Edition ,
482
486
is_ref : bool ,
@@ -660,7 +664,7 @@ pub(super) fn highlight_def(
660
664
} ;
661
665
662
666
let def_crate = def. krate ( db) ;
663
- let is_from_other_crate = def_crate != Some ( krate) ;
667
+ let is_from_other_crate = krate . map_or ( false , |it| def_crate != Some ( it . krate ( ) ) ) ;
664
668
let is_from_builtin_crate = def_crate. is_some_and ( |def_crate| def_crate. is_builtin ( db) ) ;
665
669
let is_builtin = matches ! (
666
670
def,
@@ -681,7 +685,7 @@ pub(super) fn highlight_def(
681
685
682
686
fn highlight_method_call_by_name_ref (
683
687
sema : & Semantics < ' _ , RootDatabase > ,
684
- krate : hir :: Crate ,
688
+ krate : Option < SemanticsScope < ' _ > > ,
685
689
name_ref : & ast:: NameRef ,
686
690
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
687
691
) -> Option < Highlight > {
@@ -691,7 +695,7 @@ fn highlight_method_call_by_name_ref(
691
695
692
696
fn highlight_method_call (
693
697
sema : & Semantics < ' _ , RootDatabase > ,
694
- krate : hir :: Crate ,
698
+ krate : Option < SemanticsScope < ' _ > > ,
695
699
method_call : & ast:: MethodCallExpr ,
696
700
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
697
701
) -> Option < Highlight > {
@@ -718,7 +722,7 @@ fn highlight_method_call(
718
722
}
719
723
720
724
let def_crate = func. module ( sema. db ) . krate ( ) ;
721
- let is_from_other_crate = def_crate != krate;
725
+ let is_from_other_crate = krate . as_ref ( ) . map_or ( false , |it| def_crate != it . krate ( ) ) ;
722
726
let is_from_builtin_crate = def_crate. is_builtin ( sema. db ) ;
723
727
let is_public = func. visibility ( sema. db ) == hir:: Visibility :: Public ;
724
728
@@ -791,7 +795,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
791
795
fn highlight_name_ref_by_syntax (
792
796
name : ast:: NameRef ,
793
797
sema : & Semantics < ' _ , RootDatabase > ,
794
- krate : hir :: Crate ,
798
+ krate : Option < SemanticsScope < ' _ > > ,
795
799
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
796
800
) -> Highlight {
797
801
let default = HlTag :: UnresolvedReference ;
0 commit comments