From b260641e0caa3938151afe66fa3bf5691b8c3caa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 13 Apr 2019 11:29:47 +0300 Subject: slight encapsulation --- crates/ra_hir/src/expr/scope.rs | 18 +++++++++++------- crates/ra_hir/src/source_binder.rs | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 090343d12..7f53f23aa 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -18,7 +18,7 @@ impl_arena_id!(ScopeId); pub struct ExprScopes { body: Arc, scopes: Arena, - pub(crate) scope_for: FxHashMap, + scope_by_expr: FxHashMap, } #[derive(Debug, PartialEq, Eq)] @@ -54,7 +54,7 @@ impl ExprScopes { let mut scopes = ExprScopes { body: body.clone(), scopes: Arena::default(), - scope_for: FxHashMap::default(), + scope_by_expr: FxHashMap::default(), }; let root = scopes.root_scope(); scopes.add_params_bindings(root, body.params()); @@ -73,6 +73,14 @@ impl ExprScopes { std::iter::successors(scope, move |&scope| self.scopes[scope].parent) } + pub(crate) fn scope_for(&self, expr: ExprId) -> Option { + self.scope_by_expr.get(&expr).map(|&scope| scope) + } + + pub(crate) fn scope_by_expr(&self) -> &FxHashMap { + &self.scope_by_expr + } + fn root_scope(&mut self) -> ScopeId { self.scopes.alloc(ScopeData { parent: None, entries: vec![] }) } @@ -99,11 +107,7 @@ impl ExprScopes { } fn set_scope(&mut self, node: ExprId, scope: ScopeId) { - self.scope_for.insert(node, scope); - } - - pub(crate) fn scope_for(&self, expr: ExprId) -> Option { - self.scope_for.get(&expr).map(|&scope| scope) + self.scope_by_expr.insert(node, scope); } } diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 34a00a300..8d53079c6 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -368,7 +368,7 @@ fn scope_for_offset( offset: TextUnit, ) -> Option { scopes - .scope_for + .scope_by_expr() .iter() .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope))) // find containing scope @@ -388,7 +388,7 @@ fn adjust( ) -> Option { let r = ptr.range(); let child_scopes = scopes - .scope_for + .scope_by_expr() .iter() .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope))) .map(|(ptr, scope)| (ptr.range(), scope)) -- cgit v1.2.3