mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-24 12:32:29 +00:00
Simplify some branch formatting logic
This commit is contained in:
parent
fa877e4184
commit
b51c8b0ba4
1 changed files with 36 additions and 40 deletions
|
@ -700,13 +700,11 @@ fn fmt_when<'a, 'buf>(
|
||||||
|
|
||||||
for (pattern_index, pattern) in patterns.iter().enumerate() {
|
for (pattern_index, pattern) in patterns.iter().enumerate() {
|
||||||
if pattern_index == 0 {
|
if pattern_index == 0 {
|
||||||
match &pattern.value {
|
if let Pattern::SpaceBefore(sub_pattern, spaces) = &pattern.value {
|
||||||
Pattern::SpaceBefore(sub_pattern, spaces) => {
|
|
||||||
let added_blank_line;
|
let added_blank_line;
|
||||||
|
|
||||||
if branch_index > 0 // Never render newlines before the first branch.
|
// Never render newlines before the first branch.
|
||||||
&& matches!(spaces.first(), Some(CommentOrNewline::Newline))
|
if branch_index > 0 {
|
||||||
{
|
|
||||||
if prev_branch_was_multiline {
|
if prev_branch_was_multiline {
|
||||||
// Multiline branches always get a full blank line after them.
|
// Multiline branches always get a full blank line after them.
|
||||||
buf.ensure_ends_with_blank_line();
|
buf.ensure_ends_with_blank_line();
|
||||||
|
@ -734,8 +732,7 @@ fn fmt_when<'a, 'buf>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt_pattern(buf, sub_pattern, indent + INDENT, Parens::NotNeeded);
|
fmt_pattern(buf, sub_pattern, indent + INDENT, Parens::NotNeeded);
|
||||||
}
|
} else {
|
||||||
other => {
|
|
||||||
if branch_index > 0 {
|
if branch_index > 0 {
|
||||||
if prev_branch_was_multiline {
|
if prev_branch_was_multiline {
|
||||||
// Multiline branches always get a full blank line after them.
|
// Multiline branches always get a full blank line after them.
|
||||||
|
@ -745,8 +742,7 @@ fn fmt_when<'a, 'buf>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt_pattern(buf, other, indent + INDENT, Parens::NotNeeded);
|
fmt_pattern(buf, &pattern.value, indent + INDENT, Parens::NotNeeded);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if is_multiline_patterns {
|
if is_multiline_patterns {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue