diff options
Diffstat (limited to 'crates/ide_completion/src/completions/keyword.rs')
-rw-r--r-- | crates/ide_completion/src/completions/keyword.rs | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index eb81f9765..03c6dd454 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | //! Completes keywords. | 1 | //! Completes keywords. |
2 | 2 | ||
3 | use std::iter; | ||
4 | |||
3 | use syntax::SyntaxKind; | 5 | use syntax::SyntaxKind; |
4 | use test_utils::mark; | 6 | use test_utils::mark; |
5 | 7 | ||
@@ -19,10 +21,14 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC | |||
19 | CompletionItem::new(CompletionKind::Keyword, source_range, "self") | 21 | CompletionItem::new(CompletionKind::Keyword, source_range, "self") |
20 | .kind(CompletionItemKind::Keyword) | 22 | .kind(CompletionItemKind::Keyword) |
21 | .add_to(acc); | 23 | .add_to(acc); |
22 | CompletionItem::new(CompletionKind::Keyword, source_range, "super::") | 24 | if iter::successors(ctx.path_qual.clone(), |p| p.qualifier()) |
23 | .kind(CompletionItemKind::Keyword) | 25 | .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) |
24 | .insert_text("super::") | 26 | { |
25 | .add_to(acc); | 27 | CompletionItem::new(CompletionKind::Keyword, source_range, "super::") |
28 | .kind(CompletionItemKind::Keyword) | ||
29 | .insert_text("super::") | ||
30 | .add_to(acc); | ||
31 | } | ||
26 | } | 32 | } |
27 | 33 | ||
28 | // Suggest .await syntax for types that implement Future trait | 34 | // Suggest .await syntax for types that implement Future trait |
@@ -85,6 +91,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
85 | if ctx.is_expr { | 91 | if ctx.is_expr { |
86 | add_keyword(ctx, acc, "match", "match $0 {}"); | 92 | add_keyword(ctx, acc, "match", "match $0 {}"); |
87 | add_keyword(ctx, acc, "while", "while $0 {}"); | 93 | add_keyword(ctx, acc, "while", "while $0 {}"); |
94 | add_keyword(ctx, acc, "while let", "while let $1 = $0 {}"); | ||
88 | add_keyword(ctx, acc, "loop", "loop {$0}"); | 95 | add_keyword(ctx, acc, "loop", "loop {$0}"); |
89 | add_keyword(ctx, acc, "if", "if $0 {}"); | 96 | add_keyword(ctx, acc, "if", "if $0 {}"); |
90 | add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); | 97 | add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); |
@@ -204,9 +211,17 @@ mod tests { | |||
204 | "#]], | 211 | "#]], |
205 | ); | 212 | ); |
206 | 213 | ||
214 | // FIXME: `self` shouldn't be shown here and the check below | ||
207 | check( | 215 | check( |
208 | r"use a::$0", | 216 | r"use a::$0", |
209 | expect![[r#" | 217 | expect![[r#" |
218 | kw self | ||
219 | "#]], | ||
220 | ); | ||
221 | |||
222 | check( | ||
223 | r"use super::$0", | ||
224 | expect![[r#" | ||
210 | kw self | 225 | kw self |
211 | kw super:: | 226 | kw super:: |
212 | "#]], | 227 | "#]], |
@@ -215,9 +230,8 @@ mod tests { | |||
215 | check( | 230 | check( |
216 | r"use a::{b, $0}", | 231 | r"use a::{b, $0}", |
217 | expect![[r#" | 232 | expect![[r#" |
218 | kw self | 233 | kw self |
219 | kw super:: | 234 | "#]], |
220 | "#]], | ||
221 | ); | 235 | ); |
222 | } | 236 | } |
223 | 237 | ||
@@ -256,6 +270,7 @@ mod tests { | |||
256 | kw trait | 270 | kw trait |
257 | kw match | 271 | kw match |
258 | kw while | 272 | kw while |
273 | kw while let | ||
259 | kw loop | 274 | kw loop |
260 | kw if | 275 | kw if |
261 | kw if let | 276 | kw if let |
@@ -283,6 +298,7 @@ mod tests { | |||
283 | kw trait | 298 | kw trait |
284 | kw match | 299 | kw match |
285 | kw while | 300 | kw while |
301 | kw while let | ||
286 | kw loop | 302 | kw loop |
287 | kw if | 303 | kw if |
288 | kw if let | 304 | kw if let |
@@ -310,6 +326,7 @@ mod tests { | |||
310 | kw trait | 326 | kw trait |
311 | kw match | 327 | kw match |
312 | kw while | 328 | kw while |
329 | kw while let | ||
313 | kw loop | 330 | kw loop |
314 | kw if | 331 | kw if |
315 | kw if let | 332 | kw if let |
@@ -344,6 +361,7 @@ fn quux() -> i32 { | |||
344 | expect![[r#" | 361 | expect![[r#" |
345 | kw match | 362 | kw match |
346 | kw while | 363 | kw while |
364 | kw while let | ||
347 | kw loop | 365 | kw loop |
348 | kw if | 366 | kw if |
349 | kw if let | 367 | kw if let |
@@ -393,6 +411,7 @@ fn quux() -> i32 { | |||
393 | kw trait | 411 | kw trait |
394 | kw match | 412 | kw match |
395 | kw while | 413 | kw while |
414 | kw while let | ||
396 | kw loop | 415 | kw loop |
397 | kw if | 416 | kw if |
398 | kw if let | 417 | kw if let |
@@ -552,6 +571,7 @@ pub mod future { | |||
552 | expect![[r#" | 571 | expect![[r#" |
553 | kw match | 572 | kw match |
554 | kw while | 573 | kw while |
574 | kw while let | ||
555 | kw loop | 575 | kw loop |
556 | kw if | 576 | kw if |
557 | kw if let | 577 | kw if let |
@@ -611,6 +631,7 @@ fn foo() { | |||
611 | expect![[r#" | 631 | expect![[r#" |
612 | kw match | 632 | kw match |
613 | kw while | 633 | kw while |
634 | kw while let | ||
614 | kw loop | 635 | kw loop |
615 | kw if | 636 | kw if |
616 | kw if let | 637 | kw if let |