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.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index 58e35bad9..14d6ae54e 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -49,35 +49,35 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
49 return; 49 return;
50 } 50 }
51 51
52 let has_trait_or_impl_parent = ctx.has_impl_or_trait_parent(); 52 let expects_assoc_item = ctx.expects_assoc_item();
53 let has_block_expr_parent = ctx.has_block_expr_parent(); 53 let has_block_expr_parent = ctx.has_block_expr_parent();
54 let has_item_list_parent = ctx.has_item_list_parent(); 54 let expects_item = ctx.expects_item();
55 if ctx.has_impl_or_trait_prev_sibling() { 55 if ctx.has_impl_or_trait_prev_sibling() {
56 add_keyword(ctx, acc, "where", "where "); 56 add_keyword(ctx, acc, "where", "where ");
57 return; 57 return;
58 } 58 }
59 if ctx.previous_token_is(T![unsafe]) { 59 if ctx.previous_token_is(T![unsafe]) {
60 if has_item_list_parent || has_block_expr_parent { 60 if expects_item || has_block_expr_parent {
61 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}") 61 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}")
62 } 62 }
63 63
64 if has_item_list_parent || has_block_expr_parent { 64 if expects_item || has_block_expr_parent {
65 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}"); 65 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
66 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}"); 66 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
67 } 67 }
68 68
69 return; 69 return;
70 } 70 }
71 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent { 71 if expects_item || expects_assoc_item || has_block_expr_parent {
72 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}"); 72 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}");
73 } 73 }
74 if has_item_list_parent || has_block_expr_parent { 74 if expects_item || has_block_expr_parent {
75 add_keyword(ctx, acc, "use", "use "); 75 add_keyword(ctx, acc, "use", "use ");
76 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}"); 76 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
77 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}"); 77 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
78 } 78 }
79 79
80 if has_item_list_parent { 80 if expects_item {
81 add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}"); 81 add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}");
82 add_keyword(ctx, acc, "struct", "struct $0"); 82 add_keyword(ctx, acc, "struct", "struct $0");
83 add_keyword(ctx, acc, "union", "union $1 {\n $0\n}"); 83 add_keyword(ctx, acc, "union", "union $1 {\n $0\n}");
@@ -101,24 +101,23 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
101 add_keyword(ctx, acc, "else", "else {\n $0\n}"); 101 add_keyword(ctx, acc, "else", "else {\n $0\n}");
102 add_keyword(ctx, acc, "else if", "else if $1 {\n $0\n}"); 102 add_keyword(ctx, acc, "else if", "else if $1 {\n $0\n}");
103 } 103 }
104 if has_item_list_parent || has_block_expr_parent { 104 if expects_item || has_block_expr_parent {
105 add_keyword(ctx, acc, "mod", "mod $0"); 105 add_keyword(ctx, acc, "mod", "mod $0");
106 } 106 }
107 if ctx.has_ident_or_ref_pat_parent() { 107 if ctx.has_ident_or_ref_pat_parent() {
108 add_keyword(ctx, acc, "mut", "mut "); 108 add_keyword(ctx, acc, "mut", "mut ");
109 } 109 }
110 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent { 110 if expects_item || expects_assoc_item || has_block_expr_parent {
111 add_keyword(ctx, acc, "const", "const "); 111 add_keyword(ctx, acc, "const", "const ");
112 add_keyword(ctx, acc, "type", "type "); 112 add_keyword(ctx, acc, "type", "type ");
113 } 113 }
114 if has_item_list_parent || has_block_expr_parent { 114 if expects_item || has_block_expr_parent {
115 add_keyword(ctx, acc, "static", "static "); 115 add_keyword(ctx, acc, "static", "static ");
116 }; 116 };
117 if has_item_list_parent || has_block_expr_parent { 117 if expects_item || has_block_expr_parent {
118 add_keyword(ctx, acc, "extern", "extern "); 118 add_keyword(ctx, acc, "extern", "extern ");
119 } 119 }
120 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent || ctx.is_match_arm 120 if expects_item || expects_assoc_item || has_block_expr_parent || ctx.is_match_arm {
121 {
122 add_keyword(ctx, acc, "unsafe", "unsafe "); 121 add_keyword(ctx, acc, "unsafe", "unsafe ");
123 } 122 }
124 if ctx.in_loop_body { 123 if ctx.in_loop_body {
@@ -130,7 +129,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
130 add_keyword(ctx, acc, "break", "break"); 129 add_keyword(ctx, acc, "break", "break");
131 } 130 }
132 } 131 }
133 if has_item_list_parent || ctx.has_impl_parent() || ctx.has_field_list_parent() { 132 if expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field() {
134 add_keyword(ctx, acc, "pub(crate)", "pub(crate) "); 133 add_keyword(ctx, acc, "pub(crate)", "pub(crate) ");
135 add_keyword(ctx, acc, "pub", "pub "); 134 add_keyword(ctx, acc, "pub", "pub ");
136 } 135 }