]> git.lizzy.rs Git - rust.git/commitdiff
Don't render `()` in calls to assoc functions
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 17 Feb 2019 18:30:46 +0000 (21:30 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 17 Feb 2019 18:30:46 +0000 (21:30 +0300)
crates/ra_ide_api/src/completion/completion_context.rs
crates/ra_ide_api/src/completion/completion_item.rs
crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap [new file with mode: 0644]

index 82bd4d6061d0f4e6c75389f4869a7f3a1bbae9c0..b9f0abe194073f2c960b4789e17b6446234535ff 100644 (file)
@@ -137,6 +137,13 @@ fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::N
         };
         if let Some(segment) = ast::PathSegment::cast(parent) {
             let path = segment.parent_path();
+            self.is_call = path
+                .syntax()
+                .parent()
+                .and_then(ast::PathExpr::cast)
+                .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
+                .is_some();
+
             if let Some(mut path) = hir::Path::from_ast(path) {
                 if !path.is_ident() {
                     path.segments.pop().unwrap();
@@ -176,12 +183,6 @@ fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::N
                     }
                 }
             }
-            self.is_call = path
-                .syntax()
-                .parent()
-                .and_then(ast::PathExpr::cast)
-                .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
-                .is_some()
         }
         if let Some(field_expr) = ast::FieldExpr::cast(parent) {
             // The receiver comes before the point of insertion of the fake
index 6003e1d8925a8866bf227eff9aedc69246bc1ee1..ed0b0b7e510c775b052663ecaf3106c82171ff0b 100644 (file)
@@ -427,6 +427,17 @@ fn main() {
                 frob<|>();
             }
             ",
+        );
+        check_reference_completion(
+            "dont_render_function_parens_if_already_call_assoc_fn",
+            "
+            //- /lib.rs
+            struct Foo {}
+            impl Foo { fn new() -> Foo {} }
+            fn main() {
+                Foo::ne<|>();
+            }
+            ",
         )
     }
 
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap
new file mode 100644 (file)
index 0000000..18a187c
--- /dev/null
@@ -0,0 +1,24 @@
+---
+created: "2019-02-17T18:29:14.513213526Z"
+creator: insta@0.6.2
+source: crates/ra_ide_api/src/completion/completion_item.rs
+expression: kind_completions
+---
+[
+    CompletionItem {
+        completion_kind: Reference,
+        label: "new",
+        kind: Some(
+            Method
+        ),
+        detail: Some(
+            "fn new() -> Foo"
+        ),
+        documentation: None,
+        lookup: None,
+        insert_text: None,
+        insert_text_format: PlainText,
+        source_range: [67; 69),
+        text_edit: None
+    }
+]