mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
Fix multiline_binop_conditional_with_comments
This commit is contained in:
parent
da8a1fb81f
commit
f01d6a55f7
2 changed files with 46 additions and 7 deletions
|
@ -828,10 +828,22 @@ fn fmt_if<'a, 'buf>(
|
||||||
match &expr_below {
|
match &expr_below {
|
||||||
Expr::SpaceAfter(expr_above, spaces_after_expr) => {
|
Expr::SpaceAfter(expr_above, spaces_after_expr) => {
|
||||||
expr_above.format(buf, return_indent);
|
expr_above.format(buf, return_indent);
|
||||||
|
|
||||||
|
// If any of the spaces is a newline, add a newline at the top.
|
||||||
|
// Otherwise leave it as just a comment.
|
||||||
|
let newline_at = if spaces_after_expr
|
||||||
|
.iter()
|
||||||
|
.any(|spaces| matches!(spaces, CommentOrNewline::Newline))
|
||||||
|
{
|
||||||
|
NewlineAt::Top
|
||||||
|
} else {
|
||||||
|
NewlineAt::None
|
||||||
|
};
|
||||||
|
|
||||||
fmt_comments_only(
|
fmt_comments_only(
|
||||||
buf,
|
buf,
|
||||||
spaces_after_expr.iter(),
|
spaces_after_expr.iter(),
|
||||||
NewlineAt::None,
|
newline_at,
|
||||||
return_indent,
|
return_indent,
|
||||||
);
|
);
|
||||||
buf.newline();
|
buf.newline();
|
||||||
|
@ -876,12 +888,18 @@ fn fmt_if<'a, 'buf>(
|
||||||
Expr::SpaceAfter(expr_above, spaces_above) => {
|
Expr::SpaceAfter(expr_above, spaces_above) => {
|
||||||
expr_above.format(buf, return_indent);
|
expr_above.format(buf, return_indent);
|
||||||
|
|
||||||
fmt_comments_only(
|
// If any of the spaces is a newline, add a newline at the top.
|
||||||
buf,
|
// Otherwise leave it as just a comment.
|
||||||
spaces_above.iter(),
|
let newline_at = if spaces_above
|
||||||
NewlineAt::Top,
|
.iter()
|
||||||
return_indent,
|
.any(|spaces| matches!(spaces, CommentOrNewline::Newline))
|
||||||
);
|
{
|
||||||
|
NewlineAt::Top
|
||||||
|
} else {
|
||||||
|
NewlineAt::None
|
||||||
|
};
|
||||||
|
|
||||||
|
fmt_comments_only(buf, spaces_above.iter(), newline_at, return_indent);
|
||||||
buf.newline();
|
buf.newline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4037,6 +4037,27 @@ mod test_fmt {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn multiline_binop_conditional_with_comments() {
|
||||||
|
expr_formats_same(indoc!(
|
||||||
|
r#"
|
||||||
|
if
|
||||||
|
x
|
||||||
|
+ 1 # comment 1
|
||||||
|
> 0 # comment 2
|
||||||
|
then
|
||||||
|
y
|
||||||
|
* 2 # comment 3
|
||||||
|
< 1 # comment 4
|
||||||
|
else
|
||||||
|
42
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn precedence_conflict_greater_than() {
|
fn precedence_conflict_greater_than() {
|
||||||
expr_formats_same(indoc!(
|
expr_formats_same(indoc!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue