aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/utils.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-07 14:57:38 +0000
committerAleksey Kladov <[email protected]>2020-02-07 16:28:02 +0000
commitd00add1f1fec59494c3c1a99c27937ae3891458d (patch)
tree06c2bf44b0f9967f5e5f4cdddcec743d896478e8 /crates/ra_assists/src/utils.rs
parent561b4b11ff1d87ea1ff2477dcba6ae1f396573a3 (diff)
Introduce assists utils
Diffstat (limited to 'crates/ra_assists/src/utils.rs')
-rw-r--r--crates/ra_assists/src/utils.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs
new file mode 100644
index 000000000..0d5722295
--- /dev/null
+++ b/crates/ra_assists/src/utils.rs
@@ -0,0 +1,27 @@
1//! Assorted functions shared by several assists.
2
3use ra_syntax::{
4 ast::{self, make},
5 T,
6};
7
8pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
9 if let Some(expr) = invert_special_case(&expr) {
10 return expr;
11 }
12 make::expr_prefix(T![!], expr)
13}
14
15fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
16 match expr {
17 ast::Expr::BinExpr(bin) => match bin.op_kind()? {
18 ast::BinOp::NegatedEqualityTest => bin.replace_op(T![==]).map(|it| it.into()),
19 ast::BinOp::EqualityTest => bin.replace_op(T![!=]).map(|it| it.into()),
20 _ => None,
21 },
22 ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(),
23 // FIXME:
24 // ast::Expr::Literal(true | false )
25 _ => None,
26 }
27}