@@ -455,46 +455,45 @@ impl<'a> FindUsages<'a> {
455455 }
456456
457457 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+ } )
467473 } ;
468474
469475 for ( text, file_id, search_range) in scope_files ( sema, & search_scope) {
470476 let tree = Lazy :: new ( move || sema. parse ( file_id) . syntax ( ) . clone ( ) ) ;
471477
472478 // Search for occurrences of the items name
473479 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 ;
487487 }
488488 }
489489 }
490490 // Search for occurrences of the `Self` referring to our type
491491 if let Some ( ( self_ty, finder) ) = & include_self_kw_refs {
492492 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 ;
498497 }
499498 }
500499 }
@@ -513,21 +512,21 @@ impl<'a> FindUsages<'a> {
513512 let tree = Lazy :: new ( move || sema. parse ( file_id) . syntax ( ) . clone ( ) ) ;
514513
515514 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 ;
521520 }
522521 }
523522 }
524523 if let Some ( finder) = & is_crate_root {
525524 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 ;
531530 }
532531 }
533532 }
@@ -566,11 +565,10 @@ impl<'a> FindUsages<'a> {
566565 let finder = & Finder :: new ( "self" ) ;
567566
568567 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 ;
574572 }
575573 }
576574 }
0 commit comments