Skip to content

Commit 8296b16

Browse files
committed
fix the insertion of the surronding parens
Before it was inserting whenever function field is found but it should happend only in the case of function call.
1 parent aa1cf8d commit 8296b16

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

crates/ide-completion/src/render.rs

+16-27
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ pub(crate) fn render_field(
154154
// dot access, then comes the field name and optionally insert function
155155
// call parens.
156156

157-
if let Some(receiver) = &dot_access.receiver {
158-
if let Some(receiver) = ctx.completion.sema.original_ast_node(receiver.clone()) {
159-
let range = receiver.syntax().text_range();
160-
builder.insert(range.start(), "(".to_string());
161-
builder.insert(range.end(), ")".to_string());
162-
}
163-
}
164157
builder.replace(
165158
ctx.source_range(),
166159
field_with_receiver(db, receiver.as_ref(), &escaped_name).into(),
@@ -169,11 +162,21 @@ pub(crate) fn render_field(
169162
let expected_fn_type =
170163
ctx.completion.expected_type.as_ref().is_some_and(|ty| ty.is_fn() || ty.is_closure());
171164

172-
let is_parens_needed =
173-
!matches!(dot_access.kind, DotAccessKind::Method { has_parens: true });
165+
if !expected_fn_type {
166+
if let Some(receiver) = &dot_access.receiver {
167+
if let Some(receiver) = ctx.completion.sema.original_ast_node(receiver.clone()) {
168+
let range = receiver.syntax().text_range();
169+
builder.insert(range.start(), "(".to_string());
170+
builder.insert(range.end(), ")".to_string());
171+
}
172+
}
173+
174+
let is_parens_needed =
175+
!matches!(dot_access.kind, DotAccessKind::Method { has_parens: true });
174176

175-
if !expected_fn_type && is_parens_needed {
176-
builder.insert(ctx.source_range().end(), "()".to_string());
177+
if is_parens_needed {
178+
builder.insert(ctx.source_range().end(), "()".to_string());
179+
}
177180
}
178181

179182
item.text_edit(builder.finish());
@@ -1706,22 +1709,8 @@ fn foo() {
17061709
CompletionItem {
17071710
label: "field",
17081711
source_range: 76..78,
1709-
text_edit: TextEdit {
1710-
indels: [
1711-
Indel {
1712-
insert: "(",
1713-
delete: 57..57,
1714-
},
1715-
Indel {
1716-
insert: ")",
1717-
delete: 75..75,
1718-
},
1719-
Indel {
1720-
insert: "field",
1721-
delete: 76..78,
1722-
},
1723-
],
1724-
},
1712+
delete: 76..78,
1713+
insert: "field",
17251714
kind: SymbolKind(
17261715
Field,
17271716
),

0 commit comments

Comments
 (0)