Skip to content

Commit 789d9ca

Browse files
bors[bot]Veykril
andauthored
Merge #6563
6563: Don't complete keywords in struct initializers r=matklad a=Veykril Fixes #6562 Co-authored-by: Lukas Wirth <[email protected]>
2 parents e17d604 + fb71185 commit 789d9ca

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

crates/completion/src/completions/keyword.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
4444
mark::hit!(no_keyword_completion_in_comments);
4545
return;
4646
}
47+
if ctx.record_lit_syntax.is_some() {
48+
mark::hit!(no_keyword_completion_in_record_lit);
49+
return;
50+
}
4751

4852
let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent;
4953
if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling {
@@ -563,4 +567,46 @@ struct Foo {
563567
"#]],
564568
)
565569
}
570+
571+
#[test]
572+
fn skip_struct_initializer() {
573+
mark::check!(no_keyword_completion_in_record_lit);
574+
check(
575+
r#"
576+
struct Foo {
577+
pub f: i32,
578+
}
579+
fn foo() {
580+
Foo {
581+
<|>
582+
}
583+
}
584+
"#,
585+
expect![[r#""#]],
586+
);
587+
}
588+
589+
#[test]
590+
fn struct_initializer_field_expr() {
591+
check(
592+
r#"
593+
struct Foo {
594+
pub f: i32,
595+
}
596+
fn foo() {
597+
Foo {
598+
f: <|>
599+
}
600+
}
601+
"#,
602+
expect![[r#"
603+
kw if
604+
kw if let
605+
kw loop
606+
kw match
607+
kw return
608+
kw while
609+
"#]],
610+
);
611+
}
566612
}

0 commit comments

Comments
 (0)