mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
Format multiline reecord builder fields nicely
This commit is contained in:
parent
5edcb31f32
commit
4cd2c957ca
2 changed files with 69 additions and 5 deletions
|
@ -1544,8 +1544,15 @@ fn format_record_builder_field_multiline(
|
|||
|
||||
buf.push_str(separator_prefix);
|
||||
buf.push_str(":");
|
||||
buf.spaces(1);
|
||||
ann.value.format(buf, indent);
|
||||
|
||||
if ann.value.is_multiline() {
|
||||
buf.newline();
|
||||
ann.value.format(buf, indent + INDENT);
|
||||
} else {
|
||||
buf.spaces(1);
|
||||
ann.value.format(buf, indent);
|
||||
}
|
||||
|
||||
buf.push(',');
|
||||
}
|
||||
ApplyValue(name, colon_spaces, arrow_spaces, ann) => {
|
||||
|
@ -1564,13 +1571,18 @@ fn format_record_builder_field_multiline(
|
|||
|
||||
if !arrow_spaces.is_empty() {
|
||||
fmt_spaces(buf, arrow_spaces.iter(), indent);
|
||||
buf.indent(indent);
|
||||
buf.indent(indent + INDENT);
|
||||
}
|
||||
|
||||
buf.push_str("<-");
|
||||
buf.spaces(1);
|
||||
|
||||
ann.value.format(buf, indent);
|
||||
if ann.value.is_multiline() {
|
||||
buf.newline();
|
||||
ann.value.format(buf, indent + INDENT);
|
||||
} else {
|
||||
buf.spaces(1);
|
||||
ann.value.format(buf, indent);
|
||||
}
|
||||
buf.push(',');
|
||||
}
|
||||
LabelOnly(name) => {
|
||||
|
|
|
@ -1978,6 +1978,58 @@ mod test_fmt {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiline_record_builder_field() {
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
succeed {
|
||||
a: <- get "a" |> map (\x -> x * 2)
|
||||
|> batch,
|
||||
b: <- get "b" |> batch,
|
||||
c: items
|
||||
|> List.map \x -> x * 2
|
||||
}
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
succeed {
|
||||
a: <-
|
||||
get "a"
|
||||
|> map (\x -> x * 2)
|
||||
|> batch,
|
||||
b: <- get "b" |> batch,
|
||||
c:
|
||||
items
|
||||
|> List.map \x -> x * 2,
|
||||
}
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
succeed {
|
||||
a: # I like to comment in weird places
|
||||
<- get "a" |> batch,
|
||||
b: <- get "b" |> batch,
|
||||
}
|
||||
"#
|
||||
));
|
||||
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
succeed {
|
||||
a:
|
||||
# I like to comment in weird places
|
||||
<- get "a" |> batch,
|
||||
b: <- get "b" |> batch,
|
||||
}
|
||||
"#
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outdentable_record_builders() {
|
||||
expr_formats_to(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue