diff options
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r-- | crates/ra_assists/src/handlers/apply_demorgan.rs | 3 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/early_return.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/invert_if.rs | 25 |
3 files changed, 4 insertions, 26 deletions
diff --git a/crates/ra_assists/src/handlers/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs index ba08a8223..239807e24 100644 --- a/crates/ra_assists/src/handlers/apply_demorgan.rs +++ b/crates/ra_assists/src/handlers/apply_demorgan.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | use super::invert_if::invert_boolean_expression; | ||
2 | use ra_syntax::ast::{self, AstNode}; | 1 | use ra_syntax::ast::{self, AstNode}; |
3 | 2 | ||
4 | use crate::{Assist, AssistCtx, AssistId}; | 3 | use crate::{utils::invert_boolean_expression, Assist, AssistCtx, AssistId}; |
5 | 4 | ||
6 | // Assist: apply_demorgan | 5 | // Assist: apply_demorgan |
7 | // | 6 | // |
diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs index 8eb3bd473..22f88884f 100644 --- a/crates/ra_assists/src/handlers/early_return.rs +++ b/crates/ra_assists/src/handlers/early_return.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{ | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | assist_ctx::{Assist, AssistCtx}, | 12 | assist_ctx::{Assist, AssistCtx}, |
13 | handlers::invert_if::invert_boolean_expression, | 13 | utils::invert_boolean_expression, |
14 | AssistId, | 14 | AssistId, |
15 | }; | 15 | }; |
16 | 16 | ||
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::*; |