aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-30 15:59:57 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-30 15:59:57 -0400
commit9090a2a09f119510f40c5385f3790cc6b6539abc (patch)
tree06616ba7f497a1d14003413816b98c2e0e81bda3
parentf38fa3389c881ef8341011c05d7b2435686068e7 (diff)
Arg formatting tweaks
-rw-r--r--src/formatter/args.c22
-rw-r--r--src/formatter/formatter.c10
2 files changed, 17 insertions, 15 deletions
diff --git a/src/formatter/args.c b/src/formatter/args.c
index 9809645f..997a1e39 100644
--- a/src/formatter/args.c
+++ b/src/formatter/args.c
@@ -29,14 +29,14 @@ Text_t format_arg(arg_ast_t *arg, Table_t comments, Text_t indent) {
OptionalText_t format_inline_args(arg_ast_t *args, Table_t comments) {
Text_t code = EMPTY_TEXT;
- for (; args; args = args->next) {
- if (args->name && args->next && args->type == args->next->type && args->value == args->next->value) {
- code = Texts(code, Text$from_str(args->name), ",");
+ for (arg_ast_t *arg = args; arg; arg = arg->next) {
+ if (arg->name && arg->next && arg->type == arg->next->type && arg->value == arg->next->value) {
+ code = Texts(code, Text$from_str(arg->name), ",");
} else {
- code = Texts(code, must(format_inline_arg(args, comments)));
- if (args->next) code = Texts(code, ", ");
+ code = Texts(code, must(format_inline_arg(arg, comments)));
+ if (arg->next) code = Texts(code, ", ");
}
- if (args->next && range_has_comment(args->end, args->next->start, comments)) return NONE_TEXT;
+ if (arg->next && range_has_comment(arg->end, arg->next->start, comments)) return NONE_TEXT;
}
return code;
}
@@ -45,12 +45,12 @@ Text_t format_args(arg_ast_t *args, Table_t comments, Text_t indent) {
OptionalText_t inline_args = format_inline_args(args, comments);
if (inline_args.length >= 0 && inline_args.length <= MAX_WIDTH) return inline_args;
Text_t code = EMPTY_TEXT;
- for (; args; args = args->next) {
- if (args->name && args->next && args->type == args->next->type && args->value == args->next->value) {
- code = Texts(code, Text$from_str(args->name), ",");
+ for (arg_ast_t *arg = args; arg; arg = arg->next) {
+ if (arg->name && arg->next && arg->type == arg->next->type && arg->value == arg->next->value) {
+ code = Texts(code, Text$from_str(arg->name), ",");
} else {
- code =
- Texts(code, "\n", indent, single_indent, format_arg(args, comments, Texts(indent, single_indent)), ",");
+ code = Texts(code, "\n", indent, single_indent, format_arg(arg, comments, Texts(indent, single_indent)));
+ if (args->next) code = Texts(code, ",");
}
}
return code;
diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c
index addf8445..1719a294 100644
--- a/src/formatter/formatter.c
+++ b/src/formatter/formatter.c
@@ -774,14 +774,16 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) {
/*multiline*/ case FunctionCall: {
if (inlined_fits) return inlined;
DeclareMatch(call, ast, FunctionCall);
- return Texts(fmt(call->fn, comments, indent), "(\n", indent, single_indent,
- format_args(call->args, comments, indent), "\n", Texts(indent, single_indent), ")");
+ Text_t args = format_args(call->args, comments, indent);
+ return Texts(fmt(call->fn, comments, indent), "(", args,
+ Text$has(args, Text("\n")) ? Texts("\n", indent) : EMPTY_TEXT, ")");
}
/*multiline*/ case MethodCall: {
if (inlined_fits) return inlined;
DeclareMatch(call, ast, MethodCall);
- return Texts(termify(call->self, comments, indent), ".", Text$from_str(call->name), "(\n", indent,
- single_indent, format_args(call->args, comments, indent), "\n", Texts(indent, single_indent), ")");
+ Text_t args = format_args(call->args, comments, indent);
+ return Texts(termify(call->self, comments, indent), ".", Text$from_str(call->name), "(", args,
+ Text$has(args, Text("\n")) ? Texts("\n", indent) : EMPTY_TEXT, ")");
}
/*multiline*/ case DocTest: {
DeclareMatch(test, ast, DocTest);