From 8ada1a2689eb33b78402ba739a5fb1e7c011def8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Oct 2018 16:36:28 +0300 Subject: Simplify --- crates/ra_analysis/src/imp.rs | 6 +++--- crates/ra_editor/src/lib.rs | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index c15873328..83a0dc445 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -207,7 +207,7 @@ impl AnalysisImpl { let syntax = file.syntax(); if let Some(name_ref) = find_node_at_offset::(syntax, offset) { // First try to resolve the symbol locally - return if let Some((name, range)) = resolve_local_name(&file, offset, name_ref) { + return if let Some((name, range)) = resolve_local_name(name_ref) { let mut vec = vec![]; vec.push(( file_id, @@ -262,7 +262,7 @@ impl AnalysisImpl { if let Some(name_ref) = find_node_at_offset::(syntax, offset) { // We are only handing local references for now - if let Some(resolved) = resolve_local_name(&file, offset, name_ref) { + if let Some(resolved) = resolve_local_name(name_ref) { ret.push((file_id, resolved.1)); @@ -270,7 +270,7 @@ impl AnalysisImpl { let refs : Vec<_> = fn_def.syntax().descendants() .filter_map(ast::NameRef::cast) - .filter(|n: &ast::NameRef| resolve_local_name(&file, n.syntax().range().start(), *n) == Some(resolved.clone())) + .filter(|&n: &ast::NameRef| resolve_local_name(n) == Some(resolved.clone())) .collect(); for r in refs { diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index 417080d90..94e9a18e4 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs @@ -152,11 +152,9 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>( } pub fn resolve_local_name( - file: &File, - offset: TextUnit, name_ref: ast::NameRef, ) -> Option<(SmolStr, TextRange)> { - let fn_def = find_node_at_offset::(file.syntax(), offset)?; + let fn_def = name_ref.syntax().ancestors().find_map(ast::FnDef::cast)?; let scopes = scope::FnScopes::new(fn_def); let scope_entry = scope::resolve_local_name(name_ref, &scopes)?; let name = scope_entry.ast().name()?; -- cgit v1.2.3