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.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index fa6bcc955..58e35bad9 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -49,34 +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_parent || ctx.has_trait_parent; 52 let has_trait_or_impl_parent = ctx.has_impl_or_trait_parent();
53 if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling { 53 let has_block_expr_parent = ctx.has_block_expr_parent();
54 let has_item_list_parent = ctx.has_item_list_parent();
55 if ctx.has_impl_or_trait_prev_sibling() {
54 add_keyword(ctx, acc, "where", "where "); 56 add_keyword(ctx, acc, "where", "where ");
55 return; 57 return;
56 } 58 }
57 if ctx.previous_token_is(T![unsafe]) { 59 if ctx.previous_token_is(T![unsafe]) {
58 if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { 60 if has_item_list_parent || has_block_expr_parent {
59 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}") 61 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}")
60 } 62 }
61 63
62 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 64 if has_item_list_parent || has_block_expr_parent {
63 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}"); 65 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
64 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}"); 66 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
65 } 67 }
66 68
67 return; 69 return;
68 } 70 }
69 if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent 71 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent {
70 {
71 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}"); 72 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}");
72 } 73 }
73 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 74 if has_item_list_parent || has_block_expr_parent {
74 add_keyword(ctx, acc, "use", "use "); 75 add_keyword(ctx, acc, "use", "use ");
75 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}"); 76 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
76 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}"); 77 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
77 } 78 }
78 79
79 if ctx.has_item_list_or_source_file_parent { 80 if has_item_list_parent {
80 add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}"); 81 add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}");
81 add_keyword(ctx, acc, "struct", "struct $0"); 82 add_keyword(ctx, acc, "struct", "struct $0");
82 add_keyword(ctx, acc, "union", "union $1 {\n $0\n}"); 83 add_keyword(ctx, acc, "union", "union $1 {\n $0\n}");
@@ -92,7 +93,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
92 add_keyword(ctx, acc, "for", "for $1 in $2 {\n $0\n}"); 93 add_keyword(ctx, acc, "for", "for $1 in $2 {\n $0\n}");
93 } 94 }
94 95
95 if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || ctx.block_expr_parent { 96 if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || has_block_expr_parent {
96 add_keyword(ctx, acc, "let", "let "); 97 add_keyword(ctx, acc, "let", "let ");
97 } 98 }
98 99
@@ -100,27 +101,23 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
100 add_keyword(ctx, acc, "else", "else {\n $0\n}"); 101 add_keyword(ctx, acc, "else", "else {\n $0\n}");
101 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}");
102 } 103 }
103 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 104 if has_item_list_parent || has_block_expr_parent {
104 add_keyword(ctx, acc, "mod", "mod $0"); 105 add_keyword(ctx, acc, "mod", "mod $0");
105 } 106 }
106 if ctx.bind_pat_parent || ctx.ref_pat_parent { 107 if ctx.has_ident_or_ref_pat_parent() {
107 add_keyword(ctx, acc, "mut", "mut "); 108 add_keyword(ctx, acc, "mut", "mut ");
108 } 109 }
109 if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent 110 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent {
110 {
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 (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 114 if has_item_list_parent || has_block_expr_parent {
115 add_keyword(ctx, acc, "static", "static "); 115 add_keyword(ctx, acc, "static", "static ");
116 }; 116 };
117 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 117 if has_item_list_parent || has_block_expr_parent {
118 add_keyword(ctx, acc, "extern", "extern "); 118 add_keyword(ctx, acc, "extern", "extern ");
119 } 119 }
120 if ctx.has_item_list_or_source_file_parent 120 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent || ctx.is_match_arm
121 || has_trait_or_impl_parent
122 || ctx.block_expr_parent
123 || ctx.is_match_arm
124 { 121 {
125 add_keyword(ctx, acc, "unsafe", "unsafe "); 122 add_keyword(ctx, acc, "unsafe", "unsafe ");
126 } 123 }
@@ -133,7 +130,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
133 add_keyword(ctx, acc, "break", "break"); 130 add_keyword(ctx, acc, "break", "break");
134 } 131 }
135 } 132 }
136 if ctx.has_item_list_or_source_file_parent || ctx.has_impl_parent | ctx.has_field_list_parent { 133 if has_item_list_parent || ctx.has_impl_parent() || ctx.has_field_list_parent() {
137 add_keyword(ctx, acc, "pub(crate)", "pub(crate) "); 134 add_keyword(ctx, acc, "pub(crate)", "pub(crate) ");
138 add_keyword(ctx, acc, "pub", "pub "); 135 add_keyword(ctx, acc, "pub", "pub ");
139 } 136 }
@@ -141,7 +138,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
141 if !ctx.is_trivial_path { 138 if !ctx.is_trivial_path {
142 return; 139 return;
143 } 140 }
144 let fn_def = match &ctx.function_syntax { 141 let fn_def = match &ctx.function_def {
145 Some(it) => it, 142 Some(it) => it,
146 None => return, 143 None => return,
147 }; 144 };