mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +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.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) => {
|
||||
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, _) => {
|
||||
let apply_needs_parens = parens == Parens::InApply || parens == Parens::InApplyLastArg;
|
||||
if buf.flags().parens_and_commas {
|
||||
fmt_pnc_apply(loc_expr, &Collection::with_items(loc_args), indent, buf);
|
||||
} else if !apply_needs_parens || loc_args.is_empty() {
|
||||
if !apply_needs_parens || loc_args.is_empty() {
|
||||
fmt_apply(loc_expr, loc_args, indent, buf);
|
||||
} else {
|
||||
fmt_parens(item, buf, indent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue