aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorLachlan Easton <lachlan@lakebythewoods.xyz>2020-09-15 18:49:59 +1000
committerLachlan Easton <lachlan@lakebythewoods.xyz>2020-09-18 20:34:00 +1000
commit4496a6c9cccbd6a9c82b5d4ca7f533b18ebeab32 (patch)
tree7a980dbf010237366b17b95f592000644f32f21f /lib/std
parent1aacedf6e197ea212025dccad622894a44eb5461 (diff)
downloadzig-4496a6c9cccbd6a9c82b5d4ca7f533b18ebeab32.tar.gz
zig-4496a6c9cccbd6a9c82b5d4ca7f533b18ebeab32.zip
zig fmt: Special case un-indent comma after multiline string in param list
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/zig/parser_test.zig11
-rw-r--r--lib/std/zig/render.zig7
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index c7d64bc513..994ad6d5d1 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -1374,7 +1374,7 @@ test "zig fmt: multiline string parameter in fn call with trailing comma" {
\\ \\ZIG_C_HEADER_FILES {}
\\ \\ZIG_DIA_GUIDS_LIB {}
\\ \\
- \\ ,
+ \\ ,
\\ std.cstr.toSliceConst(c.ZIG_CMAKE_BINARY_DIR),
\\ std.cstr.toSliceConst(c.ZIG_CXX_COMPILER),
\\ 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
\\ \\------------
\\ \\xxxxxxxxxxxx
\\ \\xxxxxxxxxxxx
- \\ ,
+ \\ ,
\\ g.GtkMessageType.GTK_MESSAGE_WARNING,
\\ null,
\\ );
+ \\
+ \\ z.display_message_dialog(*const [323:0]u8,
+ \\ \\Message Text
+ \\ \\------------
+ \\ \\xxxxxxxxxxxx
+ \\ \\xxxxxxxxxxxx
+ \\ , g.GtkMessageType.GTK_MESSAGE_WARNING, null);
\\}
\\
);
diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig
index 30f739aaef..67afbb77d9 100644
--- a/lib/std/zig/render.zig
+++ b/lib/std/zig/render.zig
@@ -1071,6 +1071,13 @@ fn renderExpression(
if (i + 1 < params.len) {
const next_node = params[i + 1];
try renderExpression(allocator, ais, tree, param_node, Space.None);
+
+ // Unindent the comma for multiline string literals
+ const maybe_multiline_string = param_node.firstToken();
+ const is_multiline_string = tree.token_ids[maybe_multiline_string] == .MultilineStringLiteralLine;
+ if (is_multiline_string) ais.popIndent();
+ defer if (is_multiline_string) ais.pushIndent();
+
const comma = tree.nextToken(param_node.lastToken());
try renderToken(tree, ais, comma, Space.Newline); // ,
try renderExtraNewline(tree, ais, next_node);