authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-06-25 01:12:28+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-06-25 01:12:28+03:00
logf6d83ba9185dd81106c731e12ab361685fa226c4
treea2b3876e81fefaa17b3a3e6b9df2a3da5e621167
parent24400d5882aa2b83a4aed3e4c1503d0393e1c541
signaturelock-open Commit is signed but in an unrecognized format.

fixed comment formatting in arrays and fn params


2 files changed, 42 insertions(+), 4 deletions(-)

std/zig/parser_test.zig+38
......@@ -2234,6 +2234,44 @@ test "zig fmt: multiline string in array" {
22342234 );
22352235}
22362236
2237test "zig fmt: line comment in array" {
2238 try testTransform(
2239 \\test "a" {
2240 \\ var arr = [_]u32{
2241 \\ 0
2242 \\ // 1,
2243 \\ // 2,
2244 \\ };
2245 \\}
2246 \\
2247 ,
2248 \\test "a" {
2249 \\ var arr = [_]u32{
2250 \\ 0, // 1,
2251 \\ // 2,
2252 \\ };
2253 \\}
2254 \\
2255 );
2256}
2257
2258test "zig fmt: comment after params" {
2259 try testTransform(
2260 \\fn a(
2261 \\ b: u32
2262 \\ // c: u32,
2263 \\ // d: u32,
2264 \\) void {}
2265 \\
2266 ,
2267 \\fn a(
2268 \\ b: u32, // c: u32,
2269 \\ // d: u32,
2270 \\) void {}
2271 \\
2272 );
2273}
2274
22372275const std = @import("std");
22382276const mem = std.mem;
22392277const warn = std.debug.warn;
std/zig/render.zig+4-4
......@@ -658,7 +658,7 @@ fn renderExpression(
658658 try renderToken(tree, stream, lbrace, indent, start_col, Space.None);
659659 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
660660 }
661 if (exprs.len == 1) {
661 if (exprs.len == 1 and tree.tokens.at(exprs.at(0).*.lastToken() + 1).id == .RBrace) {
662662 const expr = exprs.at(0).*;
663663
664664 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
......@@ -719,7 +719,7 @@ fn renderExpression(
719719 while (it.next()) |expr| : (i += 1) {
720720 counting_stream.bytes_written = 0;
721721 var dummy_col: usize = 0;
722 try renderExpression(allocator, &counting_stream.stream, tree, 0, &dummy_col, expr.*, Space.None);
722 try renderExpression(allocator, &counting_stream.stream, tree, indent, &dummy_col, expr.*, Space.None);
723723 const width = @intCast(usize, counting_stream.bytes_written);
724724 const col = i % row_size;
725725 column_widths[col] = std.math.max(column_widths[col], width);
......@@ -1139,8 +1139,8 @@ fn renderExpression(
11391139 });
11401140
11411141 const src_params_trailing_comma = blk: {
1142 const maybe_comma = tree.prevToken(rparen);
1143 break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma;
1142 const maybe_comma = tree.tokens.at(rparen - 1).id;
1143 break :blk maybe_comma == .Comma or maybe_comma == .LineComment;
11441144 };
11451145
11461146 if (!src_params_trailing_comma) {