mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
formatter: add newlines between parens delimiters for multiline expressions
This commit is contained in:
parent
0d3a614945
commit
e2e77a2324
3 changed files with 71 additions and 3 deletions
|
@ -132,9 +132,20 @@ impl<'a> Formattable for Expr<'a> {
|
|||
if parens == Parens::NotNeeded && !sub_expr_requests_parens(sub_expr) {
|
||||
sub_expr.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent);
|
||||
} else {
|
||||
let should_add_newlines = match sub_expr {
|
||||
Expr::Closure(..)
|
||||
| Expr::SpaceBefore(..)
|
||||
| Expr::SpaceAfter(Closure(..), ..) => false,
|
||||
_ => sub_expr.is_multiline(),
|
||||
};
|
||||
|
||||
buf.indent(indent);
|
||||
buf.push('(');
|
||||
let next_indent = if starts_with_newline(sub_expr) {
|
||||
if should_add_newlines {
|
||||
buf.newline();
|
||||
}
|
||||
|
||||
let next_indent = if starts_with_newline(sub_expr) || should_add_newlines {
|
||||
indent + INDENT
|
||||
} else {
|
||||
indent
|
||||
|
@ -146,6 +157,10 @@ impl<'a> Formattable for Expr<'a> {
|
|||
Newlines::Yes,
|
||||
next_indent,
|
||||
);
|
||||
|
||||
if !matches!(sub_expr, Expr::SpaceAfter(..)) && should_add_newlines {
|
||||
buf.newline();
|
||||
}
|
||||
buf.indent(indent);
|
||||
buf.push(')');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue