|
5 | 5 | use syntax::T; |
6 | 6 |
|
7 | 7 | use crate::{ |
8 | | - context::{PathCompletionCtx, PathKind}, |
9 | | - patterns::ImmediateLocation, |
10 | | - CompletionContext, CompletionItem, CompletionItemKind, Completions, |
| 8 | + context::PathKind, patterns::ImmediateLocation, CompletionContext, CompletionItem, |
| 9 | + CompletionItemKind, Completions, |
11 | 10 | }; |
12 | 11 |
|
13 | 12 | pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { |
@@ -83,75 +82,9 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte |
83 | 82 | add_keyword("struct", "struct $0"); |
84 | 83 | add_keyword("union", "union $1 {\n $0\n}"); |
85 | 84 | } |
86 | | - |
87 | | - if ctx.expects_type() { |
88 | | - return; |
89 | | - } |
90 | | - |
91 | | - if ctx.expects_expression() { |
92 | | - if !has_block_expr_parent { |
93 | | - add_keyword("unsafe", "unsafe {\n $0\n}"); |
94 | | - } |
95 | | - add_keyword("match", "match $1 {\n $0\n}"); |
96 | | - add_keyword("while", "while $1 {\n $0\n}"); |
97 | | - add_keyword("while let", "while let $1 = $2 {\n $0\n}"); |
98 | | - add_keyword("loop", "loop {\n $0\n}"); |
99 | | - add_keyword("if", "if $1 {\n $0\n}"); |
100 | | - add_keyword("if let", "if let $1 = $2 {\n $0\n}"); |
101 | | - add_keyword("for", "for $1 in $2 {\n $0\n}"); |
102 | | - add_keyword("true", "true"); |
103 | | - add_keyword("false", "false"); |
104 | | - } |
105 | | - |
106 | | - if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || has_block_expr_parent { |
107 | | - add_keyword("let", "let"); |
108 | | - } |
109 | | - |
110 | | - if ctx.after_if() { |
111 | | - add_keyword("else", "else {\n $0\n}"); |
112 | | - add_keyword("else if", "else if $1 {\n $0\n}"); |
113 | | - } |
114 | | - |
115 | | - if ctx.expects_ident_ref_expr() { |
116 | | - add_keyword("mut", "mut "); |
117 | | - } |
118 | | - |
119 | | - let (can_be_stmt, in_loop_body) = match ctx.path_context() { |
120 | | - Some(&PathCompletionCtx { |
121 | | - is_absolute_path: false, |
122 | | - kind: PathKind::Expr { in_block_expr, in_loop_body, .. }, |
123 | | - .. |
124 | | - }) => (in_block_expr, in_loop_body), |
125 | | - _ => return, |
126 | | - }; |
127 | | - |
128 | | - if in_loop_body { |
129 | | - if can_be_stmt { |
130 | | - add_keyword("continue", "continue;"); |
131 | | - add_keyword("break", "break;"); |
132 | | - } else { |
133 | | - add_keyword("continue", "continue"); |
134 | | - add_keyword("break", "break"); |
135 | | - } |
136 | | - } |
137 | | - |
138 | | - let fn_def = match &ctx.function_def { |
139 | | - Some(it) => it, |
140 | | - None => return, |
141 | | - }; |
142 | | - |
143 | | - add_keyword( |
144 | | - "return", |
145 | | - match (can_be_stmt, fn_def.ret_type().is_some()) { |
146 | | - (true, true) => "return $0;", |
147 | | - (true, false) => "return;", |
148 | | - (false, true) => "return $0", |
149 | | - (false, false) => "return", |
150 | | - }, |
151 | | - ) |
152 | 85 | } |
153 | 86 |
|
154 | | -fn add_keyword(acc: &mut Completions, ctx: &CompletionContext, kw: &str, snippet: &str) { |
| 87 | +pub(super) fn add_keyword(acc: &mut Completions, ctx: &CompletionContext, kw: &str, snippet: &str) { |
155 | 88 | let mut item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), kw); |
156 | 89 |
|
157 | 90 | match ctx.config.snippet_cap { |
|
0 commit comments