diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-20 07:32:19 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-20 07:32:19 +0000 |
commit | 1878fbe8bd60c7f9e58fda6dc7788e5f44ad0f89 (patch) | |
tree | 5dd13a24ef92a10bd686a80bbb2e59b83bf015d0 /crates/ra_ide/src/completion/completion_context.rs | |
parent | 1ba03c6995015b3143a417ed07437f0c9028a97d (diff) | |
parent | ec24c090063b3b86349f7812b716412d83dad069 (diff) |
Merge #3541
3541: Completition for type name? #3418 r=matklad a=slyngbaek
Iterate through TupleStructPat's until a MatchArm if
one exists. Store in a new is_pat_bind_and_path bool
and allow the `complete_scope` to find matches.
Added some tests to ensure it works in simple and nested cases.
Co-authored-by: Steffen Lyngbaek <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/completion/completion_context.rs')
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 54589a2a8..319e33b61 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -36,6 +36,9 @@ pub(crate) struct CompletionContext<'a> { | |||
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: 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, | ||
39 | /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path. | 42 | /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path. |
40 | pub(super) is_trivial_path: bool, | 43 | pub(super) is_trivial_path: bool, |
41 | /// If not a trivial path, the prefix (qualifier). | 44 | /// If not a trivial path, the prefix (qualifier). |
@@ -95,6 +98,7 @@ impl<'a> CompletionContext<'a> { | |||
95 | impl_def: None, | 98 | impl_def: None, |
96 | is_param: false, | 99 | is_param: false, |
97 | is_pat_binding: false, | 100 | is_pat_binding: false, |
101 | is_pat_binding_and_path: false, | ||
98 | is_trivial_path: false, | 102 | is_trivial_path: false, |
99 | path_prefix: None, | 103 | path_prefix: None, |
100 | after_if: false, | 104 | after_if: false, |
@@ -188,10 +192,17 @@ impl<'a> CompletionContext<'a> { | |||
188 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { | 192 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { |
189 | let parent = bind_pat.syntax().parent(); | 193 | let parent = bind_pat.syntax().parent(); |
190 | if parent.clone().and_then(ast::MatchArm::cast).is_some() | 194 | if parent.clone().and_then(ast::MatchArm::cast).is_some() |
191 | || parent.and_then(ast::Condition::cast).is_some() | 195 | || parent.clone().and_then(ast::Condition::cast).is_some() |
192 | { | 196 | { |
193 | self.is_pat_binding = true; | 197 | self.is_pat_binding = true; |
194 | } | 198 | } |
199 | |||
200 | if parent.and_then(ast::RecordFieldPatList::cast).is_none() | ||
201 | && bind_pat.pat().is_none() | ||
202 | && !bind_pat.is_ref() | ||
203 | { | ||
204 | self.is_pat_binding_and_path = true; | ||
205 | } | ||
195 | } | 206 | } |
196 | if is_node::<ast::Param>(name.syntax()) { | 207 | if is_node::<ast::Param>(name.syntax()) { |
197 | self.is_param = true; | 208 | self.is_param = true; |