aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorVexu <15308111+Vexu@users.noreply.github.com>2019-06-25 01:12:28 +0300
committerVexu <15308111+Vexu@users.noreply.github.com>2019-06-25 01:12:28 +0300
commitf6d83ba9185dd81106c731e12ab361685fa226c4 (patch)
treea2b3876e81fefaa17b3a3e6b9df2a3da5e621167 /std
parent24400d5882aa2b83a4aed3e4c1503d0393e1c541 (diff)
downloadzig-f6d83ba9185dd81106c731e12ab361685fa226c4.tar.gz
zig-f6d83ba9185dd81106c731e12ab361685fa226c4.zip
fixed comment formatting in arrays and fn params
Diffstat (limited to 'std')
-rw-r--r--std/zig/parser_test.zig38
-rw-r--r--std/zig/render.zig8
2 files changed, 42 insertions, 4 deletions
diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig
index 281f09d57b..dc3e6190f5 100644
--- a/std/zig/parser_test.zig
+++ b/std/zig/parser_test.zig
@@ -2234,6 +2234,44 @@ test "zig fmt: multiline string in array" {
);
}
+test "zig fmt: line comment in array" {
+ try testTransform(
+ \\test "a" {
+ \\ var arr = [_]u32{
+ \\ 0
+ \\ // 1,
+ \\ // 2,
+ \\ };
+ \\}
+ \\
+ ,
+ \\test "a" {
+ \\ var arr = [_]u32{
+ \\ 0, // 1,
+ \\ // 2,
+ \\ };
+ \\}
+ \\
+ );
+}
+
+test "zig fmt: comment after params" {
+ try testTransform(
+ \\fn a(
+ \\ b: u32
+ \\ // c: u32,
+ \\ // d: u32,
+ \\) void {}
+ \\
+ ,
+ \\fn a(
+ \\ b: u32, // c: u32,
+ \\ // d: u32,
+ \\) void {}
+ \\
+ );
+}
+
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;
diff --git a/std/zig/render.zig b/std/zig/render.zig
index ef5c8f2346..b66cbeb860 100644
--- a/std/zig/render.zig
+++ b/std/zig/render.zig
@@ -658,7 +658,7 @@ fn renderExpression(
try renderToken(tree, stream, lbrace, indent, start_col, Space.None);
return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
}
- if (exprs.len == 1) {
+ if (exprs.len == 1 and tree.tokens.at(exprs.at(0).*.lastToken() + 1).id == .RBrace) {
const expr = exprs.at(0).*;
try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
@@ -719,7 +719,7 @@ fn renderExpression(
while (it.next()) |expr| : (i += 1) {
counting_stream.bytes_written = 0;
var dummy_col: usize = 0;
- try renderExpression(allocator, &counting_stream.stream, tree, 0, &dummy_col, expr.*, Space.None);
+ try renderExpression(allocator, &counting_stream.stream, tree, indent, &dummy_col, expr.*, Space.None);
const width = @intCast(usize, counting_stream.bytes_written);
const col = i % row_size;
column_widths[col] = std.math.max(column_widths[col], width);
@@ -1139,8 +1139,8 @@ fn renderExpression(
});
const src_params_trailing_comma = blk: {
- const maybe_comma = tree.prevToken(rparen);
- break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma;
+ const maybe_comma = tree.tokens.at(rparen - 1).id;
+ break :blk maybe_comma == .Comma or maybe_comma == .LineComment;
};
if (!src_params_trailing_comma) {