aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/completion_context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion/completion_context.rs')
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs31
1 files changed, 14 insertions, 17 deletions
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index fdc0da2c5..b8213d62f 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -35,10 +35,7 @@ pub(crate) struct CompletionContext<'a> {
35 pub(super) is_param: bool, 35 pub(super) is_param: bool,
36 /// If a name-binding or reference to a const in a pattern. 36 /// If a name-binding or reference to a const in a pattern.
37 /// Irrefutable patterns (like let) are excluded. 37 /// Irrefutable patterns (like let) are excluded.
38 pub(super) is_pat_binding: bool, 38 pub(super) is_pat_binding_or_const: bool,
39 // A bind battern which may also be part of a path.
40 // if let Some(En<|>) = Some(Enum::A)
41 pub(super) is_pat_binding_and_path: bool,
42 /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path. 39 /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
43 pub(super) is_trivial_path: bool, 40 pub(super) is_trivial_path: bool,
44 /// If not a trivial path, the prefix (qualifier). 41 /// If not a trivial path, the prefix (qualifier).
@@ -97,8 +94,7 @@ impl<'a> CompletionContext<'a> {
97 record_lit_pat: None, 94 record_lit_pat: None,
98 impl_def: None, 95 impl_def: None,
99 is_param: false, 96 is_param: false,
100 is_pat_binding: false, 97 is_pat_binding_or_const: false,
101 is_pat_binding_and_path: false,
102 is_trivial_path: false, 98 is_trivial_path: false,
103 path_prefix: None, 99 path_prefix: None,
104 after_if: false, 100 after_if: false,
@@ -190,18 +186,19 @@ impl<'a> CompletionContext<'a> {
190 // suggest declaration names, see `CompletionKind::Magic`. 186 // suggest declaration names, see `CompletionKind::Magic`.
191 if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) { 187 if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) {
192 if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { 188 if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) {
193 let parent = bind_pat.syntax().parent(); 189 self.is_pat_binding_or_const = true;
194 if parent.clone().and_then(ast::MatchArm::cast).is_some() 190 if bind_pat.has_at() || bind_pat.is_ref() || bind_pat.is_mutable() {
195 || parent.clone().and_then(ast::Condition::cast).is_some() 191 self.is_pat_binding_or_const = false;
196 {
197 self.is_pat_binding = true;
198 } 192 }
199 193 if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() {
200 if parent.and_then(ast::RecordFieldPatList::cast).is_none() 194 self.is_pat_binding_or_const = false;
201 && bind_pat.pat().is_none() 195 }
202 && !bind_pat.is_ref() 196 if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) {
203 { 197 if let Some(pat) = let_stmt.pat() {
204 self.is_pat_binding_and_path = true; 198 if bind_pat.syntax().text_range().is_subrange(&pat.syntax().text_range()) {
199 self.is_pat_binding_or_const = false;
200 }
201 }
205 } 202 }
206 } 203 }
207 if is_node::<ast::Param>(name.syntax()) { 204 if is_node::<ast::Param>(name.syntax()) {