authorgravatar for lachlan@lakebythewoods.xyzLachlan Easton <lachlan@lakebythewoods.xyz> 2020-09-15 18:49:59+10:00
committergravatar for lachlan@lakebythewoods.xyzLachlan Easton <lachlan@lakebythewoods.xyz> 2020-09-18 20:34:00+10:00
log4496a6c9cccbd6a9c82b5d4ca7f533b18ebeab32
tree7a980dbf010237366b17b95f592000644f32f21f
parent1aacedf6e197ea212025dccad622894a44eb5461

zig fmt: Special case un-indent comma after multiline string in param list


2 files changed, 16 insertions(+), 2 deletions(-)

lib/std/zig/parser_test.zig+9-2
......@@ -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+7
......@@ -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);