about summary refs log tree commit diff
diff options
context:
space:
mode:
authordfireBird <me@dfirebird.dev>2023-12-04 22:06:19 +0530
committerdfireBird <me@dfirebird.dev>2023-12-04 22:37:34 +0530
commit20c6f270240bdb3b34d4f1399ccc29823343deed (patch)
tree98e662d06a0208fbe6fb7f7d9148a0b50e2165e4
parente402c494b7c7d94a37c6d789a216187aaf9ccd3e (diff)
downloadrust-20c6f270240bdb3b34d4f1399ccc29823343deed.tar.gz
rust-20c6f270240bdb3b34d4f1399ccc29823343deed.zip
Insert fn call parens only if the parens inserted around field name
-rw-r--r--crates/ide-completion/src/completions/record.rs25
-rw-r--r--crates/ide-completion/src/render.rs12
2 files changed, 31 insertions, 6 deletions
diff --git a/crates/ide-completion/src/completions/record.rs b/crates/ide-completion/src/completions/record.rs
index 945c3945bfa..46213deb0af 100644
--- a/crates/ide-completion/src/completions/record.rs
+++ b/crates/ide-completion/src/completions/record.rs
@@ -430,4 +430,29 @@ fn foo() {
 "#,
         );
     }
+
+    #[test]
+    fn callable_field_struct_init() {
+        check_edit(
+            "field",
+            r#"
+struct S {
+    field: fn(),
+}
+
+fn main() {
+    S {fi$0
+}
+"#,
+            r#"
+struct S {
+    field: fn(),
+}
+
+fn main() {
+    S {field
+}
+"#,
+        );
+    }
 }
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 048730c078d..830d7cabab5 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -169,14 +169,14 @@ pub(crate) fn render_field(
                 if let Some(receiver) = ctx.completion.sema.original_ast_node(receiver.clone()) {
                     builder.insert(receiver.syntax().text_range().start(), "(".to_string());
                     builder.insert(ctx.source_range().end(), ")".to_string());
-                }
-            }
 
-            let is_parens_needed =
-                !matches!(dot_access.kind, DotAccessKind::Method { has_parens: true });
+                    let is_parens_needed =
+                        !matches!(dot_access.kind, DotAccessKind::Method { has_parens: true });
 
-            if is_parens_needed {
-                builder.insert(ctx.source_range().end(), "()".to_string());
+                    if is_parens_needed {
+                        builder.insert(ctx.source_range().end(), "()".to_string());
+                    }
+                }
             }
         }