| author | |
| committer | |
| log | 988f1c6a6f075e63d0ab2dc8f6e802a67b4a0902 |
| tree | 556d86698b53d5be7708ded08c817ba4f28d318c |
| parent | 08107a555eb1bc8d6e9aa8d80507896d08b2b18d |
also
zig fmt: space after top level doc comment3 files changed, 34 insertions(+), 1 deletions(-)
lib/std/zig/parse.zig+6-1| ... | ... | @@ -3706,7 +3706,12 @@ const Parser = struct { |
| 3706 | 3706 | const param = try p.expectParamDecl(); |
| 3707 | 3707 | if (param != 0) break param; |
| 3708 | 3708 | switch (p.token_tags[p.nextToken()]) { |
| 3709 | .comma => continue, | |
| 3709 | .comma => { | |
| 3710 | if (p.eatToken(.r_paren)) |_| { | |
| 3711 | return SmallSpan{ .zero_or_one = 0 }; | |
| 3712 | } | |
| 3713 | continue; | |
| 3714 | }, | |
| 3710 | 3715 | .r_paren => return SmallSpan{ .zero_or_one = 0 }, |
| 3711 | 3716 | else => { |
| 3712 | 3717 | // This is likely just a missing comma; |
lib/std/zig/parser_test.zig+18| ... | ... | @@ -4134,6 +4134,24 @@ test "zig fmt: function params should align nicely" { |
| 4134 | 4134 | ); |
| 4135 | 4135 | } |
| 4136 | 4136 | |
| 4137 | test "zig fmt: fn proto end with anytype and comma" { | |
| 4138 | try testCanonical( | |
| 4139 | \\pub fn format( | |
| 4140 | \\ out_stream: anytype, | |
| 4141 | \\) !void {} | |
| 4142 | \\ | |
| 4143 | ); | |
| 4144 | } | |
| 4145 | ||
| 4146 | test "zig fmt: space after top level doc comment" { | |
| 4147 | try testCanonical( | |
| 4148 | \\//! top level doc comment | |
| 4149 | \\ | |
| 4150 | \\field: i32, | |
| 4151 | \\ | |
| 4152 | ); | |
| 4153 | } | |
| 4154 | ||
| 4137 | 4155 | test "zig fmt: error for invalid bit range" { |
| 4138 | 4156 | try testError( |
| 4139 | 4157 | \\var x: []align(0:0:0)u8 = bar; |
lib/std/zig/render.zig+10| ... | ... | @@ -1449,6 +1449,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. |
| 1449 | 1449 | .identifier => {}, |
| 1450 | 1450 | .keyword_anytype => { |
| 1451 | 1451 | try renderToken(ais, tree, last_param_token, .comma); // anytype |
| 1452 | if (token_tags[last_param_token + 1] == .comma) | |
| 1453 | last_param_token += 1; | |
| 1452 | 1454 | continue; |
| 1453 | 1455 | }, |
| 1454 | 1456 | .r_paren => break, |
| ... | ... | @@ -1462,6 +1464,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. |
| 1462 | 1464 | } |
| 1463 | 1465 | if (token_tags[last_param_token] == .keyword_anytype) { |
| 1464 | 1466 | try renderToken(ais, tree, last_param_token, .comma); // anytype |
| 1467 | if (token_tags[last_param_token + 1] == .comma) | |
| 1468 | last_param_token += 1; | |
| 1465 | 1469 | continue; |
| 1466 | 1470 | } |
| 1467 | 1471 | const param = fn_proto.ast.params[param_i]; |
| ... | ... | @@ -2363,6 +2367,12 @@ fn renderContainerDocComments(ais: *Ais, tree: ast.Tree, start_token: ast.TokenI |
| 2363 | 2367 | while (token_tags[tok] == .container_doc_comment) : (tok += 1) { |
| 2364 | 2368 | try renderToken(ais, tree, tok, .newline); |
| 2365 | 2369 | } |
| 2370 | // Render extra newline if there is one between final container doc comment and | |
| 2371 | // the next token. If the next token is a doc comment, that code path | |
| 2372 | // will have its own logic to insert a newline. | |
| 2373 | if (token_tags[tok] != .doc_comment) { | |
| 2374 | try renderExtraNewlineToken(ais, tree, tok); | |
| 2375 | } | |
| 2366 | 2376 | } |
| 2367 | 2377 | |
| 2368 | 2378 | fn tokenSliceForRender(tree: ast.Tree, token_index: ast.TokenIndex) []const u8 { |