From 67de38ec7d5c235dec209fe859d6bf6b0dbe497a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 27 Nov 2018 23:40:23 +0300 Subject: move resolve_local_scope --- crates/ra_analysis/src/hir/function/mod.rs | 2 +- crates/ra_analysis/src/hir/function/scope.rs | 29 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'crates/ra_analysis/src/hir/function') diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs index 5de9806e3..8161a604f 100644 --- a/crates/ra_analysis/src/hir/function/mod.rs +++ b/crates/ra_analysis/src/hir/function/mod.rs @@ -15,7 +15,7 @@ use crate::{ syntax_ptr::SyntaxPtr, FileId, }; -pub(crate) use self::scope::{resolve_local_name, FnScopes}; +pub(crate) use self::scope::FnScopes; pub(crate) use crate::loc2id::FnId; impl FnId { diff --git a/crates/ra_analysis/src/hir/function/scope.rs b/crates/ra_analysis/src/hir/function/scope.rs index 5307a0a8e..b8bdebe47 100644 --- a/crates/ra_analysis/src/hir/function/scope.rs +++ b/crates/ra_analysis/src/hir/function/scope.rs @@ -57,6 +57,19 @@ impl FnScopes { self.scopes[scope].parent }) } + pub(crate) fn resolve_local_name<'a>( + &'a self, + name_ref: ast::NameRef, + ) -> Option<&'a ScopeEntry> { + let mut shadowed = FxHashSet::default(); + let ret = self + .scope_chain(name_ref.syntax()) + .flat_map(|scope| self.entries(scope).iter()) + .filter(|entry| shadowed.insert(entry.name())) + .filter(|entry| entry.name() == &name_ref.text()) + .nth(0); + ret + } fn root_scope(&mut self) -> ScopeId { self.scopes.alloc(ScopeData { parent: None, @@ -249,20 +262,6 @@ fn compute_expr_scopes(expr: ast::Expr, scopes: &mut FnScopes, scope: ScopeId) { } } -pub fn resolve_local_name<'a>( - name_ref: ast::NameRef, - scopes: &'a FnScopes, -) -> Option<&'a ScopeEntry> { - let mut shadowed = FxHashSet::default(); - let ret = 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); - ret -} - #[cfg(test)] mod tests { use ra_editor::find_node_at_offset; @@ -376,7 +375,7 @@ mod tests { let scopes = FnScopes::new(fn_def); - let local_name_entry = resolve_local_name(name_ref, &scopes).unwrap(); + let local_name_entry = scopes.resolve_local_name(name_ref).unwrap(); let local_name = local_name_entry.ptr().resolve(&file); let expected_name = find_node_at_offset::(file.syntax(), expected_offset.into()).unwrap(); -- cgit v1.2.3