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" {...@@ -1374,7 +1374,7 @@ test "zig fmt: multiline string parameter in fn call with trailing comma" {
1374 \\ \\ZIG_C_HEADER_FILES {}1374 \\ \\ZIG_C_HEADER_FILES {}
1375 \\ \\ZIG_DIA_GUIDS_LIB {}1375 \\ \\ZIG_DIA_GUIDS_LIB {}
1376 \\ \\1376 \\ \\
1377 \\ ,1377 \\ ,
1378 \\ std.cstr.toSliceConst(c.ZIG_CMAKE_BINARY_DIR),1378 \\ std.cstr.toSliceConst(c.ZIG_CMAKE_BINARY_DIR),
1379 \\ std.cstr.toSliceConst(c.ZIG_CXX_COMPILER),1379 \\ std.cstr.toSliceConst(c.ZIG_CXX_COMPILER),
1380 \\ std.cstr.toSliceConst(c.ZIG_DIA_GUIDS_LIB),1380 \\ 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...@@ -3385,10 +3385,17 @@ test "zig fmt: Indent comma correctly after multiline string literals in arg lis
3385 \\ \\------------3385 \\ \\------------
3386 \\ \\xxxxxxxxxxxx3386 \\ \\xxxxxxxxxxxx
3387 \\ \\xxxxxxxxxxxx3387 \\ \\xxxxxxxxxxxx
3388 \\ ,3388 \\ ,
3389 \\ g.GtkMessageType.GTK_MESSAGE_WARNING,3389 \\ g.GtkMessageType.GTK_MESSAGE_WARNING,
3390 \\ null,3390 \\ null,
3391 \\ );3391 \\ );
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);
3392 \\}3399 \\}
3393 \\3400 \\
3394 );3401 );
lib/std/zig/render.zig+7
...@@ -1071,6 +1071,13 @@ fn renderExpression(...@@ -1071,6 +1071,13 @@ fn renderExpression(
1071 if (i + 1 < params.len) {1071 if (i + 1 < params.len) {
1072 const next_node = params[i + 1];1072 const next_node = params[i + 1];
1073 try renderExpression(allocator, ais, tree, param_node, Space.None);1073 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
1074 const comma = tree.nextToken(param_node.lastToken());1081 const comma = tree.nextToken(param_node.lastToken());
1075 try renderToken(tree, ais, comma, Space.Newline); // ,1082 try renderToken(tree, ais, comma, Space.Newline); // ,
1076 try renderExtraNewline(tree, ais, next_node);1083 try renderExtraNewline(tree, ais, next_node);