diff options
Diffstat (limited to 'crates/completion/src/completions')
-rw-r--r-- | crates/completion/src/completions/pattern.rs | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/crates/completion/src/completions/pattern.rs b/crates/completion/src/completions/pattern.rs index ba9921a44..eee31098d 100644 --- a/crates/completion/src/completions/pattern.rs +++ b/crates/completion/src/completions/pattern.rs | |||
@@ -1,7 +1,5 @@ | |||
1 | //! Completes constats and paths in patterns. | 1 | //! Completes constats and paths in patterns. |
2 | 2 | ||
3 | use hir::StructKind; | ||
4 | |||
5 | use crate::{CompletionContext, Completions}; | 3 | use crate::{CompletionContext, Completions}; |
6 | 4 | ||
7 | /// Completes constants and paths in patterns. | 5 | /// Completes constants and paths in patterns. |
@@ -22,11 +20,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
22 | acc.add_struct_pat(ctx, strukt.clone(), Some(name.clone())); | 20 | acc.add_struct_pat(ctx, strukt.clone(), Some(name.clone())); |
23 | true | 21 | true |
24 | } | 22 | } |
25 | hir::ModuleDef::Variant(variant) | 23 | hir::ModuleDef::Variant(variant) if !ctx.is_irrefutable_pat_binding => { |
26 | if !ctx.is_irrefutable_pat_binding | ||
27 | // render_resolution already does some pattern completion tricks for tuple variants | ||
28 | && variant.kind(ctx.db) == StructKind::Record => | ||
29 | { | ||
30 | acc.add_variant_pat(ctx, variant.clone(), Some(name.clone())); | 24 | acc.add_variant_pat(ctx, variant.clone(), Some(name.clone())); |
31 | true | 25 | true |
32 | } | 26 | } |
@@ -49,7 +43,10 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
49 | mod tests { | 43 | mod tests { |
50 | use expect_test::{expect, Expect}; | 44 | use expect_test::{expect, Expect}; |
51 | 45 | ||
52 | use crate::{test_utils::completion_list, CompletionKind}; | 46 | use crate::{ |
47 | test_utils::{check_edit, completion_list}, | ||
48 | CompletionKind, | ||
49 | }; | ||
53 | 50 | ||
54 | fn check(ra_fixture: &str, expect: Expect) { | 51 | fn check(ra_fixture: &str, expect: Expect) { |
55 | let actual = completion_list(ra_fixture, CompletionKind::Reference); | 52 | let actual = completion_list(ra_fixture, CompletionKind::Reference); |
@@ -81,7 +78,7 @@ fn foo() { | |||
81 | en E | 78 | en E |
82 | ct Z | 79 | ct Z |
83 | st Bar | 80 | st Bar |
84 | ev X () | 81 | ev X |
85 | md m | 82 | md m |
86 | "#]], | 83 | "#]], |
87 | ); | 84 | ); |
@@ -238,4 +235,27 @@ fn outer() { | |||
238 | "#]], | 235 | "#]], |
239 | ) | 236 | ) |
240 | } | 237 | } |
238 | |||
239 | #[test] | ||
240 | fn only_shows_ident_completion() { | ||
241 | check_edit( | ||
242 | "Foo", | ||
243 | r#" | ||
244 | struct Foo(i32); | ||
245 | fn main() { | ||
246 | match Foo(92) { | ||
247 | <|>(92) => (), | ||
248 | } | ||
249 | } | ||
250 | "#, | ||
251 | r#" | ||
252 | struct Foo(i32); | ||
253 | fn main() { | ||
254 | match Foo(92) { | ||
255 | Foo(92) => (), | ||
256 | } | ||
257 | } | ||
258 | "#, | ||
259 | ); | ||
260 | } | ||
241 | } | 261 | } |