aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/imp.rs48
1 files changed, 16 insertions, 32 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index f950a7995..1eb8cb912 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -325,40 +325,24 @@ impl AnalysisImpl {
325 let file = self.db.file_syntax(file_id); 325 let file = self.db.file_syntax(file_id);
326 let syntax = file.syntax(); 326 let syntax = file.syntax();
327 327
328 let mut ret = vec![]; 328 // Find the binding associated with the offset
329 329 let maybe_binding = find_node_at_offset::<ast::BindPat>(syntax, offset)
330 if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, offset) { 330 .or_else(|| {
331 let decl = DeclarationDescriptor::new(binding); 331 let name_ref = find_node_at_offset::<ast::NameRef>(syntax, offset)?;
332 332 let resolved = resolve_local_name(&self.db, file_id, name_ref)?;
333 ret.push((file_id, decl.range)); 333 find_node_at_offset::<ast::BindPat>(syntax, resolved.1.end())
334 334 });
335 ret.extend(decl.find_all_refs().into_iter() 335
336 .map(|ref_desc| (file_id, ref_desc.range ))); 336 let binding = match maybe_binding {
337 337 None => return Vec::new(),
338 return ret; 338 Some(it) => it,
339 } 339 };
340
341 // Find the symbol we are looking for
342 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
343
344 // We are only handing local references for now
345 if let Some(resolved) = resolve_local_name(&self.db, file_id, name_ref) {
346
347 ret.push((file_id, resolved.1));
348
349 if let Some(fn_def) = find_node_at_offset::<ast::FnDef>(syntax, offset) {
350 340
351 let refs : Vec<_> = fn_def.syntax().descendants() 341 let decl = DeclarationDescriptor::new(binding);
352 .filter_map(ast::NameRef::cast)
353 .filter(|&n: &ast::NameRef| resolve_local_name(&self.db, file_id, n) == Some(resolved.clone()))
354 .collect();
355 342
356 for r in refs { 343 let mut ret = vec![(file_id, decl.range)];
357 ret.push((file_id, r.syntax().range())); 344 ret.extend(decl.find_all_refs().into_iter()
358 } 345 .map(|ref_desc| (file_id, ref_desc.range )));
359 }
360 }
361 }
362 346
363 ret 347 ret
364 } 348 }