diff options
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/assists/invert_if.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ra_assists/src/assists/invert_if.rs b/crates/ra_assists/src/assists/invert_if.rs index 9a53a3d18..c2c8529fe 100644 --- a/crates/ra_assists/src/assists/invert_if.rs +++ b/crates/ra_assists/src/assists/invert_if.rs | |||
@@ -2,8 +2,8 @@ use hir::db::HirDatabase; | |||
2 | use ra_syntax::ast::{self, AstNode}; | 2 | use ra_syntax::ast::{self, AstNode}; |
3 | use ra_syntax::{TextRange, TextUnit}; | 3 | use ra_syntax::{TextRange, TextUnit}; |
4 | 4 | ||
5 | use crate::{Assist, AssistCtx, AssistId}; | ||
6 | use super::apply_demorgan::undo_negation; | 5 | use super::apply_demorgan::undo_negation; |
6 | use crate::{Assist, AssistCtx, AssistId}; | ||
7 | 7 | ||
8 | // Assist: invert_if | 8 | // Assist: invert_if |
9 | // | 9 | // |
@@ -24,7 +24,6 @@ use super::apply_demorgan::undo_negation; | |||
24 | // } | 24 | // } |
25 | // ``` | 25 | // ``` |
26 | 26 | ||
27 | |||
28 | pub(crate) fn invert_if(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 27 | pub(crate) fn invert_if(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
29 | let expr = ctx.find_node_at_offset::<ast::IfExpr>()?; | 28 | let expr = ctx.find_node_at_offset::<ast::IfExpr>()?; |
30 | let expr_range = expr.syntax().text_range(); | 29 | let expr_range = expr.syntax().text_range(); |
@@ -49,12 +48,9 @@ pub(crate) fn invert_if(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
49 | edit.replace(else_range, then_node.text()); | 48 | edit.replace(else_range, then_node.text()); |
50 | edit.replace(then_range, else_node.text()); | 49 | edit.replace(then_range, else_node.text()); |
51 | }) | 50 | }) |
52 | |||
53 | } else { | 51 | } else { |
54 | None | 52 | None |
55 | } | 53 | } |
56 | |||
57 | |||
58 | } | 54 | } |
59 | 55 | ||
60 | #[cfg(test)] | 56 | #[cfg(test)] |
@@ -65,12 +61,20 @@ mod tests { | |||
65 | 61 | ||
66 | #[test] | 62 | #[test] |
67 | fn invert_if_remove_inequality() { | 63 | fn invert_if_remove_inequality() { |
68 | check_assist(invert_if, "fn f() { i<|>f x != 3 {1} else {3 + 2} }", "fn f() { i<|>f x == 3 {3 + 2} else {1} }") | 64 | check_assist( |
65 | invert_if, | ||
66 | "fn f() { i<|>f x != 3 {1} else {3 + 2} }", | ||
67 | "fn f() { i<|>f x == 3 {3 + 2} else {1} }", | ||
68 | ) | ||
69 | } | 69 | } |
70 | 70 | ||
71 | #[test] | 71 | #[test] |
72 | fn invert_if_remove_not() { | 72 | fn invert_if_remove_not() { |
73 | check_assist(invert_if, "fn f() { <|>if !cond {3 * 2} else {1} }", "fn f() { <|>if cond {1} else {3 * 2} }") | 73 | check_assist( |
74 | invert_if, | ||
75 | "fn f() { <|>if !cond {3 * 2} else {1} }", | ||
76 | "fn f() { <|>if cond {1} else {3 * 2} }", | ||
77 | ) | ||
74 | } | 78 | } |
75 | 79 | ||
76 | #[test] | 80 | #[test] |