mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Flip binexpr works for lhs binexpr
This commit is contained in:
parent
bc9c952b6d
commit
e18b89452e
1 changed files with 18 additions and 0 deletions
|
@ -33,6 +33,15 @@ pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the lhs is a binary expression we check if its rhs can be used as the lhs of the current expression
|
||||||
|
let lhs = match BinExpr::cast(lhs.clone()) {
|
||||||
|
Some(lhs) => match lhs.rhs() {
|
||||||
|
Some(lhs) => lhs,
|
||||||
|
None => lhs,
|
||||||
|
},
|
||||||
|
None => lhs,
|
||||||
|
};
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("flip_binexpr", AssistKind::RefactorRewrite),
|
AssistId("flip_binexpr", AssistKind::RefactorRewrite),
|
||||||
"Flip binary expression",
|
"Flip binary expression",
|
||||||
|
@ -114,6 +123,15 @@ mod tests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn flip_binexpr_works_for_lhs_binexpr() {
|
||||||
|
check_assist(
|
||||||
|
flip_binexpr,
|
||||||
|
r"fn f() { let res = 1 + (2 - 3) +$0 4 + 5; }",
|
||||||
|
r"fn f() { let res = 1 + 4 + (2 - 3) + 5; }",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flip_binexpr_works_inside_match() {
|
fn flip_binexpr_works_inside_match() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
Loading…
Reference in a new issue