aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/completions
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-01-15 12:49:59 +0000
committerAleksey Kladov <[email protected]>2021-01-15 12:49:59 +0000
commitf2ba2048d1afb816623d037f265f4445a2f44b54 (patch)
treee5b5f19b0207028a0ac99d7b211d843cba6f9b8c /crates/completion/src/completions
parent41ea2602017027e22f5a68df3d6ad98e2ae880f8 (diff)
Insert `;` when completing keywords in let
Diffstat (limited to 'crates/completion/src/completions')
-rw-r--r--crates/completion/src/completions/keyword.rs58
1 files changed, 57 insertions, 1 deletions
diff --git a/crates/completion/src/completions/keyword.rs b/crates/completion/src/completions/keyword.rs
index effc3e4bf..c1af348dc 100644
--- a/crates/completion/src/completions/keyword.rs
+++ b/crates/completion/src/completions/keyword.rs
@@ -161,7 +161,17 @@ fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet
161 let builder = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), kw) 161 let builder = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), kw)
162 .kind(CompletionItemKind::Keyword); 162 .kind(CompletionItemKind::Keyword);
163 let builder = match ctx.config.snippet_cap { 163 let builder = match ctx.config.snippet_cap {
164 Some(cap) => builder.insert_snippet(cap, snippet), 164 Some(cap) => {
165 let tmp;
166 let snippet = if snippet.ends_with('}') && ctx.incomplete_let {
167 mark::hit!(let_semi);
168 tmp = format!("{};", snippet);
169 &tmp
170 } else {
171 snippet
172 };
173 builder.insert_snippet(cap, snippet)
174 }
165 None => builder.insert_text(if snippet.contains('$') { kw } else { snippet }), 175 None => builder.insert_text(if snippet.contains('$') { kw } else { snippet }),
166 }; 176 };
167 acc.add(builder.build()); 177 acc.add(builder.build());
@@ -601,4 +611,50 @@ fn foo() {
601 "#]], 611 "#]],
602 ); 612 );
603 } 613 }
614
615 #[test]
616 fn let_semi() {
617 mark::check!(let_semi);
618 check_edit(
619 "match",
620 r#"
621fn main() { let x = $0 }
622"#,
623 r#"
624fn main() { let x = match $0 {}; }
625"#,
626 );
627
628 check_edit(
629 "if",
630 r#"
631fn main() {
632 let x = $0
633 let y = 92;
634}
635"#,
636 r#"
637fn main() {
638 let x = if $0 {};
639 let y = 92;
640}
641"#,
642 );
643
644 check_edit(
645 "loop",
646 r#"
647fn main() {
648 let x = $0
649 bar();
650}
651"#,
652 r#"
653fn main() {
654 let x = loop {$0};
655 bar();
656}
657"#,
658 );
659 }
604} 660}