mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-12 23:06:18 +00:00
Indent for multiline | patterns
This commit is contained in:
parent
872efa9724
commit
244a501433
3 changed files with 21 additions and 17 deletions
|
@ -162,10 +162,6 @@ 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 {
|
||||
|
@ -177,7 +173,7 @@ 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()) {
|
||||
if starts_with_inline_comment(spaces.iter()) {
|
||||
buf.spaces(1);
|
||||
}
|
||||
|
||||
|
@ -206,8 +202,11 @@ 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(_)))
|
||||
fn starts_with_inline_comment<'a, I: IntoIterator<Item = &'a CommentOrNewline<'a>>>(
|
||||
spaces: I,
|
||||
) -> bool {
|
||||
match spaces.into_iter().next() {
|
||||
Some(space) => matches!(space, CommentOrNewline::LineComment(_)),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue