aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/apply_demorgan.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers/apply_demorgan.rs')
-rw-r--r--crates/ra_assists/src/handlers/apply_demorgan.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/crates/ra_assists/src/handlers/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs
index 233e8fb8e..a1fd6e112 100644
--- a/crates/ra_assists/src/handlers/apply_demorgan.rs
+++ b/crates/ra_assists/src/handlers/apply_demorgan.rs
@@ -1,6 +1,6 @@
1use ra_syntax::ast::{self, AstNode}; 1use ra_syntax::ast::{self, AstNode};
2 2
3use crate::{utils::invert_boolean_expression, AssistContext, AssistId, Assists}; 3use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKind, Assists};
4 4
5// Assist: apply_demorgan 5// Assist: apply_demorgan
6// 6//
@@ -39,11 +39,17 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<(
39 let rhs_range = rhs.syntax().text_range(); 39 let rhs_range = rhs.syntax().text_range();
40 let not_rhs = invert_boolean_expression(rhs); 40 let not_rhs = invert_boolean_expression(rhs);
41 41
42 acc.add(AssistId("apply_demorgan"), "Apply De Morgan's law", op_range, |edit| { 42 acc.add(
43 edit.replace(op_range, opposite_op); 43 AssistId("apply_demorgan"),
44 edit.replace(lhs_range, format!("!({}", not_lhs.syntax().text())); 44 AssistKind::RefactorRewrite,
45 edit.replace(rhs_range, format!("{})", not_rhs.syntax().text())); 45 "Apply De Morgan's law",
46 }) 46 op_range,
47 |edit| {
48 edit.replace(op_range, opposite_op);
49 edit.replace(lhs_range, format!("!({}", not_lhs.syntax().text()));
50 edit.replace(rhs_range, format!("{})", not_rhs.syntax().text()));
51 },
52 )
47} 53}
48 54
49// Return the opposite text for a given logical operator, if it makes sense 55// Return the opposite text for a given logical operator, if it makes sense