diff options
author | Lukas Wirth <[email protected]> | 2020-10-25 14:12:21 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-10-25 14:12:21 +0000 |
commit | 3182c067521ced88f546900cca3c6e9b82d18df6 (patch) | |
tree | 9ab2df6630c58d19ba64628bd6171f9ae17dd71b /crates | |
parent | 6675d4c57641135a73658d9ba66b78205bb45742 (diff) |
Don't keep parens around in remove-dbg
Diffstat (limited to 'crates')
-rw-r--r-- | crates/assists/src/handlers/remove_dbg.rs | 62 |
1 files changed, 61 insertions, 1 deletions
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<SyntaxElement>) - | |||
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 | 120 | if symbol_not_in_bracket |
121 | // paths | ||
121 | && symbol_kind != SyntaxKind::COLON | 122 | && symbol_kind != SyntaxKind::COLON |
123 | // field/method access | ||
122 | && symbol_kind != SyntaxKind::DOT | 124 | && 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) | ||
124 | { | 128 | { |
125 | return true; | 129 | return true; |
126 | } | 130 | } |
@@ -300,4 +304,60 @@ fn main() { | |||
300 | }"#, | 304 | }"#, |
301 | ); | 305 | ); |
302 | } | 306 | } |
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 | } | ||
303 | } | 363 | } |