aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-15 14:24:04 +0000
committerAleksey Kladov <[email protected]>2019-01-19 12:37:25 +0000
commitafaa26636e4391ebacfc09e9c994c11bab58b834 (patch)
tree79d66f1d2eb70f3092285ab37f1e21c3832ea8b8 /crates/ra_hir/src/code_model_impl
parent0a82d9cdc975da27e78839e1a8cb873ba99ae64b (diff)
Add additional pattern variants
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r--crates/ra_hir/src/code_model_impl/function/scope.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function/scope.rs b/crates/ra_hir/src/code_model_impl/function/scope.rs
index afca1e9f8..c551e445a 100644
--- a/crates/ra_hir/src/code_model_impl/function/scope.rs
+++ b/crates/ra_hir/src/code_model_impl/function/scope.rs
@@ -47,9 +47,11 @@ impl FnScopes {
47 compute_expr_scopes(body.body_expr(), &body, &mut scopes, root); 47 compute_expr_scopes(body.body_expr(), &body, &mut scopes, root);
48 scopes 48 scopes
49 } 49 }
50
50 pub fn entries(&self, scope: ScopeId) -> &[ScopeEntry] { 51 pub fn entries(&self, scope: ScopeId) -> &[ScopeEntry] {
51 &self.scopes[scope].entries 52 &self.scopes[scope].entries
52 } 53 }
54
53 pub fn scope_chain_for<'a>(&'a self, expr: ExprId) -> impl Iterator<Item = ScopeId> + 'a { 55 pub fn scope_chain_for<'a>(&'a self, expr: ExprId) -> impl Iterator<Item = ScopeId> + 'a {
54 generate(self.scope_for(expr), move |&scope| { 56 generate(self.scope_for(expr), move |&scope| {
55 self.scopes[scope].parent 57 self.scopes[scope].parent
@@ -76,12 +78,14 @@ impl FnScopes {
76 entries: vec![], 78 entries: vec![],
77 }) 79 })
78 } 80 }
81
79 fn new_scope(&mut self, parent: ScopeId) -> ScopeId { 82 fn new_scope(&mut self, parent: ScopeId) -> ScopeId {
80 self.scopes.alloc(ScopeData { 83 self.scopes.alloc(ScopeData {
81 parent: Some(parent), 84 parent: Some(parent),
82 entries: vec![], 85 entries: vec![],
83 }) 86 })
84 } 87 }
88
85 fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) { 89 fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) {
86 match &body[pat] { 90 match &body[pat] {
87 Pat::Bind { name } => self.scopes[scope].entries.push(ScopeEntry { 91 Pat::Bind { name } => self.scopes[scope].entries.push(ScopeEntry {
@@ -91,15 +95,18 @@ impl FnScopes {
91 p => p.walk_child_pats(|pat| self.add_bindings(body, scope, pat)), 95 p => p.walk_child_pats(|pat| self.add_bindings(body, scope, pat)),
92 } 96 }
93 } 97 }
98
94 fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) { 99 fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) {
95 let body = Arc::clone(&self.body); 100 let body = Arc::clone(&self.body);
96 params 101 params
97 .into_iter() 102 .into_iter()
98 .for_each(|pat| self.add_bindings(&body, scope, *pat)); 103 .for_each(|pat| self.add_bindings(&body, scope, *pat));
99 } 104 }
105
100 fn set_scope(&mut self, node: ExprId, scope: ScopeId) { 106 fn set_scope(&mut self, node: ExprId, scope: ScopeId) {
101 self.scope_for.insert(node, scope); 107 self.scope_for.insert(node, scope);
102 } 108 }
109
103 fn scope_for(&self, expr: ExprId) -> Option<ScopeId> { 110 fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
104 self.scope_for.get(&expr).map(|&scope| scope) 111 self.scope_for.get(&expr).map(|&scope| scope)
105 } 112 }
@@ -121,6 +128,7 @@ impl ScopeEntryWithSyntax {
121 pub fn name(&self) -> &Name { 128 pub fn name(&self) -> &Name {
122 &self.name 129 &self.name
123 } 130 }
131
124 pub fn ptr(&self) -> LocalSyntaxPtr { 132 pub fn ptr(&self) -> LocalSyntaxPtr {
125 self.ptr 133 self.ptr
126 } 134 }
@@ -132,6 +140,7 @@ impl ScopesWithSyntaxMapping {
132 self.scopes.scopes[scope].parent 140 self.scopes.scopes[scope].parent
133 }) 141 })
134 } 142 }
143
135 pub fn scope_chain_for_offset<'a>( 144 pub fn scope_chain_for_offset<'a>(
136 &'a self, 145 &'a self,
137 offset: TextUnit, 146 offset: TextUnit,
@@ -152,6 +161,7 @@ impl ScopesWithSyntaxMapping {
152 161
153 generate(scope, move |&scope| self.scopes.scopes[scope].parent) 162 generate(scope, move |&scope| self.scopes.scopes[scope].parent)
154 } 163 }
164
155 // XXX: during completion, cursor might be outside of any particular 165 // XXX: during completion, cursor might be outside of any particular
156 // expression. Try to figure out the correct scope... 166 // expression. Try to figure out the correct scope...
157 fn adjust(&self, ptr: LocalSyntaxPtr, original_scope: ScopeId, offset: TextUnit) -> ScopeId { 167 fn adjust(&self, ptr: LocalSyntaxPtr, original_scope: ScopeId, offset: TextUnit) -> ScopeId {
@@ -225,6 +235,7 @@ impl ScopeEntry {
225 pub fn name(&self) -> &Name { 235 pub fn name(&self) -> &Name {
226 &self.name 236 &self.name
227 } 237 }
238
228 pub fn pat(&self) -> PatId { 239 pub fn pat(&self) -> PatId {
229 self.pat 240 self.pat
230 } 241 }