@@ -256,40 +256,24 @@ impl AnalysisImpl {
256
256
let file = root. syntax ( file_id) ;
257
257
let syntax = file. syntax ( ) ;
258
258
259
- let mut ret = vec ! [ ] ;
260
-
261
- if let Some ( binding) = find_node_at_offset :: < ast:: BindPat > ( syntax, offset) {
262
- let decl = DeclarationDescriptor :: new ( binding) ;
263
-
264
- ret. push ( ( file_id, decl. range ) ) ;
265
-
266
- ret. extend ( decl. find_all_refs ( ) . into_iter ( )
267
- . map ( |ref_desc| ( file_id, ref_desc. range ) ) ) ;
268
-
269
- return ret;
259
+ // Find the binding associated with the offset
260
+ let maybe_binding = find_node_at_offset :: < ast:: BindPat > ( syntax, offset)
261
+ . or_else ( ||
262
+ find_node_at_offset :: < ast:: NameRef > ( syntax, offset)
263
+ . and_then ( |name_ref| resolve_local_name ( name_ref) )
264
+ . and_then ( |resolved| find_node_at_offset :: < ast:: BindPat > ( syntax, resolved. 1 . end ( ) ) ) ) ;
265
+
266
+ if maybe_binding. is_none ( ) {
267
+ return Vec :: new ( ) ;
270
268
}
271
269
272
- // Find the symbol we are looking for
273
- if let Some ( name_ref) = find_node_at_offset :: < ast:: NameRef > ( syntax, offset) {
274
-
275
- // We are only handing local references for now
276
- if let Some ( resolved) = resolve_local_name ( name_ref) {
277
-
278
- ret. push ( ( file_id, resolved. 1 ) ) ;
270
+ let binding = maybe_binding. unwrap ( ) ;
279
271
280
- if let Some ( fn_def ) = find_node_at_offset :: < ast :: FnDef > ( syntax , offset ) {
272
+ let decl = DeclarationDescriptor :: new ( binding ) ;
281
273
282
- let refs : Vec < _ > = fn_def. syntax ( ) . descendants ( )
283
- . filter_map ( ast:: NameRef :: cast)
284
- . filter ( |& n: & ast:: NameRef | resolve_local_name ( n) == Some ( resolved. clone ( ) ) )
285
- . collect ( ) ;
286
-
287
- for r in refs {
288
- ret. push ( ( file_id, r. syntax ( ) . range ( ) ) ) ;
289
- }
290
- }
291
- }
292
- }
274
+ let mut ret = vec ! [ ( file_id, decl. range) ] ;
275
+ ret. extend ( decl. find_all_refs ( ) . into_iter ( )
276
+ . map ( |ref_desc| ( file_id, ref_desc. range ) ) ) ;
293
277
294
278
ret
295
279
}
0 commit comments