Skip to content

Commit 3182c06

Browse files
committed
Don't keep parens around in remove-dbg
1 parent 6675d4c commit 3182c06

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

crates/assists/src/handlers/remove_dbg.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) -
118118
symbol_kind => {
119119
let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty();
120120
if symbol_not_in_bracket
121+
// paths
121122
&& symbol_kind != SyntaxKind::COLON
123+
// field/method access
122124
&& symbol_kind != SyntaxKind::DOT
123-
&& symbol_kind.is_punct()
125+
// try operator
126+
&& symbol_kind != SyntaxKind::QUESTION
127+
&& (symbol_kind.is_punct() || symbol_kind == SyntaxKind::AS_KW)
124128
{
125129
return true;
126130
}
@@ -300,4 +304,60 @@ fn main() {
300304
}"#,
301305
);
302306
}
307+
308+
#[test]
309+
fn test_remove_dbg_try_expr() {
310+
check_assist(
311+
remove_dbg,
312+
r#"let res = <|>dbg!(result?).foo();"#,
313+
r#"let res = result?.foo();"#,
314+
);
315+
}
316+
317+
#[test]
318+
fn test_remove_dbg_await_expr() {
319+
check_assist(
320+
remove_dbg,
321+
r#"let res = <|>dbg!(fut.await).foo();"#,
322+
r#"let res = fut.await.foo();"#,
323+
);
324+
}
325+
326+
#[test]
327+
fn test_remove_dbg_as_cast() {
328+
check_assist(
329+
remove_dbg,
330+
r#"let res = <|>dbg!(3 as usize).foo();"#,
331+
r#"let res = (3 as usize).foo();"#,
332+
);
333+
}
334+
335+
#[test]
336+
fn test_remove_dbg_index_expr() {
337+
check_assist(
338+
remove_dbg,
339+
r#"let res = <|>dbg!(array[3]).foo();"#,
340+
r#"let res = array[3].foo();"#,
341+
);
342+
check_assist(
343+
remove_dbg,
344+
r#"let res = <|>dbg!(tuple.3).foo();"#,
345+
r#"let res = tuple.3.foo();"#,
346+
);
347+
}
348+
349+
#[test]
350+
#[ignore] // FIXME: we encounter SyntaxKind::DOT instead of SyntaxKind::DOT2 causing this to fail
351+
fn test_remove_dbg_range_expr() {
352+
check_assist(
353+
remove_dbg,
354+
r#"let res = <|>dbg!(foo..bar).foo();"#,
355+
r#"let res = (foo..bar).foo();"#,
356+
);
357+
check_assist(
358+
remove_dbg,
359+
r#"let res = <|>dbg!(foo..=bar).foo();"#,
360+
r#"let res = (foo..=bar).foo();"#,
361+
);
362+
}
303363
}

0 commit comments

Comments
 (0)