aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/keyword.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/keyword.rs')
-rw-r--r--crates/ide_completion/src/completions/keyword.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index e71a04b6e..0d035c611 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -4,7 +4,10 @@ use std::iter;
4 4
5use syntax::{SyntaxKind, T}; 5use syntax::{SyntaxKind, T};
6 6
7use crate::{CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions}; 7use crate::{
8 patterns::ImmediateLocation, CompletionContext, CompletionItem, CompletionItemKind,
9 CompletionKind, Completions,
10};
8 11
9pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) { 12pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) {
10 // complete keyword "crate" in use stmt 13 // complete keyword "crate" in use stmt
@@ -44,7 +47,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
44 cov_mark::hit!(no_keyword_completion_in_comments); 47 cov_mark::hit!(no_keyword_completion_in_comments);
45 return; 48 return;
46 } 49 }
47 if ctx.record_lit_syntax.is_some() { 50 if matches!(ctx.completion_location, Some(ImmediateLocation::RecordExpr(_))) {
48 cov_mark::hit!(no_keyword_completion_in_record_lit); 51 cov_mark::hit!(no_keyword_completion_in_record_lit);
49 return; 52 return;
50 } 53 }
@@ -55,7 +58,6 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
55 let expects_item = ctx.expects_item(); 58 let expects_item = ctx.expects_item();
56 59
57 if ctx.has_impl_or_trait_prev_sibling() { 60 if ctx.has_impl_or_trait_prev_sibling() {
58 // FIXME this also incorrectly shows up after a complete trait/impl
59 add_keyword("where", "where "); 61 add_keyword("where", "where ");
60 return; 62 return;
61 } 63 }
@@ -77,11 +79,8 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
77 add_keyword("pub", "pub "); 79 add_keyword("pub", "pub ");
78 } 80 }
79 81
80 if expects_item || expects_assoc_item || has_block_expr_parent || ctx.is_match_arm {
81 add_keyword("unsafe", "unsafe ");
82 }
83
84 if expects_item || expects_assoc_item || has_block_expr_parent { 82 if expects_item || expects_assoc_item || has_block_expr_parent {
83 add_keyword("unsafe", "unsafe ");
85 add_keyword("fn", "fn $1($2) {\n $0\n}"); 84 add_keyword("fn", "fn $1($2) {\n $0\n}");
86 add_keyword("const", "const $0"); 85 add_keyword("const", "const $0");
87 add_keyword("type", "type $0"); 86 add_keyword("type", "type $0");
@@ -103,6 +102,9 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
103 } 102 }
104 103
105 if ctx.expects_expression() { 104 if ctx.expects_expression() {
105 if !has_block_expr_parent {
106 add_keyword("unsafe", "unsafe {\n $0\n}");
107 }
106 add_keyword("match", "match $1 {\n $0\n}"); 108 add_keyword("match", "match $1 {\n $0\n}");
107 add_keyword("while", "while $1 {\n $0\n}"); 109 add_keyword("while", "while $1 {\n $0\n}");
108 add_keyword("while let", "while let $1 = $2 {\n $0\n}"); 110 add_keyword("while let", "while let $1 = $2 {\n $0\n}");
@@ -574,6 +576,7 @@ pub mod future {
574 check( 576 check(
575 r#"fn main() { let _ = $0 }"#, 577 r#"fn main() { let _ = $0 }"#,
576 expect![[r#" 578 expect![[r#"
579 kw unsafe
577 kw match 580 kw match
578 kw while 581 kw while
579 kw while let 582 kw while let
@@ -634,6 +637,7 @@ fn foo() {
634} 637}
635"#, 638"#,
636 expect![[r#" 639 expect![[r#"
640 kw unsafe
637 kw match 641 kw match
638 kw while 642 kw while
639 kw while let 643 kw while let