diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-03 20:11:40 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-03 20:11:40 +0100 |
commit | 6207ac90da7e607218457bf872fa32df6b78f224 (patch) | |
tree | 222a315a1522e1cd99589233674e259303b56395 /crates/ra_ide/src/completion/completion_context.rs | |
parent | cde92d0fe1ad33706dc0804e3c39e4ef9a5e12b9 (diff) | |
parent | a5e8dfd0247648d8108386f4f98b3af0e48181f7 (diff) |
Merge #3840
3840: Add parens for enums r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/completion/completion_context.rs')
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 31 |
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()) { |