@@ -94,12 +94,16 @@ pub(crate) fn find_all_refs(
9494 let sema = Semantics :: new ( db) ;
9595 let syntax = sema. parse ( position. file_id ) . syntax ( ) . clone ( ) ;
9696
97- let ( opt_name, search_kind) =
98- if let Some ( name) = get_struct_def_name_for_struct_literal_search ( & syntax, position) {
99- ( Some ( name) , ReferenceKind :: StructLiteral )
100- } else {
101- ( find_node_at_offset :: < ast:: Name > ( & syntax, position. offset ) , ReferenceKind :: Other )
102- } ;
97+ let ( opt_name, search_kind) = if let Some ( name) =
98+ get_struct_def_name_for_struct_literal_search ( & sema, & syntax, position)
99+ {
100+ ( Some ( name) , ReferenceKind :: StructLiteral )
101+ } else {
102+ (
103+ sema. find_node_at_offset_with_descend :: < ast:: Name > ( & syntax, position. offset ) ,
104+ ReferenceKind :: Other ,
105+ )
106+ } ;
103107
104108 let RangeInfo { range, info : def } = find_name ( & sema, & syntax, position, opt_name) ?;
105109
@@ -131,7 +135,8 @@ fn find_name(
131135 let range = name. syntax ( ) . text_range ( ) ;
132136 return Some ( RangeInfo :: new ( range, def) ) ;
133137 }
134- let name_ref = find_node_at_offset :: < ast:: NameRef > ( & syntax, position. offset ) ?;
138+ let name_ref =
139+ sema. find_node_at_offset_with_descend :: < ast:: NameRef > ( & syntax, position. offset ) ?;
135140 let def = classify_name_ref ( sema, & name_ref) ?. definition ( ) ;
136141 let range = name_ref. syntax ( ) . text_range ( ) ;
137142 Some ( RangeInfo :: new ( range, def) )
@@ -157,17 +162,26 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio
157162}
158163
159164fn get_struct_def_name_for_struct_literal_search (
165+ sema : & Semantics < RootDatabase > ,
160166 syntax : & SyntaxNode ,
161167 position : FilePosition ,
162168) -> Option < ast:: Name > {
163169 if let TokenAtOffset :: Between ( ref left, ref right) = syntax. token_at_offset ( position. offset ) {
164170 if right. kind ( ) != SyntaxKind :: L_CURLY && right. kind ( ) != SyntaxKind :: L_PAREN {
165171 return None ;
166172 }
167- if let Some ( name) = find_node_at_offset :: < ast:: Name > ( & syntax, left. text_range ( ) . start ( ) ) {
173+ if let Some ( name) =
174+ sema. find_node_at_offset_with_descend :: < ast:: Name > ( & syntax, left. text_range ( ) . start ( ) )
175+ {
168176 return name. syntax ( ) . ancestors ( ) . find_map ( ast:: StructDef :: cast) . and_then ( |l| l. name ( ) ) ;
169177 }
170- if find_node_at_offset :: < ast:: TypeParamList > ( & syntax, left. text_range ( ) . start ( ) ) . is_some ( ) {
178+ if sema
179+ . find_node_at_offset_with_descend :: < ast:: TypeParamList > (
180+ & syntax,
181+ left. text_range ( ) . start ( ) ,
182+ )
183+ . is_some ( )
184+ {
171185 return left. ancestors ( ) . find_map ( ast:: StructDef :: cast) . and_then ( |l| l. name ( ) ) ;
172186 }
173187 }
0 commit comments