@@ -54,6 +54,7 @@ pub(crate) fn find_all_refs(
5454 sema : & Semantics < ' _ , RootDatabase > ,
5555 position : FilePosition ,
5656 search_scope : Option < SearchScope > ,
57+ exclude_imports : bool ,
5758) -> Option < Vec < ReferenceSearchResult > > {
5859 let _p = profile:: span ( "find_all_refs" ) ;
5960 let syntax = sema. parse ( position. file_id ) . syntax ( ) . clone ( ) ;
@@ -79,6 +80,10 @@ pub(crate) fn find_all_refs(
7980 retain_adt_literal_usages ( & mut usages, def, sema) ;
8081 }
8182
83+ if exclude_imports {
84+ filter_import_references ( & mut usages) ;
85+ }
86+
8287 let references = usages
8388 . into_iter ( )
8489 . map ( |( file_id, refs) | {
@@ -112,6 +117,17 @@ pub(crate) fn find_all_refs(
112117 }
113118}
114119
120+ fn filter_import_references ( usages : & mut UsageSearchResult ) {
121+ for ( _file_id, refs) in & mut usages. references {
122+ refs. retain ( |it| match it. name . as_name_ref ( ) {
123+ Some ( name_ref) => {
124+ !name_ref. syntax ( ) . ancestors ( ) . any ( |it_ref| matches ! ( it_ref. kind( ) , USE ) )
125+ }
126+ None => true ,
127+ } ) ;
128+ }
129+ }
130+
115131pub ( crate ) fn find_defs < ' a > (
116132 sema : & ' a Semantics < ' _ , RootDatabase > ,
117133 syntax : & SyntaxNode ,
@@ -1094,7 +1110,7 @@ impl Foo {
10941110
10951111 fn check_with_scope ( ra_fixture : & str , search_scope : Option < SearchScope > , expect : Expect ) {
10961112 let ( analysis, pos) = fixture:: position ( ra_fixture) ;
1097- let refs = analysis. find_all_refs ( pos, search_scope) . unwrap ( ) . unwrap ( ) ;
1113+ let refs = analysis. find_all_refs ( pos, search_scope, false ) . unwrap ( ) . unwrap ( ) ;
10981114
10991115 let mut actual = String :: new ( ) ;
11001116 for refs in refs {
0 commit comments