diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 93e5d816d..272a38f11 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -10,25 +10,9 @@ use ra_syntax::TextRange; | |||
10 | use ra_text_edit::TextEditBuilder; | 10 | use ra_text_edit::TextEditBuilder; |
11 | use rustc_hash::FxHashSet; | 11 | use rustc_hash::FxHashSet; |
12 | 12 | ||
13 | /// Applies postfix edition but with CompletionKind::Reference | ||
14 | fn postfix_reference(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { | ||
15 | let edit = { | ||
16 | let receiver_range = | ||
17 | ctx.dot_receiver.as_ref().expect("no receiver available").syntax().text_range(); | ||
18 | let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); | ||
19 | let mut builder = TextEditBuilder::default(); | ||
20 | builder.replace(delete_range, snippet.to_string()); | ||
21 | builder.finish() | ||
22 | }; | ||
23 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), label) | ||
24 | .detail(detail) | ||
25 | .snippet_edit(edit) | ||
26 | } | ||
27 | |||
28 | /// Complete dot accesses, i.e. fields or methods (and .await syntax). | 13 | /// Complete dot accesses, i.e. fields or methods (and .await syntax). |
29 | pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | 14 | pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { |
30 | if let Some(dot_receiver) = &ctx.dot_receiver { | 15 | if let Some(dot_receiver) = &ctx.dot_receiver { |
31 | let receiver_text = dot_receiver.syntax().text().to_string(); | ||
32 | let receiver_ty = ctx.analyzer.type_of(ctx.db, &dot_receiver); | 16 | let receiver_ty = ctx.analyzer.type_of(ctx.db, &dot_receiver); |
33 | 17 | ||
34 | if let Some(receiver_ty) = receiver_ty { | 18 | if let Some(receiver_ty) = receiver_ty { |
@@ -39,7 +23,9 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | |||
39 | 23 | ||
40 | // Suggest .await syntax for types that implement Future trait | 24 | // Suggest .await syntax for types that implement Future trait |
41 | if ctx.analyzer.impls_future(ctx.db, receiver_ty) { | 25 | if ctx.analyzer.impls_future(ctx.db, receiver_ty) { |
42 | postfix_reference(ctx, ".await", "expr.await", &format!("{}.await", receiver_text)) | 26 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") |
27 | .detail("expr.await") | ||
28 | .insert_text("await") | ||
43 | .add_to(acc); | 29 | .add_to(acc); |
44 | } | 30 | } |
45 | } | 31 | } |
@@ -440,7 +426,7 @@ mod tests { | |||
440 | #[test] | 426 | #[test] |
441 | fn test_completion_await_impls_future() { | 427 | fn test_completion_await_impls_future() { |
442 | assert_debug_snapshot_matches!( | 428 | assert_debug_snapshot_matches!( |
443 | do_ref_completion( | 429 | do_completion( |
444 | r###" | 430 | r###" |
445 | // Mock Future trait from stdlib | 431 | // Mock Future trait from stdlib |
446 | pub mod std { | 432 | pub mod std { |
@@ -457,14 +443,14 @@ mod tests { | |||
457 | fn foo(a: A) { | 443 | fn foo(a: A) { |
458 | a.<|> | 444 | a.<|> |
459 | } | 445 | } |
460 | "###), | 446 | "###, CompletionKind::Keyword), |
461 | @r###" | 447 | @r###" |
462 | ⋮[ | 448 | ⋮[ |
463 | ⋮ CompletionItem { | 449 | ⋮ CompletionItem { |
464 | ⋮ label: ".await", | 450 | ⋮ label: "await", |
465 | ⋮ source_range: [358; 358), | 451 | ⋮ source_range: [358; 358), |
466 | ⋮ delete: [356; 358), | 452 | ⋮ delete: [358; 358), |
467 | ⋮ insert: "a.await", | 453 | ⋮ insert: "await", |
468 | ⋮ detail: "expr.await", | 454 | ⋮ detail: "expr.await", |
469 | ⋮ }, | 455 | ⋮ }, |
470 | ⋮] | 456 | ⋮] |