mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
fixed unnecessary double indentation
This commit is contained in:
parent
af9a03b5ba
commit
454933e2c6
5 changed files with 47 additions and 6 deletions
|
@ -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::*;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue