mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
zig fmt: fn proto end with anytype and comma
also zig fmt: space after top level doc comment
This commit is contained in:
parent
08107a555e
commit
988f1c6a6f
@ -3706,7 +3706,12 @@ const Parser = struct {
|
||||
const param = try p.expectParamDecl();
|
||||
if (param != 0) break param;
|
||||
switch (p.token_tags[p.nextToken()]) {
|
||||
.comma => continue,
|
||||
.comma => {
|
||||
if (p.eatToken(.r_paren)) |_| {
|
||||
return SmallSpan{ .zero_or_one = 0 };
|
||||
}
|
||||
continue;
|
||||
},
|
||||
.r_paren => return SmallSpan{ .zero_or_one = 0 },
|
||||
else => {
|
||||
// This is likely just a missing comma;
|
||||
|
||||
@ -4134,6 +4134,24 @@ test "zig fmt: function params should align nicely" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: fn proto end with anytype and comma" {
|
||||
try testCanonical(
|
||||
\\pub fn format(
|
||||
\\ out_stream: anytype,
|
||||
\\) !void {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: space after top level doc comment" {
|
||||
try testCanonical(
|
||||
\\//! top level doc comment
|
||||
\\
|
||||
\\field: i32,
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: error for invalid bit range" {
|
||||
try testError(
|
||||
\\var x: []align(0:0:0)u8 = bar;
|
||||
|
||||
@ -1449,6 +1449,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.
|
||||
.identifier => {},
|
||||
.keyword_anytype => {
|
||||
try renderToken(ais, tree, last_param_token, .comma); // anytype
|
||||
if (token_tags[last_param_token + 1] == .comma)
|
||||
last_param_token += 1;
|
||||
continue;
|
||||
},
|
||||
.r_paren => break,
|
||||
@ -1462,6 +1464,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.
|
||||
}
|
||||
if (token_tags[last_param_token] == .keyword_anytype) {
|
||||
try renderToken(ais, tree, last_param_token, .comma); // anytype
|
||||
if (token_tags[last_param_token + 1] == .comma)
|
||||
last_param_token += 1;
|
||||
continue;
|
||||
}
|
||||
const param = fn_proto.ast.params[param_i];
|
||||
@ -2363,6 +2367,12 @@ fn renderContainerDocComments(ais: *Ais, tree: ast.Tree, start_token: ast.TokenI
|
||||
while (token_tags[tok] == .container_doc_comment) : (tok += 1) {
|
||||
try renderToken(ais, tree, tok, .newline);
|
||||
}
|
||||
// Render extra newline if there is one between final container doc comment and
|
||||
// the next token. If the next token is a doc comment, that code path
|
||||
// will have its own logic to insert a newline.
|
||||
if (token_tags[tok] != .doc_comment) {
|
||||
try renderExtraNewlineToken(ais, tree, tok);
|
||||
}
|
||||
}
|
||||
|
||||
fn tokenSliceForRender(tree: ast.Tree, token_index: ast.TokenIndex) []const u8 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user