diff options
Diffstat (limited to 'crates/ra_ide/src/completion/completion_context.rs')
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 8b3401595..dd9cc7daa 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -11,7 +11,7 @@ use ra_syntax::{ | |||
11 | }; | 11 | }; |
12 | use ra_text_edit::AtomTextEdit; | 12 | use ra_text_edit::AtomTextEdit; |
13 | 13 | ||
14 | use crate::{completion::CompletionConfig, FilePosition}; | 14 | use crate::{call_info::call_info, completion::CompletionConfig, CallInfo, FilePosition}; |
15 | 15 | ||
16 | /// `CompletionContext` is created early during completion to figure out, where | 16 | /// `CompletionContext` is created early during completion to figure out, where |
17 | /// exactly is the cursor, syntax-wise. | 17 | /// exactly is the cursor, syntax-wise. |
@@ -21,6 +21,7 @@ pub(crate) struct CompletionContext<'a> { | |||
21 | pub(super) db: &'a RootDatabase, | 21 | pub(super) db: &'a RootDatabase, |
22 | pub(super) config: &'a CompletionConfig, | 22 | pub(super) config: &'a CompletionConfig, |
23 | pub(super) offset: TextUnit, | 23 | pub(super) offset: TextUnit, |
24 | pub(super) file_position: FilePosition, | ||
24 | /// The token before the cursor, in the original file. | 25 | /// The token before the cursor, in the original file. |
25 | pub(super) original_token: SyntaxToken, | 26 | pub(super) original_token: SyntaxToken, |
26 | /// The token before the cursor, in the macro-expanded file. | 27 | /// The token before the cursor, in the macro-expanded file. |
@@ -31,7 +32,9 @@ pub(crate) struct CompletionContext<'a> { | |||
31 | pub(super) use_item_syntax: Option<ast::UseItem>, | 32 | pub(super) use_item_syntax: Option<ast::UseItem>, |
32 | pub(super) record_lit_syntax: Option<ast::RecordLit>, | 33 | pub(super) record_lit_syntax: Option<ast::RecordLit>, |
33 | pub(super) record_pat_syntax: Option<ast::RecordPat>, | 34 | pub(super) record_pat_syntax: Option<ast::RecordPat>, |
35 | pub(super) record_field_syntax: Option<ast::RecordField>, | ||
34 | pub(super) impl_def: Option<ast::ImplDef>, | 36 | pub(super) impl_def: Option<ast::ImplDef>, |
37 | pub(super) call_info: Option<CallInfo>, | ||
35 | pub(super) is_param: bool, | 38 | pub(super) is_param: bool, |
36 | /// If a name-binding or reference to a const in a pattern. | 39 | /// If a name-binding or reference to a const in a pattern. |
37 | /// Irrefutable patterns (like let) are excluded. | 40 | /// Irrefutable patterns (like let) are excluded. |
@@ -88,12 +91,15 @@ impl<'a> CompletionContext<'a> { | |||
88 | original_token, | 91 | original_token, |
89 | token, | 92 | token, |
90 | offset: position.offset, | 93 | offset: position.offset, |
94 | file_position: position, | ||
91 | krate, | 95 | krate, |
92 | name_ref_syntax: None, | 96 | name_ref_syntax: None, |
93 | function_syntax: None, | 97 | function_syntax: None, |
98 | call_info: None, | ||
94 | use_item_syntax: None, | 99 | use_item_syntax: None, |
95 | record_lit_syntax: None, | 100 | record_lit_syntax: None, |
96 | record_pat_syntax: None, | 101 | record_pat_syntax: None, |
102 | record_field_syntax: None, | ||
97 | impl_def: None, | 103 | impl_def: None, |
98 | is_param: false, | 104 | is_param: false, |
99 | is_pat_binding_or_const: false, | 105 | is_pat_binding_or_const: false, |
@@ -262,12 +268,22 @@ impl<'a> CompletionContext<'a> { | |||
262 | self.use_item_syntax = | 268 | self.use_item_syntax = |
263 | self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast); | 269 | self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast); |
264 | 270 | ||
271 | self.call_info = call_info(self.db, self.file_position); | ||
272 | |||
265 | self.function_syntax = self | 273 | self.function_syntax = self |
266 | .sema | 274 | .sema |
267 | .ancestors_with_macros(self.token.parent()) | 275 | .ancestors_with_macros(self.token.parent()) |
268 | .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) | 276 | .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) |
269 | .find_map(ast::FnDef::cast); | 277 | .find_map(ast::FnDef::cast); |
270 | 278 | ||
279 | self.record_field_syntax = self | ||
280 | .sema | ||
281 | .ancestors_with_macros(self.token.parent()) | ||
282 | .take_while(|it| { | ||
283 | it.kind() != SOURCE_FILE && it.kind() != MODULE && it.kind() != CALL_EXPR | ||
284 | }) | ||
285 | .find_map(ast::RecordField::cast); | ||
286 | |||
271 | let parent = match name_ref.syntax().parent() { | 287 | let parent = match name_ref.syntax().parent() { |
272 | Some(it) => it, | 288 | Some(it) => it, |
273 | None => return, | 289 | None => return, |