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.rs59
1 files changed, 16 insertions, 43 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index 9754122a0..c99fdef05 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -37,17 +37,6 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
37 } 37 }
38 }; 38 };
39 } 39 }
40
41 // Suggest .await syntax for types that implement Future trait
42 if let Some(receiver) = ctx.dot_receiver() {
43 if let Some(ty) = ctx.sema.type_of_expr(receiver) {
44 if ty.impls_future(ctx.db) {
45 let mut item = kw_completion("await");
46 item.detail("expr.await");
47 item.add_to(acc);
48 }
49 };
50 }
51} 40}
52 41
53pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { 42pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
@@ -59,6 +48,19 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
59 cov_mark::hit!(no_keyword_completion_in_record_lit); 48 cov_mark::hit!(no_keyword_completion_in_record_lit);
60 return; 49 return;
61 } 50 }
51
52 // Suggest .await syntax for types that implement Future trait
53 if let Some(receiver) = ctx.dot_receiver() {
54 if let Some(ty) = ctx.sema.type_of_expr(receiver) {
55 if ty.impls_future(ctx.db) {
56 let mut item =
57 CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await");
58 item.kind(CompletionItemKind::Keyword).detail("expr.await");
59 item.add_to(acc);
60 }
61 };
62 }
63
62 let mut add_keyword = |kw, snippet| add_keyword(ctx, acc, kw, snippet); 64 let mut add_keyword = |kw, snippet| add_keyword(ctx, acc, kw, snippet);
63 65
64 let expects_assoc_item = ctx.expects_assoc_item(); 66 let expects_assoc_item = ctx.expects_assoc_item();
@@ -67,6 +69,9 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
67 69
68 if ctx.has_impl_or_trait_prev_sibling() { 70 if ctx.has_impl_or_trait_prev_sibling() {
69 add_keyword("where", "where "); 71 add_keyword("where", "where ");
72 if ctx.has_impl_prev_sibling() {
73 add_keyword("for", "for ");
74 }
70 return; 75 return;
71 } 76 }
72 if ctx.previous_token_is(T![unsafe]) { 77 if ctx.previous_token_is(T![unsafe]) {
@@ -386,22 +391,6 @@ fn quux() -> i32 {
386 } 391 }
387 392
388 #[test] 393 #[test]
389 fn test_where_keyword() {
390 check(
391 r"trait A $0",
392 expect![[r#"
393 kw where
394 "#]],
395 );
396 check(
397 r"impl A $0",
398 expect![[r#"
399 kw where
400 "#]],
401 );
402 }
403
404 #[test]
405 fn no_keyword_completion_in_comments() { 394 fn no_keyword_completion_in_comments() {
406 cov_mark::check!(no_keyword_completion_in_comments); 395 cov_mark::check!(no_keyword_completion_in_comments);
407 check( 396 check(
@@ -478,22 +467,6 @@ fn foo() {
478 } 467 }
479 468
480 #[test] 469 #[test]
481 fn before_field() {
482 check(
483 r#"
484struct Foo {
485 $0
486 pub f: i32,
487}
488"#,
489 expect![[r#"
490 kw pub(crate)
491 kw pub
492 "#]],
493 )
494 }
495
496 #[test]
497 fn skip_struct_initializer() { 470 fn skip_struct_initializer() {
498 cov_mark::check!(no_keyword_completion_in_record_lit); 471 cov_mark::check!(no_keyword_completion_in_record_lit);
499 check( 472 check(