Fix not applicable on trailing comma for remove_dbg

`remove_dbg` not applicable for whitespaces after trailing comma

Example
---
```rust
fn foo() {
    dbg!(
        bar(),
    );
}
```

**Before this PR**:

Assist not applicable

**After this PR**:

```rust
fn foo() {
    bar();
}
```
This commit is contained in:
A4-Tacks 2025-09-21 11:00:00 +08:00
parent c8182c4ae3
commit 1525bf3e8d
No known key found for this signature in database
GPG key ID: DBD861323040663B

View file

@ -83,7 +83,9 @@ fn compute_dbg_replacement(
let input_expressions = input_expressions
.into_iter()
.filter_map(|(is_sep, group)| (!is_sep).then_some(group))
.map(|mut tokens| syntax::hacks::parse_expr_from_str(&tokens.join(""), Edition::CURRENT))
.map(|tokens| tokens.collect::<Vec<_>>())
.filter(|tokens| !tokens.iter().all(|it| it.kind().is_trivia()))
.map(|tokens| syntax::hacks::parse_expr_from_str(&tokens.iter().join(""), Edition::CURRENT))
.collect::<Option<Vec<ast::Expr>>>()?;
let parent = macro_expr.syntax().parent()?;
@ -268,6 +270,8 @@ fn foo() {
dbg!('x');
dbg!(&n);
dbg!(n);
dbg!(n,);
dbg!(n, );
// needless comment
dbg!("foo");$0
}
@ -281,6 +285,17 @@ fn foo() {
);
}
#[test]
fn test_remove_trailing_comma_dbg() {
check("$0dbg!(1 + 1,)", "1 + 1");
check("$0dbg!(1 + 1, )", "1 + 1");
check("$0dbg!(1 + 1,\n)", "1 + 1");
check("$0dbg!(1 + 1, 2 + 3)", "(1 + 1, 2 + 3)");
check("$0dbg!(1 + 1, 2 + 3 )", "(1 + 1, 2 + 3)");
check("$0dbg!(1 + 1, 2 + 3, )", "(1 + 1, 2 + 3)");
check("$0dbg!(1 + 1, 2 + 3 ,)", "(1 + 1, 2 + 3)");
}
#[test]
fn test_remove_dbg_not_applicable() {
check_assist_not_applicable(remove_dbg, "fn main() {$0vec![1, 2, 3]}");