Skip to content

Commit e18b894

Browse files
cardosoVeykril
authored andcommitted
Flip binexpr works for lhs binexpr
1 parent bc9c952 commit e18b894

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

crates/ide-assists/src/handlers/flip_binexpr.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
3333
return None;
3434
}
3535

36+
// If the lhs is a binary expression we check if its rhs can be used as the lhs of the current expression
37+
let lhs = match BinExpr::cast(lhs.clone()) {
38+
Some(lhs) => match lhs.rhs() {
39+
Some(lhs) => lhs,
40+
None => lhs,
41+
},
42+
None => lhs,
43+
};
44+
3645
acc.add(
3746
AssistId("flip_binexpr", AssistKind::RefactorRewrite),
3847
"Flip binary expression",
@@ -114,6 +123,15 @@ mod tests {
114123
)
115124
}
116125

126+
#[test]
127+
fn flip_binexpr_works_for_lhs_binexpr() {
128+
check_assist(
129+
flip_binexpr,
130+
r"fn f() { let res = 1 + (2 - 3) +$0 4 + 5; }",
131+
r"fn f() { let res = 1 + 4 + (2 - 3) + 5; }",
132+
)
133+
}
134+
117135
#[test]
118136
fn flip_binexpr_works_inside_match() {
119137
check_assist(

0 commit comments

Comments
 (0)