@@ -455,46 +455,45 @@ impl<'a> FindUsages<'a> {
455
455
}
456
456
457
457
let find_nodes = move |name : & str , node : & syntax:: SyntaxNode , offset : TextSize | {
458
- node. token_at_offset ( offset) . find ( |it| it. text ( ) == name) . map ( |token| {
459
- // FIXME: There should be optimization potential here
460
- // Currently we try to descend everything we find which
461
- // means we call `Semantics::descend_into_macros` on
462
- // every textual hit. That function is notoriously
463
- // expensive even for things that do not get down mapped
464
- // into macros.
465
- sema. descend_into_macros ( token) . into_iter ( ) . filter_map ( |it| it. parent ( ) )
466
- } )
458
+ node. token_at_offset ( offset)
459
+ . find ( |it| {
460
+ // `name` is stripped of raw ident prefix. See the comment on name retrieval above.
461
+ it. text ( ) . trim_start_matches ( "r#" ) == name
462
+ } )
463
+ . into_iter ( )
464
+ . flat_map ( |token| {
465
+ // FIXME: There should be optimization potential here
466
+ // Currently we try to descend everything we find which
467
+ // means we call `Semantics::descend_into_macros` on
468
+ // every textual hit. That function is notoriously
469
+ // expensive even for things that do not get down mapped
470
+ // into macros.
471
+ sema. descend_into_macros ( token) . into_iter ( ) . filter_map ( |it| it. parent ( ) )
472
+ } )
467
473
} ;
468
474
469
475
for ( text, file_id, search_range) in scope_files ( sema, & search_scope) {
470
476
let tree = Lazy :: new ( move || sema. parse ( file_id) . syntax ( ) . clone ( ) ) ;
471
477
472
478
// Search for occurrences of the items name
473
479
for offset in match_indices ( & text, finder, search_range) {
474
- if let Some ( iter) = find_nodes ( name, & tree, offset) {
475
- for name in iter. filter_map ( ast:: NameLike :: cast) {
476
- if match name {
477
- ast:: NameLike :: NameRef ( name_ref) => {
478
- self . found_name_ref ( & name_ref, sink)
479
- }
480
- ast:: NameLike :: Name ( name) => self . found_name ( & name, sink) ,
481
- ast:: NameLike :: Lifetime ( lifetime) => {
482
- self . found_lifetime ( & lifetime, sink)
483
- }
484
- } {
485
- return ;
486
- }
480
+ for name in find_nodes ( name, & tree, offset) . filter_map ( ast:: NameLike :: cast) {
481
+ if match name {
482
+ ast:: NameLike :: NameRef ( name_ref) => self . found_name_ref ( & name_ref, sink) ,
483
+ ast:: NameLike :: Name ( name) => self . found_name ( & name, sink) ,
484
+ ast:: NameLike :: Lifetime ( lifetime) => self . found_lifetime ( & lifetime, sink) ,
485
+ } {
486
+ return ;
487
487
}
488
488
}
489
489
}
490
490
// Search for occurrences of the `Self` referring to our type
491
491
if let Some ( ( self_ty, finder) ) = & include_self_kw_refs {
492
492
for offset in match_indices ( & text, finder, search_range) {
493
- if let Some ( iter) = find_nodes ( "Self" , & tree, offset) {
494
- for name_ref in iter. filter_map ( ast:: NameRef :: cast) {
495
- if self . found_self_ty_name_ref ( self_ty, & name_ref, sink) {
496
- return ;
497
- }
493
+ for name_ref in find_nodes ( "Self" , & tree, offset) . filter_map ( ast:: NameRef :: cast)
494
+ {
495
+ if self . found_self_ty_name_ref ( self_ty, & name_ref, sink) {
496
+ return ;
498
497
}
499
498
}
500
499
}
@@ -513,21 +512,21 @@ impl<'a> FindUsages<'a> {
513
512
let tree = Lazy :: new ( move || sema. parse ( file_id) . syntax ( ) . clone ( ) ) ;
514
513
515
514
for offset in match_indices ( & text, finder, search_range) {
516
- if let Some ( iter ) = find_nodes ( "super" , & tree , offset ) {
517
- for name_ref in iter . filter_map ( ast:: NameRef :: cast) {
518
- if self . found_name_ref ( & name_ref , sink ) {
519
- return ;
520
- }
515
+ for name_ref in
516
+ find_nodes ( "super" , & tree , offset ) . filter_map ( ast:: NameRef :: cast)
517
+ {
518
+ if self . found_name_ref ( & name_ref , sink ) {
519
+ return ;
521
520
}
522
521
}
523
522
}
524
523
if let Some ( finder) = & is_crate_root {
525
524
for offset in match_indices ( & text, finder, search_range) {
526
- if let Some ( iter ) = find_nodes ( "crate" , & tree , offset ) {
527
- for name_ref in iter . filter_map ( ast:: NameRef :: cast) {
528
- if self . found_name_ref ( & name_ref , sink ) {
529
- return ;
530
- }
525
+ for name_ref in
526
+ find_nodes ( "crate" , & tree , offset ) . filter_map ( ast:: NameRef :: cast)
527
+ {
528
+ if self . found_name_ref ( & name_ref , sink ) {
529
+ return ;
531
530
}
532
531
}
533
532
}
@@ -566,11 +565,10 @@ impl<'a> FindUsages<'a> {
566
565
let finder = & Finder :: new ( "self" ) ;
567
566
568
567
for offset in match_indices ( & text, finder, search_range) {
569
- if let Some ( iter) = find_nodes ( "self" , & tree, offset) {
570
- for name_ref in iter. filter_map ( ast:: NameRef :: cast) {
571
- if self . found_self_module_name_ref ( & name_ref, sink) {
572
- return ;
573
- }
568
+ for name_ref in find_nodes ( "self" , & tree, offset) . filter_map ( ast:: NameRef :: cast)
569
+ {
570
+ if self . found_self_module_name_ref ( & name_ref, sink) {
571
+ return ;
574
572
}
575
573
}
576
574
}
0 commit comments