diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-25 21:38:46 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-25 21:38:46 +0100 |
commit | 54d1a582812e01691ecb2f8ed11e8df9dda1530c (patch) | |
tree | d57842c6462f4921976d6d9642ce7751681cf0bd /crates/ra_assists/src/assists/apply_demorgan.rs | |
parent | e6cb06d2850b9b9c38c0c13d6948ab39adcd652e (diff) | |
parent | d385438bcc8d302fbcb91114e19ac0cc30528822 (diff) |
Merge #2071
2071: generate more assists docs r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/assists/apply_demorgan.rs')
-rw-r--r-- | crates/ra_assists/src/assists/apply_demorgan.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/crates/ra_assists/src/assists/apply_demorgan.rs b/crates/ra_assists/src/assists/apply_demorgan.rs index 5f2b0dd18..a072f63e7 100644 --- a/crates/ra_assists/src/assists/apply_demorgan.rs +++ b/crates/ra_assists/src/assists/apply_demorgan.rs | |||
@@ -1,18 +1,26 @@ | |||
1 | //! This contains the functions associated with the demorgan assist. | ||
2 | //! This assist transforms boolean expressions of the form `!a || !b` into | ||
3 | //! `!(a && b)`. | ||
4 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
5 | use ra_syntax::ast::{self, AstNode}; | 2 | use ra_syntax::ast::{self, AstNode}; |
6 | use ra_syntax::SyntaxNode; | 3 | use ra_syntax::SyntaxNode; |
7 | 4 | ||
8 | use crate::{Assist, AssistCtx, AssistId}; | 5 | use crate::{Assist, AssistCtx, AssistId}; |
9 | 6 | ||
10 | /// Assist for applying demorgan's law | 7 | // Assist: apply_demorgan |
11 | /// | 8 | // Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). |
12 | /// This transforms expressions of the form `!l || !r` into `!(l && r)`. | 9 | // This transforms expressions of the form `!l || !r` into `!(l && r)`. |
13 | /// This also works with `&&`. This assist can only be applied with the cursor | 10 | // This also works with `&&`. This assist can only be applied with the cursor |
14 | /// on either `||` or `&&`, with both operands being a negation of some kind. | 11 | // on either `||` or `&&`, with both operands being a negation of some kind. |
15 | /// This means something of the form `!x` or `x != y`. | 12 | // This means something of the form `!x` or `x != y`. |
13 | // ``` | ||
14 | // fn main() { | ||
15 | // if x != 4 ||<|> !y {} | ||
16 | // } | ||
17 | // ``` | ||
18 | // -> | ||
19 | // ``` | ||
20 | // fn main() { | ||
21 | // if !(x == 4 && y) {} | ||
22 | // } | ||
23 | // ``` | ||
16 | pub(crate) fn apply_demorgan(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 24 | pub(crate) fn apply_demorgan(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
17 | let expr = ctx.node_at_offset::<ast::BinExpr>()?; | 25 | let expr = ctx.node_at_offset::<ast::BinExpr>()?; |
18 | let op = expr.op_kind()?; | 26 | let op = expr.op_kind()?; |