Skip to content

Commit 4496a6c

Browse files
zig fmt: Special case un-indent comma after multiline string in param list
1 parent 1aacedf commit 4496a6c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/std/zig/parser_test.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ test "zig fmt: multiline string parameter in fn call with trailing comma" {
13741374
\\ \\ZIG_C_HEADER_FILES {}
13751375
\\ \\ZIG_DIA_GUIDS_LIB {}
13761376
\\ \\
1377-
\\ ,
1377+
\\ ,
13781378
\\ std.cstr.toSliceConst(c.ZIG_CMAKE_BINARY_DIR),
13791379
\\ std.cstr.toSliceConst(c.ZIG_CXX_COMPILER),
13801380
\\ std.cstr.toSliceConst(c.ZIG_DIA_GUIDS_LIB),
@@ -3385,10 +3385,17 @@ test "zig fmt: Indent comma correctly after multiline string literals in arg lis
33853385
\\ \\------------
33863386
\\ \\xxxxxxxxxxxx
33873387
\\ \\xxxxxxxxxxxx
3388-
\\ ,
3388+
\\ ,
33893389
\\ g.GtkMessageType.GTK_MESSAGE_WARNING,
33903390
\\ null,
33913391
\\ );
3392+
\\
3393+
\\ z.display_message_dialog(*const [323:0]u8,
3394+
\\ \\Message Text
3395+
\\ \\------------
3396+
\\ \\xxxxxxxxxxxx
3397+
\\ \\xxxxxxxxxxxx
3398+
\\ , g.GtkMessageType.GTK_MESSAGE_WARNING, null);
33923399
\\}
33933400
\\
33943401
);

lib/std/zig/render.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,13 @@ fn renderExpression(
10711071
if (i + 1 < params.len) {
10721072
const next_node = params[i + 1];
10731073
try renderExpression(allocator, ais, tree, param_node, Space.None);
1074+
1075+
// Unindent the comma for multiline string literals
1076+
const maybe_multiline_string = param_node.firstToken();
1077+
const is_multiline_string = tree.token_ids[maybe_multiline_string] == .MultilineStringLiteralLine;
1078+
if (is_multiline_string) ais.popIndent();
1079+
defer if (is_multiline_string) ais.pushIndent();
1080+
10741081
const comma = tree.nextToken(param_node.lastToken());
10751082
try renderToken(tree, ais, comma, Space.Newline); // ,
10761083
try renderExtraNewline(tree, ais, next_node);

0 commit comments

Comments
 (0)