aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-13 09:29:47 +0100
committerAleksey Kladov <[email protected]>2019-04-13 09:29:47 +0100
commitb260641e0caa3938151afe66fa3bf5691b8c3caa (patch)
tree5af23f20b86fcec3b13b1315237ba73ff9aa9dcd /crates/ra_hir
parentf9e825d95624129b66c34f25904f6ae46b9d5760 (diff)
slight encapsulation
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/expr/scope.rs18
-rw-r--r--crates/ra_hir/src/source_binder.rs4
2 files changed, 13 insertions, 9 deletions
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);
18pub struct ExprScopes { 18pub struct ExprScopes {
19 body: Arc<Body>, 19 body: Arc<Body>,
20 scopes: Arena<ScopeId, ScopeData>, 20 scopes: Arena<ScopeId, ScopeData>,
21 pub(crate) scope_for: FxHashMap<ExprId, ScopeId>, 21 scope_by_expr: FxHashMap<ExprId, ScopeId>,
22} 22}
23 23
24#[derive(Debug, PartialEq, Eq)] 24#[derive(Debug, PartialEq, Eq)]
@@ -54,7 +54,7 @@ impl ExprScopes {
54 let mut scopes = ExprScopes { 54 let mut scopes = ExprScopes {
55 body: body.clone(), 55 body: body.clone(),
56 scopes: Arena::default(), 56 scopes: Arena::default(),
57 scope_for: FxHashMap::default(), 57 scope_by_expr: FxHashMap::default(),
58 }; 58 };
59 let root = scopes.root_scope(); 59 let root = scopes.root_scope();
60 scopes.add_params_bindings(root, body.params()); 60 scopes.add_params_bindings(root, body.params());
@@ -73,6 +73,14 @@ impl ExprScopes {
73 std::iter::successors(scope, move |&scope| self.scopes[scope].parent) 73 std::iter::successors(scope, move |&scope| self.scopes[scope].parent)
74 } 74 }
75 75
76 pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
77 self.scope_by_expr.get(&expr).map(|&scope| scope)
78 }
79
80 pub(crate) fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> {
81 &self.scope_by_expr
82 }
83
76 fn root_scope(&mut self) -> ScopeId { 84 fn root_scope(&mut self) -> ScopeId {
77 self.scopes.alloc(ScopeData { parent: None, entries: vec![] }) 85 self.scopes.alloc(ScopeData { parent: None, entries: vec![] })
78 } 86 }
@@ -99,11 +107,7 @@ impl ExprScopes {
99 } 107 }
100 108
101 fn set_scope(&mut self, node: ExprId, scope: ScopeId) { 109 fn set_scope(&mut self, node: ExprId, scope: ScopeId) {
102 self.scope_for.insert(node, scope); 110 self.scope_by_expr.insert(node, scope);
103 }
104
105 pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
106 self.scope_for.get(&expr).map(|&scope| scope)
107 } 111 }
108} 112}
109 113
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(
368 offset: TextUnit, 368 offset: TextUnit,
369) -> Option<ScopeId> { 369) -> Option<ScopeId> {
370 scopes 370 scopes
371 .scope_for 371 .scope_by_expr()
372 .iter() 372 .iter()
373 .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope))) 373 .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope)))
374 // find containing scope 374 // find containing scope
@@ -388,7 +388,7 @@ fn adjust(
388) -> Option<ScopeId> { 388) -> Option<ScopeId> {
389 let r = ptr.range(); 389 let r = ptr.range();
390 let child_scopes = scopes 390 let child_scopes = scopes
391 .scope_for 391 .scope_by_expr()
392 .iter() 392 .iter()
393 .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope))) 393 .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope)))
394 .map(|(ptr, scope)| (ptr.range(), scope)) 394 .map(|(ptr, scope)| (ptr.range(), scope))