diff options
Diffstat (limited to 'crates/ra_assists/src/handlers/invert_if.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/invert_if.rs | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/crates/ra_assists/src/handlers/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs index 983392f21..a594e7e0c 100644 --- a/crates/ra_assists/src/handlers/invert_if.rs +++ b/crates/ra_assists/src/handlers/invert_if.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ra_syntax::ast::{self, make, AstNode}; | 1 | use ra_syntax::ast::{self, AstNode}; |
2 | use ra_syntax::T; | 2 | use ra_syntax::T; |
3 | 3 | ||
4 | use crate::{Assist, AssistCtx, AssistId}; | 4 | use crate::{utils::invert_boolean_expression, Assist, AssistCtx, AssistId}; |
5 | 5 | ||
6 | // Assist: invert_if | 6 | // Assist: invert_if |
7 | // | 7 | // |
@@ -51,27 +51,6 @@ pub(crate) fn invert_if(ctx: AssistCtx) -> Option<Assist> { | |||
51 | None | 51 | None |
52 | } | 52 | } |
53 | 53 | ||
54 | pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr { | ||
55 | if let Some(expr) = invert_special_case(&expr) { | ||
56 | return expr; | ||
57 | } | ||
58 | make::expr_prefix(T![!], expr) | ||
59 | } | ||
60 | |||
61 | pub(crate) fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> { | ||
62 | match expr { | ||
63 | ast::Expr::BinExpr(bin) => match bin.op_kind()? { | ||
64 | ast::BinOp::NegatedEqualityTest => bin.replace_op(T![==]).map(|it| it.into()), | ||
65 | ast::BinOp::EqualityTest => bin.replace_op(T![!=]).map(|it| it.into()), | ||
66 | _ => None, | ||
67 | }, | ||
68 | ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(), | ||
69 | // FIXME: | ||
70 | // ast::Expr::Literal(true | false ) | ||
71 | _ => None, | ||
72 | } | ||
73 | } | ||
74 | |||
75 | #[cfg(test)] | 54 | #[cfg(test)] |
76 | mod tests { | 55 | mod tests { |
77 | use super::*; | 56 | use super::*; |