diff options
Diffstat (limited to 'crates/assists/src/handlers')
-rw-r--r-- | crates/assists/src/handlers/invert_if.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/assists/src/handlers/invert_if.rs b/crates/assists/src/handlers/invert_if.rs index 294256297..461fcf862 100644 --- a/crates/assists/src/handlers/invert_if.rs +++ b/crates/assists/src/handlers/invert_if.rs | |||
@@ -49,13 +49,14 @@ pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | |||
49 | ast::ElseBranch::IfExpr(_) => return None, | 49 | ast::ElseBranch::IfExpr(_) => return None, |
50 | }; | 50 | }; |
51 | 51 | ||
52 | let cond_range = cond.syntax().text_range(); | ||
53 | let flip_cond = invert_boolean_expression(cond); | ||
54 | let else_node = else_block.syntax(); | ||
55 | let else_range = else_node.text_range(); | ||
56 | let then_range = then_node.text_range(); | ||
57 | acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| { | 52 | acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| { |
58 | edit.replace(cond_range, flip_cond.syntax().text()); | 53 | let flip_cond = invert_boolean_expression(cond.clone()); |
54 | edit.replace_ast(cond, flip_cond); | ||
55 | |||
56 | let else_node = else_block.syntax(); | ||
57 | let else_range = else_node.text_range(); | ||
58 | let then_range = then_node.text_range(); | ||
59 | |||
59 | edit.replace(else_range, then_node.text()); | 60 | edit.replace(else_range, then_node.text()); |
60 | edit.replace(then_range, else_node.text()); | 61 | edit.replace(then_range, else_node.text()); |
61 | }) | 62 | }) |