aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/completions/pattern.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-02-09 20:32:05 +0000
committerLukas Wirth <[email protected]>2021-02-09 20:35:02 +0000
commit5454559c0a45d208db963df105f22f5e17f0340a (patch)
tree6038de6fd6a16ad6edef22a4bef9bd323071dc99 /crates/completion/src/completions/pattern.rs
parent5d4ae1c8e3b76798fcb5eb656d886fe65a2c7277 (diff)
Show qualified variant pattern completions
Diffstat (limited to 'crates/completion/src/completions/pattern.rs')
-rw-r--r--crates/completion/src/completions/pattern.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/completion/src/completions/pattern.rs b/crates/completion/src/completions/pattern.rs
index 43a5160cb..9282c3827 100644
--- a/crates/completion/src/completions/pattern.rs
+++ b/crates/completion/src/completions/pattern.rs
@@ -11,6 +11,12 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
11 return; 11 return;
12 } 12 }
13 13
14 if let Some(ty) = &ctx.expected_type {
15 super::complete_enum_variants(acc, ctx, ty, |acc, ctx, variant, path| {
16 acc.add_qualified_variant_pat(ctx, variant, path)
17 });
18 }
19
14 // FIXME: ideally, we should look at the type we are matching against and 20 // FIXME: ideally, we should look at the type we are matching against and
15 // suggest variants + auto-imports 21 // suggest variants + auto-imports
16 ctx.scope.process_all_names(&mut |name, res| { 22 ctx.scope.process_all_names(&mut |name, res| {
@@ -286,4 +292,26 @@ impl Foo {
286 "#]], 292 "#]],
287 ) 293 )
288 } 294 }
295
296 #[test]
297 fn completes_qualified_variant() {
298 check_snippet(
299 r#"
300enum Foo {
301 Bar { baz: i32 }
302}
303impl Foo {
304 fn foo() {
305 match {Foo::Bar { baz: 0 }} {
306 B$0
307 }
308 }
309}
310 "#,
311 expect![[r#"
312 bn Self::Bar Self::Bar { baz$1 }$0
313 bn Foo::Bar Foo::Bar { baz$1 }$0
314 "#]],
315 )
316 }
289} 317}