mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Auto merge of #16016 - dfireBird:regression-fix-15879, r=lnicola
fix: Insert fn call parens only if the parens inserted around field name Fixes #16014. Sorry I missed it in previous PR. I've added a test as level to prevent regressions again. Give any suggestions to improve the test if anything.
This commit is contained in:
commit
afc1ae1aa3
2 changed files with 32 additions and 7 deletions
|
@ -427,6 +427,31 @@ fn foo() {
|
|||
..Default::default()
|
||||
};
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -169,15 +169,15 @@ 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 });
|
||||
|
||||
if is_parens_needed {
|
||||
builder.insert(ctx.source_range().end(), "()".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
item.text_edit(builder.finish());
|
||||
|
|
Loading…
Reference in a new issue