Skip to content

Commit 838944b

Browse files
committed
improve logic for trailing comma addition
1 parent a961266 commit 838944b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/ide_completion/src/completions/fn_param.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,18 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: ast::ParamLi
9898
}
9999

100100
fn surround_with_commas(ctx: &CompletionContext, param: String) -> Option<String> {
101-
let end_of_param_list = matches!(ctx.token.next_token()?.kind(), SyntaxKind::R_PAREN);
102-
let trailing = if end_of_param_list { "" } else { "," };
101+
let next_token = {
102+
let t = ctx.token.next_token()?;
103+
if !matches!(t.kind(), SyntaxKind::WHITESPACE) {
104+
t
105+
} else {
106+
t.next_token()?
107+
}
108+
};
109+
110+
let trailing_comma_missing = matches!(next_token.kind(), SyntaxKind::IDENT);
111+
let trailing = if trailing_comma_missing { "," } else { "" };
112+
dbg!(&ctx.token.next_token()?);
103113

104114
let previous_token = if matches!(ctx.token.kind(), SyntaxKind::IDENT | SyntaxKind::WHITESPACE) {
105115
ctx.previous_token.as_ref()?

0 commit comments

Comments
 (0)