aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/completion_context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_context.rs')
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index 65dffa470..359f2cffa 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};
8use hir::{source_binder, Resolver}; 8use hir::source_binder;
9 9
10use crate::{db, FilePosition}; 10use crate::{db, FilePosition};
11 11
@@ -14,11 +14,10 @@ use crate::{db, FilePosition};
14#[derive(Debug)] 14#[derive(Debug)]
15pub(crate) struct CompletionContext<'a> { 15pub(crate) struct CompletionContext<'a> {
16 pub(super) db: &'a db::RootDatabase, 16 pub(super) db: &'a db::RootDatabase,
17 pub(super) analyzer: hir::SourceAnalyzer,
17 pub(super) offset: TextUnit, 18 pub(super) offset: TextUnit,
18 pub(super) token: SyntaxToken<'a>, 19 pub(super) token: SyntaxToken<'a>,
19 pub(super) resolver: Resolver,
20 pub(super) module: Option<hir::Module>, 20 pub(super) module: Option<hir::Module>,
21 pub(super) function: Option<hir::Function>,
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>,
24 pub(super) struct_lit_syntax: Option<&'a ast::StructLit>, 23 pub(super) struct_lit_syntax: Option<&'a ast::StructLit>,
@@ -47,16 +46,16 @@ 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()?;
51 let analyzer =
52 hir::SourceAnalyzer::new(db, position.file_id, token.parent(), Some(position.offset));
53 let mut ctx = CompletionContext { 53 let mut ctx = CompletionContext {
54 db, 54 db,
55 analyzer,
55 token, 56 token,
56 offset: position.offset, 57 offset: position.offset,
57 resolver,
58 module, 58 module,
59 function: None,
60 function_syntax: None, 59 function_syntax: None,
61 use_item_syntax: None, 60 use_item_syntax: None,
62 struct_lit_syntax: None, 61 struct_lit_syntax: None,
@@ -147,10 +146,6 @@ impl<'a> CompletionContext<'a> {
147 .ancestors() 146 .ancestors()
148 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) 147 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
149 .find_map(ast::FnDef::cast); 148 .find_map(ast::FnDef::cast);
150 if let (Some(module), Some(fn_def)) = (self.module, self.function_syntax) {
151 let function = source_binder::function_from_module(self.db, module, fn_def);
152 self.function = Some(function);
153 }
154 149
155 let parent = match name_ref.syntax().parent() { 150 let parent = match name_ref.syntax().parent() {
156 Some(it) => it, 151 Some(it) => it,