mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
Make Collection formattable
This commit is contained in:
parent
2eb9243942
commit
5c6d2a909e
2 changed files with 11 additions and 4 deletions
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
spaces::{fmt_comments_only, fmt_spaces, NewlineAt, INDENT},
|
spaces::{fmt_comments_only, fmt_spaces, NewlineAt, INDENT},
|
||||||
Buf,
|
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_parse::ident::UppercaseIdent;
|
||||||
use roc_region::all::Loc;
|
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
|
/// A Located formattable value is also formattable
|
||||||
impl<T> Formattable for Loc<T>
|
impl<T> Formattable for Loc<T>
|
||||||
where
|
where
|
||||||
|
|
|
@ -17,10 +17,8 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
|
||||||
<T as ExtractSpaces<'a>>::Item: Formattable,
|
<T as ExtractSpaces<'a>>::Item: Formattable,
|
||||||
{
|
{
|
||||||
buf.indent(indent);
|
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 braces_indent = indent;
|
||||||
let item_indent = braces_indent + INDENT;
|
let item_indent = braces_indent + INDENT;
|
||||||
if newline == Newlines::Yes {
|
if newline == Newlines::Yes {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue