aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/resolving.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ssr/src/resolving.rs')
-rw-r--r--crates/ra_ssr/src/resolving.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/resolving.rs b/crates/ra_ssr/src/resolving.rs
index d53981737..123bd2bb2 100644
--- a/crates/ra_ssr/src/resolving.rs
+++ b/crates/ra_ssr/src/resolving.rs
@@ -152,6 +152,7 @@ impl<'db> ResolutionScope<'db> {
152 .left_biased() 152 .left_biased()
153 .map(|token| token.parent()) 153 .map(|token| token.parent())
154 .unwrap_or_else(|| file.syntax().clone()); 154 .unwrap_or_else(|| file.syntax().clone());
155 let node = pick_node_for_resolution(node);
155 let scope = sema.scope(&node); 156 let scope = sema.scope(&node);
156 ResolutionScope { 157 ResolutionScope {
157 scope, 158 scope,
@@ -185,6 +186,33 @@ impl<'db> ResolutionScope<'db> {
185 } 186 }
186} 187}
187 188
189/// Returns a suitable node for resolving paths in the current scope. If we create a scope based on
190/// a statement node, then we can't resolve local variables that were defined in the current scope
191/// (only in parent scopes). So we find another node, ideally a child of the statement where local
192/// variable resolution is permitted.
193fn pick_node_for_resolution(node: SyntaxNode) -> SyntaxNode {
194 match node.kind() {
195 SyntaxKind::EXPR_STMT => {
196 if let Some(n) = node.first_child() {
197 mark::hit!(cursor_after_semicolon);
198 return n;
199 }
200 }
201 SyntaxKind::LET_STMT | SyntaxKind::BIND_PAT => {
202 if let Some(next) = node.next_sibling() {
203 return pick_node_for_resolution(next);
204 }
205 }
206 SyntaxKind::NAME => {
207 if let Some(parent) = node.parent() {
208 return pick_node_for_resolution(parent);
209 }
210 }
211 _ => {}
212 }
213 node
214}
215
188/// Returns whether `path` or any of its qualifiers contains type arguments. 216/// Returns whether `path` or any of its qualifiers contains type arguments.
189fn path_contains_type_arguments(path: Option<ast::Path>) -> bool { 217fn path_contains_type_arguments(path: Option<ast::Path>) -> bool {
190 if let Some(path) = path { 218 if let Some(path) = path {