diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-06 12:36:25 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-06 12:36:25 +0100 |
commit | 69512dae26278f06b5ac96a7b6093abb69cdd040 (patch) | |
tree | f390143fdb1feea0b6a32cef9fad7907538fb8ef /crates/assists/src/handlers/remove_dbg.rs | |
parent | cb78c40b0ed1e8cf609457d63c5137022d2e1907 (diff) | |
parent | af4ae86e2700209283333490da377767e00f5ed2 (diff) |
Merge #6147
6147: Do not leave braces for colons in dbg! r=matklad a=SomeoneToIgnore
Tweak remove dbg heuristics a bit to remove braces when colons (`:`) are used in the non-leaf dbg expressions.
Before:
`dbg!(Foo::foo_test()).bar()` -> `(Foo::foo_test()).bar()`
After:
`dbg!(Foo::foo_test()).bar()` -> `Foo::foo_test().bar()`
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/assists/src/handlers/remove_dbg.rs')
-rw-r--r-- | crates/assists/src/handlers/remove_dbg.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/crates/assists/src/handlers/remove_dbg.rs b/crates/assists/src/handlers/remove_dbg.rs index a8ab2aecc..e10616779 100644 --- a/crates/assists/src/handlers/remove_dbg.rs +++ b/crates/assists/src/handlers/remove_dbg.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use syntax::{ | 1 | use syntax::{ |
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode}, |
3 | SyntaxElement, TextRange, TextSize, T, | 3 | SyntaxElement, SyntaxKind, TextRange, TextSize, T, |
4 | }; | 4 | }; |
5 | 5 | ||
6 | use crate::{AssistContext, AssistId, AssistKind, Assists}; | 6 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
@@ -117,7 +117,10 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) - | |||
117 | } | 117 | } |
118 | symbol_kind => { | 118 | symbol_kind => { |
119 | let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); | 119 | let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); |
120 | if symbol_not_in_bracket && symbol_kind.is_punct() { | 120 | if symbol_not_in_bracket |
121 | && symbol_kind != SyntaxKind::COLON | ||
122 | && symbol_kind.is_punct() | ||
123 | { | ||
121 | return true; | 124 | return true; |
122 | } | 125 | } |
123 | } | 126 | } |
@@ -159,6 +162,8 @@ fn foo(n: usize) { | |||
159 | } | 162 | } |
160 | ", | 163 | ", |
161 | ); | 164 | ); |
165 | |||
166 | check_assist(remove_dbg, "<|>dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()"); | ||
162 | } | 167 | } |
163 | 168 | ||
164 | #[test] | 169 | #[test] |