From 3182c067521ced88f546900cca3c6e9b82d18df6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 25 Oct 2020 15:12:21 +0100 Subject: Don't keep parens around in remove-dbg --- crates/assists/src/handlers/remove_dbg.rs | 62 ++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/crates/assists/src/handlers/remove_dbg.rs b/crates/assists/src/handlers/remove_dbg.rs index e7072d2b9..be3afa250 100644 --- a/crates/assists/src/handlers/remove_dbg.rs +++ b/crates/assists/src/handlers/remove_dbg.rs @@ -118,9 +118,13 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec) - symbol_kind => { let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); if symbol_not_in_bracket + // paths && symbol_kind != SyntaxKind::COLON + // field/method access && symbol_kind != SyntaxKind::DOT - && symbol_kind.is_punct() + // try operator + && symbol_kind != SyntaxKind::QUESTION + && (symbol_kind.is_punct() || symbol_kind == SyntaxKind::AS_KW) { return true; } @@ -300,4 +304,60 @@ fn main() { }"#, ); } + + #[test] + fn test_remove_dbg_try_expr() { + check_assist( + remove_dbg, + r#"let res = <|>dbg!(result?).foo();"#, + r#"let res = result?.foo();"#, + ); + } + + #[test] + fn test_remove_dbg_await_expr() { + check_assist( + remove_dbg, + r#"let res = <|>dbg!(fut.await).foo();"#, + r#"let res = fut.await.foo();"#, + ); + } + + #[test] + fn test_remove_dbg_as_cast() { + check_assist( + remove_dbg, + r#"let res = <|>dbg!(3 as usize).foo();"#, + r#"let res = (3 as usize).foo();"#, + ); + } + + #[test] + fn test_remove_dbg_index_expr() { + check_assist( + remove_dbg, + r#"let res = <|>dbg!(array[3]).foo();"#, + r#"let res = array[3].foo();"#, + ); + check_assist( + remove_dbg, + r#"let res = <|>dbg!(tuple.3).foo();"#, + r#"let res = tuple.3.foo();"#, + ); + } + + #[test] + #[ignore] // FIXME: we encounter SyntaxKind::DOT instead of SyntaxKind::DOT2 causing this to fail + fn test_remove_dbg_range_expr() { + check_assist( + remove_dbg, + r#"let res = <|>dbg!(foo..bar).foo();"#, + r#"let res = (foo..bar).foo();"#, + ); + check_assist( + remove_dbg, + r#"let res = <|>dbg!(foo..=bar).foo();"#, + r#"let res = (foo..=bar).foo();"#, + ); + } } -- cgit v1.2.3