mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Format apply funcs with try suffix correctly
This commit is contained in:
parent
90db3b2db0
commit
eb9d1bcf09
2 changed files with 75 additions and 3 deletions
|
@ -92,14 +92,62 @@ fn format_expr_only(
|
||||||
buf.indent(indent);
|
buf.indent(indent);
|
||||||
buf.push_str("try");
|
buf.push_str("try");
|
||||||
}
|
}
|
||||||
|
Expr::PncApply(
|
||||||
|
Loc {
|
||||||
|
value: Expr::TrySuffix(expr),
|
||||||
|
region,
|
||||||
|
},
|
||||||
|
loc_args,
|
||||||
|
) => {
|
||||||
|
let arena = buf.text.bump();
|
||||||
|
let apply = arena.alloc(Expr::PncApply(
|
||||||
|
arena.alloc(Loc {
|
||||||
|
value: **expr,
|
||||||
|
region: *region,
|
||||||
|
}),
|
||||||
|
*loc_args,
|
||||||
|
));
|
||||||
|
format_expr_only(
|
||||||
|
arena.alloc(Expr::TrySuffix(apply)),
|
||||||
|
buf,
|
||||||
|
parens,
|
||||||
|
newlines,
|
||||||
|
indent,
|
||||||
|
);
|
||||||
|
}
|
||||||
Expr::PncApply(loc_expr, loc_args) => {
|
Expr::PncApply(loc_expr, loc_args) => {
|
||||||
fmt_pnc_apply(loc_expr, loc_args, indent, buf);
|
fmt_pnc_apply(loc_expr, loc_args, indent, buf);
|
||||||
}
|
}
|
||||||
|
Expr::Apply(
|
||||||
|
Loc {
|
||||||
|
value: Expr::TrySuffix(expr),
|
||||||
|
region,
|
||||||
|
},
|
||||||
|
loc_args,
|
||||||
|
_,
|
||||||
|
) if buf.flags().parens_and_commas => {
|
||||||
|
let arena = buf.text.bump();
|
||||||
|
let apply = arena.alloc(Expr::PncApply(
|
||||||
|
arena.alloc(Loc {
|
||||||
|
value: **expr,
|
||||||
|
region: *region,
|
||||||
|
}),
|
||||||
|
Collection::with_items(loc_args),
|
||||||
|
));
|
||||||
|
format_expr_only(
|
||||||
|
arena.alloc(Expr::TrySuffix(apply)),
|
||||||
|
buf,
|
||||||
|
parens,
|
||||||
|
newlines,
|
||||||
|
indent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Expr::Apply(loc_expr, loc_args, _) if buf.flags().parens_and_commas => {
|
||||||
|
fmt_pnc_apply(loc_expr, &Collection::with_items(loc_args), indent, buf);
|
||||||
|
}
|
||||||
Expr::Apply(loc_expr, loc_args, _) => {
|
Expr::Apply(loc_expr, loc_args, _) => {
|
||||||
let apply_needs_parens = parens == Parens::InApply || parens == Parens::InApplyLastArg;
|
let apply_needs_parens = parens == Parens::InApply || parens == Parens::InApplyLastArg;
|
||||||
if buf.flags().parens_and_commas {
|
if !apply_needs_parens || loc_args.is_empty() {
|
||||||
fmt_pnc_apply(loc_expr, &Collection::with_items(loc_args), indent, buf);
|
|
||||||
} else if !apply_needs_parens || loc_args.is_empty() {
|
|
||||||
fmt_apply(loc_expr, loc_args, indent, buf);
|
fmt_apply(loc_expr, loc_args, indent, buf);
|
||||||
} else {
|
} else {
|
||||||
fmt_parens(item, buf, indent);
|
fmt_parens(item, buf, indent);
|
||||||
|
|
|
@ -5602,6 +5602,30 @@ mod test_fmt {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pnc_apply_with_try_suffix_after_fn() {
|
||||||
|
expr_formats_to_with_flags(
|
||||||
|
indoc!("some_fn?(arg1, arg2)"),
|
||||||
|
indoc!("some_fn(arg1, arg2)?"),
|
||||||
|
MigrationFlags {
|
||||||
|
snakify: true,
|
||||||
|
parens_and_commas: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ws_apply_with_try_suffix_after_fn() {
|
||||||
|
expr_formats_to_with_flags(
|
||||||
|
indoc!("some_fn? arg1 arg2"),
|
||||||
|
indoc!("some_fn(arg1, arg2)?"),
|
||||||
|
MigrationFlags {
|
||||||
|
snakify: true,
|
||||||
|
parens_and_commas: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn func_call_trailing_multiline_lambda() {
|
fn func_call_trailing_multiline_lambda() {
|
||||||
// New syntax
|
// New syntax
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue