aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-11-16 11:49:48 +0000
committerGitHub <[email protected]>2020-11-16 11:49:48 +0000
commit789d9ca1d32afd55c7cb8d0db45652048abd7341 (patch)
tree3017eb7e6f8c18376bf0fa7daa36aa515b97a395 /crates/completion/src
parente17d6048886c3ff0ba5e065c2fec5eff145b0fdc (diff)
parentfb71185692367f4d80e5a466d2a45ccc28492680 (diff)
Merge #6563
6563: Don't complete keywords in struct initializers r=matklad a=Veykril Fixes #6562 Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/completion/src')
-rw-r--r--crates/completion/src/completions/keyword.rs46
1 files changed, 46 insertions, 0 deletions
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
44 mark::hit!(no_keyword_completion_in_comments); 44 mark::hit!(no_keyword_completion_in_comments);
45 return; 45 return;
46 } 46 }
47 if ctx.record_lit_syntax.is_some() {
48 mark::hit!(no_keyword_completion_in_record_lit);
49 return;
50 }
47 51
48 let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent; 52 let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent;
49 if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling { 53 if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling {
@@ -563,4 +567,46 @@ struct Foo {
563 "#]], 567 "#]],
564 ) 568 )
565 } 569 }
570
571 #[test]
572 fn skip_struct_initializer() {
573 mark::check!(no_keyword_completion_in_record_lit);
574 check(
575 r#"
576struct Foo {
577 pub f: i32,
578}
579fn 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#"
593struct Foo {
594 pub f: i32,
595}
596fn 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 }
566} 612}