diff options
author | Jeremy A. Kolb <[email protected]> | 2018-10-24 20:54:58 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-31 20:38:22 +0000 |
commit | 9b9fc135d6763b403dcf2455c35251d5c36d83e5 (patch) | |
tree | e050fff356f2f6ec75ad1524d0f16f55e464e5e0 /crates/ra_analysis | |
parent | 406f366ccc8b903f457cc694dc1214794c0cfc88 (diff) |
Simplify find_all_refs by always resolving a ast::BindPat
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 48 |
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 | } |