mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-25 11:17:13 +00:00
Merge pull request #20714 from A4-Tacks/rm-dbg-trailing-comma
Fix not applicable on trailing comma for remove_dbg
This commit is contained in:
commit
e7d7cb415a
@ -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]}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user