mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Improve indent of has-abilities clauses
This commit is contained in:
parent
dc3f8db6b8
commit
be9944a7e1
@ -79,7 +79,7 @@ impl<'a> Formattable for TypeDef<'a> {
|
||||
Opaque {
|
||||
header: TypeHeader { name, vars },
|
||||
typ: ann,
|
||||
derived,
|
||||
derived: has_abilities,
|
||||
} => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(name.value);
|
||||
@ -95,28 +95,26 @@ impl<'a> Formattable for TypeDef<'a> {
|
||||
let ann_is_where_clause =
|
||||
matches!(ann.extract_spaces().item, TypeAnnotation::Where(..));
|
||||
|
||||
// Always put the has-derived clause on a newline if it is itself multiline, or
|
||||
// the annotation has a where-has clause.
|
||||
let derived_multiline = if let Some(derived) = derived {
|
||||
!derived.value.is_empty() && (derived.is_multiline() || ann_is_where_clause)
|
||||
// Always put the has-abilities clause on a newline if the opaque annotation
|
||||
// contains a where-has clause.
|
||||
let has_abilities_multiline = if let Some(has_abilities) = has_abilities {
|
||||
!has_abilities.value.is_empty() && ann_is_where_clause
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let make_multiline = ann.is_multiline() || derived_multiline;
|
||||
let make_multiline = ann.is_multiline() || has_abilities_multiline;
|
||||
|
||||
ann.format(buf, indent);
|
||||
|
||||
if let Some(derived) = derived {
|
||||
if !make_multiline {
|
||||
buf.spaces(1);
|
||||
}
|
||||
if let Some(has_abilities) = has_abilities {
|
||||
buf.spaces(1);
|
||||
|
||||
derived.format_with_options(
|
||||
has_abilities.format_with_options(
|
||||
buf,
|
||||
Parens::NotNeeded,
|
||||
Newlines::from_bool(make_multiline),
|
||||
indent + INDENT,
|
||||
indent + 1 + INDENT,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5078,7 +5078,7 @@ mod test_fmt {
|
||||
indoc!(
|
||||
r#"
|
||||
A := U8
|
||||
has [Eq, Hash]
|
||||
has [Eq, Hash]
|
||||
|
||||
0
|
||||
"#
|
||||
@ -5096,7 +5096,7 @@ mod test_fmt {
|
||||
indoc!(
|
||||
r#"
|
||||
A := a | a has Hash
|
||||
has [Eq, Hash]
|
||||
has [Eq, Hash]
|
||||
|
||||
0
|
||||
"#
|
||||
@ -5154,13 +5154,12 @@ mod test_fmt {
|
||||
indoc!(
|
||||
r#"
|
||||
A := U8 has [Eq { eq, eq1 }]
|
||||
A := U8
|
||||
has [
|
||||
Eq {
|
||||
eq,
|
||||
eq1,
|
||||
},
|
||||
]
|
||||
A := U8 has [
|
||||
Eq {
|
||||
eq,
|
||||
eq1,
|
||||
},
|
||||
]
|
||||
|
||||
0
|
||||
"#
|
||||
@ -5170,7 +5169,7 @@ mod test_fmt {
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
A := a | a has Other
|
||||
has [Eq { eq }, Hash { hash }]
|
||||
has [Eq { eq }, Hash { hash }]
|
||||
|
||||
0
|
||||
"#
|
||||
|
Loading…
Reference in New Issue
Block a user