diff options
author | Aleksey Kladov <[email protected]> | 2019-04-12 22:44:47 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-12 22:44:47 +0100 |
commit | 0fd93bc14a2d0ce2edd682d26c18979c13f181c5 (patch) | |
tree | e800dc46abe63bad2eaffaf7f3c0f4d8358d0c9a /crates/ra_hir/src | |
parent | 20013de2abb95bc024f55163b1a5044cfb52a873 (diff) |
use really correct resolver for expressions
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 182bc36ff..846394212 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -9,7 +9,7 @@ use std::sync::Arc; | |||
9 | 9 | ||
10 | use ra_db::{FileId, FilePosition}; | 10 | use ra_db::{FileId, FilePosition}; |
11 | use ra_syntax::{ | 11 | use ra_syntax::{ |
12 | SyntaxNode, AstPtr, | 12 | SyntaxNode, AstPtr, TextUnit, |
13 | ast::{self, AstNode, NameOwner}, | 13 | ast::{self, AstNode, NameOwner}, |
14 | algo::find_node_at_offset, | 14 | algo::find_node_at_offset, |
15 | }; | 15 | }; |
@@ -196,13 +196,21 @@ pub fn trait_from_module( | |||
196 | Trait { id: ctx.to_def(trait_def) } | 196 | Trait { id: ctx.to_def(trait_def) } |
197 | } | 197 | } |
198 | 198 | ||
199 | fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNode) -> Resolver { | 199 | fn resolver_for_node( |
200 | db: &impl HirDatabase, | ||
201 | file_id: FileId, | ||
202 | node: &SyntaxNode, | ||
203 | offset: Option<TextUnit>, | ||
204 | ) -> Resolver { | ||
200 | node.ancestors() | 205 | node.ancestors() |
201 | .find_map(|node| { | 206 | .find_map(|node| { |
202 | if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { | 207 | if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { |
203 | if let Some(func) = function_from_child_node(db, file_id, node) { | 208 | if let Some(func) = function_from_child_node(db, file_id, node) { |
204 | let scopes = func.scopes(db); | 209 | let scopes = func.scopes(db); |
205 | let scope = scopes.scope_for(&node); | 210 | let scope = match offset { |
211 | None => scopes.scope_for(&node), | ||
212 | Some(offset) => scopes.scope_for_offset(offset), | ||
213 | }; | ||
206 | Some(expr::resolver_for_scope(func.body(db), db, scope)) | 214 | Some(expr::resolver_for_scope(func.body(db), db, scope)) |
207 | } else { | 215 | } else { |
208 | // FIXME const/static/array length | 216 | // FIXME const/static/array length |
@@ -260,7 +268,12 @@ pub enum PathResolution { | |||
260 | } | 268 | } |
261 | 269 | ||
262 | impl SourceAnalyzer { | 270 | impl SourceAnalyzer { |
263 | pub fn new(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNode) -> SourceAnalyzer { | 271 | pub fn new( |
272 | db: &impl HirDatabase, | ||
273 | file_id: FileId, | ||
274 | node: &SyntaxNode, | ||
275 | offset: Option<TextUnit>, | ||
276 | ) -> SourceAnalyzer { | ||
264 | let def_with_body = node.ancestors().find_map(|node| { | 277 | let def_with_body = node.ancestors().find_map(|node| { |
265 | if let Some(src) = ast::FnDef::cast(node) { | 278 | if let Some(src) = ast::FnDef::cast(node) { |
266 | return function_from_source(db, file_id, src).map(DefWithBody::from); | 279 | return function_from_source(db, file_id, src).map(DefWithBody::from); |
@@ -274,8 +287,7 @@ impl SourceAnalyzer { | |||
274 | None | 287 | None |
275 | }); | 288 | }); |
276 | SourceAnalyzer { | 289 | SourceAnalyzer { |
277 | //TODO: use scope_for_offset here to get correct scope for completion | 290 | resolver: resolver_for_node(db, file_id, node, offset), |
278 | resolver: resolver_for_node(db, file_id, node), | ||
279 | body_source_map: def_with_body.map(|it| it.body_source_map(db)), | 291 | body_source_map: def_with_body.map(|it| it.body_source_map(db)), |
280 | infer: def_with_body.map(|it| it.infer(db)), | 292 | infer: def_with_body.map(|it| it.infer(db)), |
281 | } | 293 | } |