From 1f897f7319da4852eac53ff765ed4e5b66a31b67 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 26 May 2021 23:46:00 +0200 Subject: Set `record_pat_syntax` more precisely in CompletionContext --- crates/ide_completion/src/completions/pattern.rs | 40 +++++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'crates/ide_completion/src/completions') 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 @@ //! Completes constants and paths in patterns. -use crate::{context::IsPatOrConst, CompletionContext, Completions}; +use crate::{context::PatternRefutability, CompletionContext, Completions}; /// Completes constants and paths in patterns. pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { - if ctx.is_pat_or_const == IsPatOrConst::No { - return; - } - if ctx.record_pat_syntax.is_some() { - return; - } + let refutable = match ctx.is_pat_or_const { + Some(it) => it == PatternRefutability::Refutable, + None => return, + }; - let refutable = ctx.is_pat_or_const == IsPatOrConst::Refutable; if refutable { if let Some(hir::Adt::Enum(e)) = ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) @@ -403,4 +400,31 @@ impl Foo { "#]], ) } + + #[test] + fn completes_in_record_field_pat() { + check_snippet( + r#" +struct Foo { bar: Bar } +struct Bar(u32); +fn outer(Foo { bar: $0 }: Foo) {} +"#, + expect![[r#" + bn Foo Foo { bar$1 }$0 + bn Bar Bar($1)$0 + "#]], + ) + } + + #[test] + fn skips_in_record_field_pat_name() { + check_snippet( + r#" +struct Foo { bar: Bar } +struct Bar(u32); +fn outer(Foo { bar$0 }: Foo) {} +"#, + expect![[r#""#]], + ) + } } -- cgit v1.2.3