6563: Don't complete keywords in struct initializers r=matklad a=Veykril

Fixes #6562

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2020-11-16 11:49:48 +00:00 committed by GitHub
commit 789d9ca1d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
"#]],
);
}
}