From 40facb559a1f12ae608439041c9b3629ea633b77 Mon Sep 17 00:00:00 2001 From: Evgenii P Date: Sat, 3 Aug 2019 02:40:59 +0700 Subject: Change postfix completion to keyword completion --- crates/ra_ide_api/src/completion/complete_dot.rs | 30 +++++++----------------- 1 file 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; use ra_text_edit::TextEditBuilder; use rustc_hash::FxHashSet; -/// Applies postfix edition but with CompletionKind::Reference -fn postfix_reference(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { - let edit = { - let receiver_range = - ctx.dot_receiver.as_ref().expect("no receiver available").syntax().text_range(); - let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); - let mut builder = TextEditBuilder::default(); - builder.replace(delete_range, snippet.to_string()); - builder.finish() - }; - CompletionItem::new(CompletionKind::Reference, ctx.source_range(), label) - .detail(detail) - .snippet_edit(edit) -} - /// Complete dot accesses, i.e. fields or methods (and .await syntax). pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { if let Some(dot_receiver) = &ctx.dot_receiver { - let receiver_text = dot_receiver.syntax().text().to_string(); let receiver_ty = ctx.analyzer.type_of(ctx.db, &dot_receiver); if let Some(receiver_ty) = receiver_ty { @@ -39,7 +23,9 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { // Suggest .await syntax for types that implement Future trait if ctx.analyzer.impls_future(ctx.db, receiver_ty) { - postfix_reference(ctx, ".await", "expr.await", &format!("{}.await", receiver_text)) + CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") + .detail("expr.await") + .insert_text("await") .add_to(acc); } } @@ -440,7 +426,7 @@ mod tests { #[test] fn test_completion_await_impls_future() { assert_debug_snapshot_matches!( - do_ref_completion( + do_completion( r###" // Mock Future trait from stdlib pub mod std { @@ -457,14 +443,14 @@ mod tests { fn foo(a: A) { a.<|> } - "###), + "###, CompletionKind::Keyword), @r###" ⋮[ ⋮ CompletionItem { - ⋮ label: ".await", + ⋮ label: "await", ⋮ source_range: [358; 358), - ⋮ delete: [356; 358), - ⋮ insert: "a.await", + ⋮ delete: [358; 358), + ⋮ insert: "await", ⋮ detail: "expr.await", ⋮ }, ⋮] -- cgit v1.2.3