Make Collection formattable

This commit is contained in:
Richard Feldman 2022-01-30 11:33:46 -05:00
parent 2eb9243942
commit 5c6d2a909e
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
2 changed files with 11 additions and 4 deletions

View file

@ -3,7 +3,7 @@ use crate::{
spaces::{fmt_comments_only, fmt_spaces, NewlineAt, INDENT},
Buf,
};
use roc_parse::ast::{AliasHeader, AssignedField, Expr, Tag, TypeAnnotation};
use roc_parse::ast::{AliasHeader, AssignedField, Collection, Expr, Tag, TypeAnnotation};
use roc_parse::ident::UppercaseIdent;
use roc_region::all::Loc;
@ -83,6 +83,15 @@ where
}
}
impl<'a, T> Formattable for Collection<'a, T>
where
T: Formattable,
{
fn is_multiline(&self) -> bool {
self.items.iter().any(|item| item.is_multiline()) || !self.final_comments().is_empty()
}
}
/// A Located formattable value is also formattable
impl<T> Formattable for Loc<T>
where

View file

@ -17,10 +17,8 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
<T as ExtractSpaces<'a>>::Item: Formattable,
{
buf.indent(indent);
let is_multiline =
items.iter().any(|item| item.is_multiline()) || !items.final_comments().is_empty();
if is_multiline {
if items.is_multiline() {
let braces_indent = indent;
let item_indent = braces_indent + INDENT;
if newline == Newlines::Yes {