From 828bd73195a43dfba2837812c070880914001e8f Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Sat, 6 Oct 2018 12:02:15 -0400 Subject: Resolve local names first --- crates/ra_editor/src/scope/fn_scope.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/ra_editor/src/scope') diff --git a/crates/ra_editor/src/scope/fn_scope.rs b/crates/ra_editor/src/scope/fn_scope.rs index 03f9df094..67eb8e2ab 100644 --- a/crates/ra_editor/src/scope/fn_scope.rs +++ b/crates/ra_editor/src/scope/fn_scope.rs @@ -89,7 +89,7 @@ impl ScopeEntry { .unwrap() .text() } - fn ast(&self) -> ast::BindPat { + pub fn ast(&self) -> ast::BindPat { ast::BindPat::cast(self.syntax.borrowed()) .unwrap() } @@ -241,16 +241,15 @@ struct ScopeData { entries: Vec } -pub fn resolve_local_name<'a>(name_ref: ast::NameRef, scopes: &'a FnScopes) -> Option> { +pub fn resolve_local_name<'a>(name_ref: ast::NameRef, scopes: &'a FnScopes) -> Option<&'a ScopeEntry> { use std::collections::HashSet; let mut shadowed = HashSet::new(); - let names = scopes.scope_chain(name_ref.syntax()) + scopes.scope_chain(name_ref.syntax()) .flat_map(|scope| scopes.entries(scope).iter()) .filter(|entry| shadowed.insert(entry.name())) .filter(|entry| entry.name() == name_ref.text()) - .nth(0)?; - names.ast().name() + .nth(0) } #[cfg(test)] @@ -365,7 +364,7 @@ mod tests { let scopes = FnScopes::new(fn_def); - let local_name = resolve_local_name(name_ref, &scopes).unwrap(); + let local_name = resolve_local_name(name_ref, &scopes).unwrap().ast().name().unwrap(); let expected_name = find_node_at_offset::(file.syntax(), expected_offset.into()).unwrap(); assert_eq!(local_name.syntax().range(), expected_name.syntax().range()); -- cgit v1.2.3