@@ -309,40 +309,24 @@ impl AnalysisImpl {
309
309
let file = self . db . file_syntax ( file_id) ;
310
310
let syntax = file. syntax ( ) ;
311
311
312
- let mut ret = vec ! [ ] ;
313
-
314
- if let Some ( binding) = find_node_at_offset :: < ast:: BindPat > ( syntax, offset) {
315
- let decl = DeclarationDescriptor :: new ( binding) ;
316
-
317
- ret. push ( ( file_id, decl. range ) ) ;
318
-
319
- ret. extend ( decl. find_all_refs ( ) . into_iter ( )
320
- . map ( |ref_desc| ( file_id, ref_desc. range ) ) ) ;
321
-
322
- return ret;
312
+ // Find the binding associated with the offset
313
+ let maybe_binding = find_node_at_offset :: < ast:: BindPat > ( syntax, offset)
314
+ . or_else ( ||
315
+ find_node_at_offset :: < ast:: NameRef > ( syntax, offset)
316
+ . and_then ( |name_ref| resolve_local_name ( name_ref) )
317
+ . and_then ( |resolved| find_node_at_offset :: < ast:: BindPat > ( syntax, resolved. 1 . end ( ) ) ) ) ;
318
+
319
+ if maybe_binding. is_none ( ) {
320
+ return Vec :: new ( ) ;
323
321
}
324
322
325
- // Find the symbol we are looking for
326
- if let Some ( name_ref) = find_node_at_offset :: < ast:: NameRef > ( syntax, offset) {
327
-
328
- // We are only handing local references for now
329
- if let Some ( resolved) = resolve_local_name ( name_ref) {
330
-
331
- ret. push ( ( file_id, resolved. 1 ) ) ;
323
+ let binding = maybe_binding. unwrap ( ) ;
332
324
333
- if let Some ( fn_def ) = find_node_at_offset :: < ast :: FnDef > ( syntax , offset ) {
325
+ let decl = DeclarationDescriptor :: new ( binding ) ;
334
326
335
- let refs : Vec < _ > = fn_def. syntax ( ) . descendants ( )
336
- . filter_map ( ast:: NameRef :: cast)
337
- . filter ( |& n: & ast:: NameRef | resolve_local_name ( n) == Some ( resolved. clone ( ) ) )
338
- . collect ( ) ;
339
-
340
- for r in refs {
341
- ret. push ( ( file_id, r. syntax ( ) . range ( ) ) ) ;
342
- }
343
- }
344
- }
345
- }
327
+ let mut ret = vec ! [ ( file_id, decl. range) ] ;
328
+ ret. extend ( decl. find_all_refs ( ) . into_iter ( )
329
+ . map ( |ref_desc| ( file_id, ref_desc. range ) ) ) ;
346
330
347
331
ret
348
332
}
0 commit comments