aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-11 14:49:35 +0100
committerAleksey Kladov <[email protected]>2019-04-11 14:49:35 +0100
commitebb0c377f0ab99a0f5e6d0c776cb9b026b62b0e4 (patch)
tree49a2c265c83ae03182cf593c52ec8a0c155ad151 /crates/ra_hir
parent3c9f2d0e372cff6490dcd30411cb6cc1f691fde7 (diff)
remove resolver from CompletonContext
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/source_binder.rs29
1 files changed, 5 insertions, 24 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index dc9d614c0..560b48303 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -11,7 +11,7 @@ use ra_db::{FileId, FilePosition};
11use ra_syntax::{ 11use ra_syntax::{
12 SyntaxNode, AstPtr, 12 SyntaxNode, AstPtr,
13 ast::{self, AstNode, NameOwner}, 13 ast::{self, AstNode, NameOwner},
14 algo::{find_node_at_offset, find_token_at_offset}, 14 algo::find_node_at_offset,
15}; 15};
16 16
17use crate::{ 17use crate::{
@@ -196,29 +196,6 @@ 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
199pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver {
200 let file_id = position.file_id;
201 let file = db.parse(file_id);
202 find_token_at_offset(file.syntax(), position.offset)
203 .find_map(|token| {
204 token.parent().ancestors().find_map(|node| {
205 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() {
206 if let Some(func) = function_from_child_node(db, file_id, node) {
207 let scopes = func.scopes(db);
208 let scope = scopes.scope_for_offset(position.offset);
209 Some(expr::resolver_for_scope(func.body(db), db, scope))
210 } else {
211 // FIXME const/static/array length
212 None
213 }
214 } else {
215 try_get_resolver_for_node(db, file_id, node)
216 }
217 })
218 })
219 .unwrap_or_default()
220}
221
222fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNode) -> Resolver { 199fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNode) -> Resolver {
223 node.ancestors() 200 node.ancestors()
224 .find_map(|node| { 201 .find_map(|node| {
@@ -305,6 +282,10 @@ impl SourceAnalyzer {
305 } 282 }
306 } 283 }
307 284
285 pub fn resolver(&self) -> &Resolver {
286 &self.resolver
287 }
288
308 pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option<crate::Ty> { 289 pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option<crate::Ty> {
309 let expr_id = self.body_source_map.as_ref()?.node_expr(expr)?; 290 let expr_id = self.body_source_map.as_ref()?.node_expr(expr)?;
310 Some(self.infer.as_ref()?[expr_id].clone()) 291 Some(self.infer.as_ref()?[expr_id].clone())