aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/source_binder.rs18
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs34
2 files changed, 27 insertions, 25 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index cf9a9e108..2c4cedd8b 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -428,20 +428,18 @@ impl SourceAnalyzer {
428 let std_future_trait = 428 let std_future_trait =
429 match self.resolver.resolve_path_segments(db, &std_future_path).into_fully_resolved() { 429 match self.resolver.resolve_path_segments(db, &std_future_path).into_fully_resolved() {
430 PerNs { types: Some(Resolution::Def(ModuleDef::Trait(trait_))), .. } => { 430 PerNs { types: Some(Resolution::Def(ModuleDef::Trait(trait_))), .. } => {
431 Some(trait_) 431 trait_
432 } 432 }
433 _ => None, 433 _ => return false,
434 }; 434 };
435 435
436 let krate = self.resolver.krate(); 436 let krate = match self.resolver.krate() {
437 if let Some(krate) = krate { 437 Some(krate) => krate,
438 if let Some(trait_) = std_future_trait { 438 _ => return false,
439 let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 }; 439 };
440 return implements_trait(&canonical_ty, db, &self.resolver, krate, trait_);
441 }
442 }
443 440
444 false 441 let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 };
442 return implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait);
445 } 443 }
446 444
447 #[cfg(test)] 445 #[cfg(test)]
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 9a3b353a9..d43ff2eec 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -9,23 +9,27 @@ use rustc_hash::FxHashSet;
9 9
10/// Complete dot accesses, i.e. fields or methods (and .await syntax). 10/// Complete dot accesses, i.e. fields or methods (and .await syntax).
11pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { 11pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
12 if let Some(dot_receiver) = &ctx.dot_receiver { 12 let dot_receiver = match &ctx.dot_receiver {
13 let receiver_ty = ctx.analyzer.type_of(ctx.db, &dot_receiver); 13 Some(expr) => expr,
14 _ => return,
15 };
14 16
15 if let Some(receiver_ty) = receiver_ty { 17 let receiver_ty = match ctx.analyzer.type_of(ctx.db, &dot_receiver) {
16 if !ctx.is_call { 18 Some(ty) => ty,
17 complete_fields(acc, ctx, receiver_ty.clone()); 19 _ => return,
18 } 20 };
19 complete_methods(acc, ctx, receiver_ty.clone());
20 21
21 // Suggest .await syntax for types that implement Future trait 22 if !ctx.is_call {
22 if ctx.analyzer.impls_future(ctx.db, receiver_ty) { 23 complete_fields(acc, ctx, receiver_ty.clone());
23 CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") 24 }
24 .detail("expr.await") 25 complete_methods(acc, ctx, receiver_ty.clone());
25 .insert_text("await") 26
26 .add_to(acc); 27 // Suggest .await syntax for types that implement Future trait
27 } 28 if ctx.analyzer.impls_future(ctx.db, receiver_ty) {
28 } 29 CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await")
30 .detail("expr.await")
31 .insert_text("await")
32 .add_to(acc);
29 } 33 }
30} 34}
31 35