From ebb0c377f0ab99a0f5e6d0c776cb9b026b62b0e4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 11 Apr 2019 16:49:35 +0300 Subject: remove resolver from CompletonContext --- crates/ra_hir/src/source_binder.rs | 29 ++++------------------ crates/ra_ide_api/src/completion/complete_path.rs | 2 +- .../ra_ide_api/src/completion/complete_pattern.rs | 2 +- crates/ra_ide_api/src/completion/complete_scope.rs | 2 +- .../src/completion/completion_context.rs | 5 +--- 5 files changed, 9 insertions(+), 31 deletions(-) (limited to 'crates') 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}; use ra_syntax::{ SyntaxNode, AstPtr, ast::{self, AstNode, NameOwner}, - algo::{find_node_at_offset, find_token_at_offset}, + algo::find_node_at_offset, }; use crate::{ @@ -196,29 +196,6 @@ pub fn trait_from_module( Trait { id: ctx.to_def(trait_def) } } -pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver { - let file_id = position.file_id; - let file = db.parse(file_id); - find_token_at_offset(file.syntax(), position.offset) - .find_map(|token| { - token.parent().ancestors().find_map(|node| { - if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { - if let Some(func) = function_from_child_node(db, file_id, node) { - let scopes = func.scopes(db); - let scope = scopes.scope_for_offset(position.offset); - Some(expr::resolver_for_scope(func.body(db), db, scope)) - } else { - // FIXME const/static/array length - None - } - } else { - try_get_resolver_for_node(db, file_id, node) - } - }) - }) - .unwrap_or_default() -} - fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNode) -> Resolver { node.ancestors() .find_map(|node| { @@ -305,6 +282,10 @@ impl SourceAnalyzer { } } + pub fn resolver(&self) -> &Resolver { + &self.resolver + } + pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option { let expr_id = self.body_source_map.as_ref()?.node_expr(expr)?; Some(self.infer.as_ref()?[expr_id].clone()) diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 7e47fa6bd..e9bdf5af2 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -9,7 +9,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { Some(path) => path.clone(), _ => return, }; - let def = match ctx.resolver.resolve_path(ctx.db, &path).take_types() { + let def = match ctx.analyzer.resolver().resolve_path(ctx.db, &path).take_types() { Some(Resolution::Def(def)) => def, _ => return, }; diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index 7abcd019b..abbb83518 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs @@ -7,7 +7,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { } // FIXME: ideally, we should look at the type we are matching against and // suggest variants + auto-imports - let names = ctx.resolver.all_names(ctx.db); + let names = ctx.analyzer.resolver().all_names(ctx.db); for (name, res) in names.into_iter() { let r = res.as_ref(); let def = match r.take_types().or(r.take_values()) { diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 9d82f2270..4c5d07ce5 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -4,7 +4,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_trivial_path { return; } - let names = ctx.resolver.all_names(ctx.db); + let names = ctx.analyzer.resolver().all_names(ctx.db); names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); } diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 98cdccef7..86b30e787 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -5,7 +5,7 @@ use ra_syntax::{ algo::{find_token_at_offset, find_covering_element, find_node_at_offset}, SyntaxKind::*, }; -use hir::{source_binder, Resolver}; +use hir::source_binder; use crate::{db, FilePosition}; @@ -17,7 +17,6 @@ pub(crate) struct CompletionContext<'a> { pub(super) analyzer: hir::SourceAnalyzer, pub(super) offset: TextUnit, pub(super) token: SyntaxToken<'a>, - pub(super) resolver: Resolver, pub(super) module: Option, pub(super) function_syntax: Option<&'a ast::FnDef>, pub(super) use_item_syntax: Option<&'a ast::UseItem>, @@ -47,7 +46,6 @@ impl<'a> CompletionContext<'a> { original_file: &'a SourceFile, position: FilePosition, ) -> Option> { - let resolver = source_binder::resolver_for_position(db, position); let module = source_binder::module_from_position(db, position); let token = find_token_at_offset(original_file.syntax(), position.offset).left_biased()?; let analyzer = hir::SourceAnalyzer::new(db, position.file_id, token.parent()); @@ -56,7 +54,6 @@ impl<'a> CompletionContext<'a> { analyzer, token, offset: position.offset, - resolver, module, function_syntax: None, use_item_syntax: None, -- cgit v1.2.3