aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/complete_keyword.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-04 09:36:12 +0100
committerAleksey Kladov <[email protected]>2020-07-04 09:41:50 +0100
commitf2f6a46aa4751393ae18e8b21aa631c9919c5f43 (patch)
tree6c0d0cbde03a3f593256d76e7ab3784349868a3b /crates/ra_ide/src/completion/complete_keyword.rs
parentcaeddff5435d9cf604aac7af7b53cc4ac8bb4a13 (diff)
Cleanup dot completiont tests
Diffstat (limited to 'crates/ra_ide/src/completion/complete_keyword.rs')
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs
index 086b917ce..340d57a49 100644
--- a/crates/ra_ide/src/completion/complete_keyword.rs
+++ b/crates/ra_ide/src/completion/complete_keyword.rs
@@ -35,6 +35,19 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
35 } 35 }
36 _ => {} 36 _ => {}
37 } 37 }
38
39 // Suggest .await syntax for types that implement Future trait
40 if let Some(receiver) = &ctx.dot_receiver {
41 if let Some(ty) = ctx.sema.type_of_expr(receiver) {
42 if ty.impls_future(ctx.db) {
43 CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await")
44 .kind(CompletionItemKind::Keyword)
45 .detail("expr.await")
46 .insert_text("await")
47 .add_to(acc);
48 }
49 };
50 }
38} 51}
39 52
40pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { 53pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
@@ -490,4 +503,26 @@ Some multi-line comment<|>
490 expect![[""]], 503 expect![[""]],
491 ); 504 );
492 } 505 }
506
507 #[test]
508 fn test_completion_await_impls_future() {
509 check(
510 r#"
511//- /main.rs
512use std::future::*;
513struct A {}
514impl Future for A {}
515fn foo(a: A) { a.<|> }
516
517//- /std/lib.rs
518pub mod future {
519 #[lang = "future_trait"]
520 pub trait Future {}
521}
522"#,
523 expect![[r#"
524 kw await expr.await
525 "#]],
526 )
527 }
493} 528}