mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Fix case of expr in binop that ends in closure, when it doesn't start on a new line
This commit is contained in:
parent
769baa9f63
commit
bab5e65480
5 changed files with 74 additions and 1 deletions
|
@ -1405,8 +1405,12 @@ fn fmt_binops<'a>(
|
|||
expr_lift_spaces(Parens::InOperator, buf.text.bump(), &loc_left_side.value);
|
||||
format_spaces(buf, lifted_left_side.before, Newlines::Yes, indent);
|
||||
|
||||
buf.indent(indent);
|
||||
let line_indent = buf.cur_line_indent();
|
||||
|
||||
let need_parens = matches!(lifted_left_side.item, Expr::BinOps(..))
|
||||
|| starts_with_unary_minus(lifted_left_side.item);
|
||||
|| starts_with_unary_minus(lifted_left_side.item)
|
||||
|| (ends_with_closure(&lifted_left_side.item) && line_indent < indent);
|
||||
|
||||
if need_parens {
|
||||
fmt_parens(&lifted_left_side.item, buf, indent);
|
||||
|
@ -1451,6 +1455,17 @@ fn fmt_binops<'a>(
|
|||
format_spaces(buf, lifted_right_side.after, Newlines::Yes, indent);
|
||||
}
|
||||
|
||||
fn ends_with_closure(item: &Expr<'_>) -> bool {
|
||||
match item {
|
||||
Expr::Closure(..) => true,
|
||||
Expr::Apply(expr, args, _) => args
|
||||
.last()
|
||||
.map(|a| ends_with_closure(&a.value))
|
||||
.unwrap_or_else(|| ends_with_closure(&expr.value)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn starts_with_unary_minus(item: Expr<'_>) -> bool {
|
||||
match item {
|
||||
Expr::UnaryOp(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue