aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/completions/keyword.rs50
1 files changed, 29 insertions, 21 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index d2d0e4a98..fa6bcc955 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -56,40 +56,40 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
56 } 56 }
57 if ctx.previous_token_is(T![unsafe]) { 57 if ctx.previous_token_is(T![unsafe]) {
58 if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { 58 if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent {
59 add_keyword(ctx, acc, "fn", "fn $0() {}") 59 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}")
60 } 60 }
61 61
62 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 62 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent {
63 add_keyword(ctx, acc, "trait", "trait $0 {}"); 63 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
64 add_keyword(ctx, acc, "impl", "impl $0 {}"); 64 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
65 } 65 }
66 66
67 return; 67 return;
68 } 68 }
69 if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent 69 if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent
70 { 70 {
71 add_keyword(ctx, acc, "fn", "fn $0() {}"); 71 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}");
72 } 72 }
73 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 73 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent {
74 add_keyword(ctx, acc, "use", "use "); 74 add_keyword(ctx, acc, "use", "use ");
75 add_keyword(ctx, acc, "impl", "impl $0 {}"); 75 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
76 add_keyword(ctx, acc, "trait", "trait $0 {}"); 76 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
77 } 77 }
78 78
79 if ctx.has_item_list_or_source_file_parent { 79 if ctx.has_item_list_or_source_file_parent {
80 add_keyword(ctx, acc, "enum", "enum $0 {}"); 80 add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}");
81 add_keyword(ctx, acc, "struct", "struct $0"); 81 add_keyword(ctx, acc, "struct", "struct $0");
82 add_keyword(ctx, acc, "union", "union $0 {}"); 82 add_keyword(ctx, acc, "union", "union $1 {\n $0\n}");
83 } 83 }
84 84
85 if ctx.is_expr { 85 if ctx.is_expr {
86 add_keyword(ctx, acc, "match", "match $0 {}"); 86 add_keyword(ctx, acc, "match", "match $1 {\n $0\n}");
87 add_keyword(ctx, acc, "while", "while $0 {}"); 87 add_keyword(ctx, acc, "while", "while $1 {\n $0\n}");
88 add_keyword(ctx, acc, "while let", "while let $1 = $0 {}"); 88 add_keyword(ctx, acc, "while let", "while let $1 = $2 {\n $0\n}");
89 add_keyword(ctx, acc, "loop", "loop {$0}"); 89 add_keyword(ctx, acc, "loop", "loop {\n $0\n}");
90 add_keyword(ctx, acc, "if", "if $0 {}"); 90 add_keyword(ctx, acc, "if", "if $1 {\n $0\n}");
91 add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); 91 add_keyword(ctx, acc, "if let", "if let $1 = $2 {\n $0\n}");
92 add_keyword(ctx, acc, "for", "for $1 in $0 {}"); 92 add_keyword(ctx, acc, "for", "for $1 in $2 {\n $0\n}");
93 } 93 }
94 94
95 if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || ctx.block_expr_parent { 95 if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || ctx.block_expr_parent {
@@ -97,8 +97,8 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
97 } 97 }
98 98
99 if ctx.after_if { 99 if ctx.after_if {
100 add_keyword(ctx, acc, "else", "else {$0}"); 100 add_keyword(ctx, acc, "else", "else {\n $0\n}");
101 add_keyword(ctx, acc, "else if", "else if $0 {}"); 101 add_keyword(ctx, acc, "else if", "else if $1 {\n $0\n}");
102 } 102 }
103 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 103 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent {
104 add_keyword(ctx, acc, "mod", "mod $0"); 104 add_keyword(ctx, acc, "mod", "mod $0");
@@ -342,7 +342,9 @@ mod tests {
342 check_edit( 342 check_edit(
343 "else", 343 "else",
344 r#"fn quux() { if true { () } $0 }"#, 344 r#"fn quux() { if true { () } $0 }"#,
345 r#"fn quux() { if true { () } else {$0} }"#, 345 r#"fn quux() { if true { () } else {
346 $0
347} }"#,
346 ); 348 );
347 } 349 }
348 350
@@ -646,7 +648,9 @@ fn foo() {
646fn main() { let x = $0 } 648fn main() { let x = $0 }
647"#, 649"#,
648 r#" 650 r#"
649fn main() { let x = match $0 {}; } 651fn main() { let x = match $1 {
652 $0
653}; }
650"#, 654"#,
651 ); 655 );
652 656
@@ -660,7 +664,9 @@ fn main() {
660"#, 664"#,
661 r#" 665 r#"
662fn main() { 666fn main() {
663 let x = if $0 {}; 667 let x = if $1 {
668 $0
669};
664 let y = 92; 670 let y = 92;
665} 671}
666"#, 672"#,
@@ -676,7 +682,9 @@ fn main() {
676"#, 682"#,
677 r#" 683 r#"
678fn main() { 684fn main() {
679 let x = loop {$0}; 685 let x = loop {
686 $0
687};
680 bar(); 688 bar();
681} 689}
682"#, 690"#,