diff options
author | Lukas Wirth <[email protected]> | 2020-10-25 14:36:02 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-10-25 14:36:02 +0000 |
commit | 551bf65e6d035f95e77b116679a4622d6cb590db (patch) | |
tree | 3bb749cdf23e7d77fc5b43bcdec7fecff35de08d /crates/assists | |
parent | 3182c067521ced88f546900cca3c6e9b82d18df6 (diff) |
Keep parens around in remove-dbg for range expressions
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/handlers/remove_dbg.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/assists/src/handlers/remove_dbg.rs b/crates/assists/src/handlers/remove_dbg.rs index be3afa250..9731344b8 100644 --- a/crates/assists/src/handlers/remove_dbg.rs +++ b/crates/assists/src/handlers/remove_dbg.rs | |||
@@ -93,8 +93,9 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) - | |||
93 | if macro_contents.len() < 2 { | 93 | if macro_contents.len() < 2 { |
94 | return false; | 94 | return false; |
95 | } | 95 | } |
96 | let mut macro_contents = macro_contents.into_iter().peekable(); | ||
96 | let mut unpaired_brackets_in_contents = Vec::new(); | 97 | let mut unpaired_brackets_in_contents = Vec::new(); |
97 | for element in macro_contents { | 98 | while let Some(element) = macro_contents.next() { |
98 | match element.kind() { | 99 | match element.kind() { |
99 | T!['('] | T!['['] | T!['{'] => unpaired_brackets_in_contents.push(element), | 100 | T!['('] | T!['['] | T!['{'] => unpaired_brackets_in_contents.push(element), |
100 | T![')'] => { | 101 | T![')'] => { |
@@ -118,12 +119,13 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) - | |||
118 | symbol_kind => { | 119 | symbol_kind => { |
119 | let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); | 120 | let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); |
120 | if symbol_not_in_bracket | 121 | if symbol_not_in_bracket |
121 | // paths | 122 | && symbol_kind != SyntaxKind::COLON // paths |
122 | && symbol_kind != SyntaxKind::COLON | 123 | && (symbol_kind != SyntaxKind::DOT // field/method access |
123 | // field/method access | 124 | || macro_contents // range expressions consist of two SyntaxKind::Dot in macro invocations |
124 | && symbol_kind != SyntaxKind::DOT | 125 | .peek() |
125 | // try operator | 126 | .map(|element| element.kind() == SyntaxKind::DOT) |
126 | && symbol_kind != SyntaxKind::QUESTION | 127 | .unwrap_or(false)) |
128 | && symbol_kind != SyntaxKind::QUESTION // try operator | ||
127 | && (symbol_kind.is_punct() || symbol_kind == SyntaxKind::AS_KW) | 129 | && (symbol_kind.is_punct() || symbol_kind == SyntaxKind::AS_KW) |
128 | { | 130 | { |
129 | return true; | 131 | return true; |
@@ -347,7 +349,6 @@ fn main() { | |||
347 | } | 349 | } |
348 | 350 | ||
349 | #[test] | 351 | #[test] |
350 | #[ignore] // FIXME: we encounter SyntaxKind::DOT instead of SyntaxKind::DOT2 causing this to fail | ||
351 | fn test_remove_dbg_range_expr() { | 352 | fn test_remove_dbg_range_expr() { |
352 | check_assist( | 353 | check_assist( |
353 | remove_dbg, | 354 | remove_dbg, |