From fb71185692367f4d80e5a466d2a45ccc28492680 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 16 Nov 2020 12:18:01 +0100 Subject: Don't complete keywords in struct literals --- crates/completion/src/completions/keyword.rs | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/crates/completion/src/completions/keyword.rs b/crates/completion/src/completions/keyword.rs index c7df15900..720349b9d 100644 --- a/crates/completion/src/completions/keyword.rs +++ b/crates/completion/src/completions/keyword.rs @@ -44,6 +44,10 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte mark::hit!(no_keyword_completion_in_comments); return; } + if ctx.record_lit_syntax.is_some() { + mark::hit!(no_keyword_completion_in_record_lit); + return; + } let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent; if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling { @@ -563,4 +567,46 @@ struct Foo { "#]], ) } + + #[test] + fn skip_struct_initializer() { + mark::check!(no_keyword_completion_in_record_lit); + check( + r#" +struct Foo { + pub f: i32, +} +fn foo() { + Foo { + <|> + } +} +"#, + expect![[r#""#]], + ); + } + + #[test] + fn struct_initializer_field_expr() { + check( + r#" +struct Foo { + pub f: i32, +} +fn foo() { + Foo { + f: <|> + } +} +"#, + expect![[r#" + kw if + kw if let + kw loop + kw match + kw return + kw while + "#]], + ); + } } -- cgit v1.2.3