mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Put a space before comments in patterns
This commit is contained in:
parent
3e2f581db4
commit
872efa9724
1 changed files with 15 additions and 0 deletions
|
@ -162,6 +162,10 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
|
||||
// Space
|
||||
SpaceBefore(sub_pattern, spaces) => {
|
||||
if has_inline_comment(spaces.iter()) {
|
||||
buf.spaces(1);
|
||||
}
|
||||
|
||||
if !sub_pattern.is_multiline() {
|
||||
fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent)
|
||||
} else {
|
||||
|
@ -172,6 +176,11 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
}
|
||||
SpaceAfter(sub_pattern, spaces) => {
|
||||
sub_pattern.format_with_options(buf, parens, newlines, indent);
|
||||
|
||||
if has_inline_comment(spaces.iter()) {
|
||||
buf.spaces(1);
|
||||
}
|
||||
|
||||
if !sub_pattern.is_multiline() {
|
||||
fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent)
|
||||
} else {
|
||||
|
@ -196,3 +205,9 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn has_inline_comment<'a, I: IntoIterator<Item = &'a CommentOrNewline<'a>>>(spaces: I) -> bool {
|
||||
spaces
|
||||
.into_iter()
|
||||
.any(|space| matches!(space, CommentOrNewline::LineComment(_)))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue