aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/pattern.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/pattern.rs')
-rw-r--r--crates/ide_completion/src/completions/pattern.rs40
1 files changed, 32 insertions, 8 deletions
diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs
index 3329a4844..b84e9a967 100644
--- a/crates/ide_completion/src/completions/pattern.rs
+++ b/crates/ide_completion/src/completions/pattern.rs
@@ -1,17 +1,14 @@
1//! Completes constants and paths in patterns. 1//! Completes constants and paths in patterns.
2 2
3use crate::{context::IsPatOrConst, CompletionContext, Completions}; 3use crate::{context::PatternRefutability, CompletionContext, Completions};
4 4
5/// Completes constants and paths in patterns. 5/// Completes constants and paths in patterns.
6pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { 6pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
7 if ctx.is_pat_or_const == IsPatOrConst::No { 7 let refutable = match ctx.is_pat_or_const {
8 return; 8 Some(it) => it == PatternRefutability::Refutable,
9 } 9 None => return,
10 if ctx.record_pat_syntax.is_some() { 10 };
11 return;
12 }
13 11
14 let refutable = ctx.is_pat_or_const == IsPatOrConst::Refutable;
15 if refutable { 12 if refutable {
16 if let Some(hir::Adt::Enum(e)) = 13 if let Some(hir::Adt::Enum(e)) =
17 ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) 14 ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt())
@@ -403,4 +400,31 @@ impl Foo {
403 "#]], 400 "#]],
404 ) 401 )
405 } 402 }
403
404 #[test]
405 fn completes_in_record_field_pat() {
406 check_snippet(
407 r#"
408struct Foo { bar: Bar }
409struct Bar(u32);
410fn outer(Foo { bar: $0 }: Foo) {}
411"#,
412 expect![[r#"
413 bn Foo Foo { bar$1 }$0
414 bn Bar Bar($1)$0
415 "#]],
416 )
417 }
418
419 #[test]
420 fn skips_in_record_field_pat_name() {
421 check_snippet(
422 r#"
423struct Foo { bar: Bar }
424struct Bar(u32);
425fn outer(Foo { bar$0 }: Foo) {}
426"#,
427 expect![[r#""#]],
428 )
429 }
406} 430}