aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r--crates/ra_assists/src/handlers/apply_demorgan.rs3
-rw-r--r--crates/ra_assists/src/handlers/early_return.rs2
-rw-r--r--crates/ra_assists/src/handlers/invert_if.rs25
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 @@
1use super::invert_if::invert_boolean_expression;
2use ra_syntax::ast::{self, AstNode}; 1use ra_syntax::ast::{self, AstNode};
3 2
4use crate::{Assist, AssistCtx, AssistId}; 3use 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
11use crate::{ 11use 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 @@
1use ra_syntax::ast::{self, make, AstNode}; 1use ra_syntax::ast::{self, AstNode};
2use ra_syntax::T; 2use ra_syntax::T;
3 3
4use crate::{Assist, AssistCtx, AssistId}; 4use 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
54pub(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
61pub(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)]
76mod tests { 55mod tests {
77 use super::*; 56 use super::*;