]> git.lizzy.rs Git - rust.git/commitdiff
Change postfix completion to keyword completion
authorEvgenii P <eupn@protonmail.com>
Fri, 2 Aug 2019 19:40:59 +0000 (02:40 +0700)
committerEvgenii P <eupn@protonmail.com>
Fri, 2 Aug 2019 19:40:59 +0000 (02:40 +0700)
crates/ra_ide_api/src/completion/complete_dot.rs

index 93e5d816d5c2e61b38c0889a489786b85d051a81..272a38f1199650151f48f4599c453bbef1d8099a 100644 (file)
 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 @@ struct A { the_field: u32 }
     #[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 @@ impl Future for A {}
             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",
        ⋮    },
        ⋮]