fixed unnecessary double indentation

This commit is contained in:
Anton-4 2022-03-07 16:02:11 +01:00
parent af9a03b5ba
commit 454933e2c6
No known key found for this signature in database
GPG key ID: C954D6E0F9C0ABFD
5 changed files with 47 additions and 6 deletions

View file

@ -143,11 +143,18 @@ impl<'a> Formattable for Expr<'a> {
} else {
buf.indent(indent);
buf.push('(');
let next_indent =
if starts_with_newline(sub_expr) {
indent + INDENT
} else {
indent
};
sub_expr.format_with_options(
buf,
Parens::NotNeeded,
Newlines::Yes,
indent + INDENT,
next_indent,
);
buf.indent(indent);
buf.push(')');
@ -304,6 +311,28 @@ impl<'a> Formattable for Expr<'a> {
}
}
fn starts_with_newline(expr: &Expr) -> bool {
use roc_parse::ast::Expr::*;
match expr {
SpaceBefore(_, comment_or_newline) =>
if (**comment_or_newline).len() > 0 {
// safe because we check the length before
(**comment_or_newline).get(0).unwrap().is_newline()
} else {
false
}
SpaceAfter(_, comment_or_newline) =>
if (**comment_or_newline).len() > 0 {
// safe because we check the length before
(**comment_or_newline).get(0).unwrap().is_newline()
} else {
false
},
_ => false
}
}
fn format_str_segment<'a, 'buf>(seg: &StrSegment<'a>, buf: &mut Buf<'buf>, indent: u16) {
use StrSegment::*;