diff options
author | Aleksey Kladov <[email protected]> | 2019-04-11 14:49:35 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-11 14:49:35 +0100 |
commit | ebb0c377f0ab99a0f5e6d0c776cb9b026b62b0e4 (patch) | |
tree | 49a2c265c83ae03182cf593c52ec8a0c155ad151 /crates | |
parent | 3c9f2d0e372cff6490dcd30411cb6cc1f691fde7 (diff) |
remove resolver from CompletonContext
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 29 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_pattern.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_context.rs | 5 |
5 files changed, 9 insertions, 31 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}; | |||
11 | use ra_syntax::{ | 11 | use 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 | ||
17 | use crate::{ | 17 | use 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 | ||
199 | pub 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 | |||
222 | fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNode) -> Resolver { | 199 | fn 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()) |
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) { | |||
9 | Some(path) => path.clone(), | 9 | Some(path) => path.clone(), |
10 | _ => return, | 10 | _ => return, |
11 | }; | 11 | }; |
12 | let def = match ctx.resolver.resolve_path(ctx.db, &path).take_types() { | 12 | let def = match ctx.analyzer.resolver().resolve_path(ctx.db, &path).take_types() { |
13 | Some(Resolution::Def(def)) => def, | 13 | Some(Resolution::Def(def)) => def, |
14 | _ => return, | 14 | _ => return, |
15 | }; | 15 | }; |
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) { | |||
7 | } | 7 | } |
8 | // FIXME: ideally, we should look at the type we are matching against and | 8 | // FIXME: ideally, we should look at the type we are matching against and |
9 | // suggest variants + auto-imports | 9 | // suggest variants + auto-imports |
10 | let names = ctx.resolver.all_names(ctx.db); | 10 | let names = ctx.analyzer.resolver().all_names(ctx.db); |
11 | for (name, res) in names.into_iter() { | 11 | for (name, res) in names.into_iter() { |
12 | let r = res.as_ref(); | 12 | let r = res.as_ref(); |
13 | let def = match r.take_types().or(r.take_values()) { | 13 | 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) { | |||
4 | if !ctx.is_trivial_path { | 4 | if !ctx.is_trivial_path { |
5 | return; | 5 | return; |
6 | } | 6 | } |
7 | let names = ctx.resolver.all_names(ctx.db); | 7 | let names = ctx.analyzer.resolver().all_names(ctx.db); |
8 | 8 | ||
9 | names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); | 9 | names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); |
10 | } | 10 | } |
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::{ | |||
5 | algo::{find_token_at_offset, find_covering_element, find_node_at_offset}, | 5 | algo::{find_token_at_offset, find_covering_element, find_node_at_offset}, |
6 | SyntaxKind::*, | 6 | SyntaxKind::*, |
7 | }; | 7 | }; |
8 | use hir::{source_binder, Resolver}; | 8 | use hir::source_binder; |
9 | 9 | ||
10 | use crate::{db, FilePosition}; | 10 | use crate::{db, FilePosition}; |
11 | 11 | ||
@@ -17,7 +17,6 @@ pub(crate) struct CompletionContext<'a> { | |||
17 | pub(super) analyzer: hir::SourceAnalyzer, | 17 | pub(super) analyzer: hir::SourceAnalyzer, |
18 | pub(super) offset: TextUnit, | 18 | pub(super) offset: TextUnit, |
19 | pub(super) token: SyntaxToken<'a>, | 19 | pub(super) token: SyntaxToken<'a>, |
20 | pub(super) resolver: Resolver, | ||
21 | pub(super) module: Option<hir::Module>, | 20 | pub(super) module: Option<hir::Module>, |
22 | pub(super) function_syntax: Option<&'a ast::FnDef>, | 21 | pub(super) function_syntax: Option<&'a ast::FnDef>, |
23 | pub(super) use_item_syntax: Option<&'a ast::UseItem>, | 22 | pub(super) use_item_syntax: Option<&'a ast::UseItem>, |
@@ -47,7 +46,6 @@ impl<'a> CompletionContext<'a> { | |||
47 | original_file: &'a SourceFile, | 46 | original_file: &'a SourceFile, |
48 | position: FilePosition, | 47 | position: FilePosition, |
49 | ) -> Option<CompletionContext<'a>> { | 48 | ) -> Option<CompletionContext<'a>> { |
50 | let resolver = source_binder::resolver_for_position(db, position); | ||
51 | let module = source_binder::module_from_position(db, position); | 49 | let module = source_binder::module_from_position(db, position); |
52 | let token = find_token_at_offset(original_file.syntax(), position.offset).left_biased()?; | 50 | let token = find_token_at_offset(original_file.syntax(), position.offset).left_biased()?; |
53 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, token.parent()); | 51 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, token.parent()); |
@@ -56,7 +54,6 @@ impl<'a> CompletionContext<'a> { | |||
56 | analyzer, | 54 | analyzer, |
57 | token, | 55 | token, |
58 | offset: position.offset, | 56 | offset: position.offset, |
59 | resolver, | ||
60 | module, | 57 | module, |
61 | function_syntax: None, | 58 | function_syntax: None, |
62 | use_item_syntax: None, | 59 | use_item_syntax: None, |