mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
improve logic for trailing comma addition
This commit is contained in:
parent
a9612666f8
commit
838944b387
@ -98,8 +98,18 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: ast::ParamLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn surround_with_commas(ctx: &CompletionContext, param: String) -> Option<String> {
|
fn surround_with_commas(ctx: &CompletionContext, param: String) -> Option<String> {
|
||||||
let end_of_param_list = matches!(ctx.token.next_token()?.kind(), SyntaxKind::R_PAREN);
|
let next_token = {
|
||||||
let trailing = if end_of_param_list { "" } else { "," };
|
let t = ctx.token.next_token()?;
|
||||||
|
if !matches!(t.kind(), SyntaxKind::WHITESPACE) {
|
||||||
|
t
|
||||||
|
} else {
|
||||||
|
t.next_token()?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let trailing_comma_missing = matches!(next_token.kind(), SyntaxKind::IDENT);
|
||||||
|
let trailing = if trailing_comma_missing { "," } else { "" };
|
||||||
|
dbg!(&ctx.token.next_token()?);
|
||||||
|
|
||||||
let previous_token = if matches!(ctx.token.kind(), SyntaxKind::IDENT | SyntaxKind::WHITESPACE) {
|
let previous_token = if matches!(ctx.token.kind(), SyntaxKind::IDENT | SyntaxKind::WHITESPACE) {
|
||||||
ctx.previous_token.as_ref()?
|
ctx.previous_token.as_ref()?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user