Skip to content

Commit

Permalink
Auto merge of #16016 - dfireBird:regression-fix-15879, r=lnicola
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Dec 5, 2023
2 parents 986577f + 20c6f27 commit afc1ae1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
25 changes: 25 additions & 0 deletions crates/ide-completion/src/completions/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
"#,
);
}
Expand Down
12 changes: 6 additions & 6 deletions crates/ide-completion/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}

Expand Down

0 comments on commit afc1ae1

Please sign in to comment.