zig fmt: comments in field decls

This commit is contained in:
Andrew Kelley 2018-04-30 19:27:14 -04:00
parent 4cc1008c2d
commit 61a726c290
2 changed files with 15 additions and 1 deletions

View File

@ -3525,6 +3525,7 @@ pub const Parser = struct {
},
ast.Node.Id.StructField => {
const field = @fieldParentPtr(ast.Node.StructField, "base", decl);
try self.renderComments(stream, &field.base, indent);
if (field.visib_token) |visib_token| {
try stream.print("{} ", self.tokenizer.getTokenSlice(visib_token));
}
@ -3534,6 +3535,7 @@ pub const Parser = struct {
},
ast.Node.Id.UnionTag => {
const tag = @fieldParentPtr(ast.Node.UnionTag, "base", decl);
try self.renderComments(stream, &tag.base, indent);
try stream.print("{}", self.tokenizer.getTokenSlice(tag.name_token));
try stack.append(RenderState { .Text = "," });
@ -3550,6 +3552,7 @@ pub const Parser = struct {
},
ast.Node.Id.EnumTag => {
const tag = @fieldParentPtr(ast.Node.EnumTag, "base", decl);
try self.renderComments(stream, &tag.base, indent);
try stream.print("{}", self.tokenizer.getTokenSlice(tag.name_token));
try stack.append(RenderState { .Text = "," });

View File

@ -1,5 +1,16 @@
test "zig fmt: doc comments before struct field" {
try testCanonical(
\\pub const Allocator = struct {
\\ /// Allocate byte_count bytes and return them in a slice, with the
\\ /// slice's pointer aligned at least to alignment bytes.
\\ allocFn: fn() void,
\\};
\\
);
}
test "zig fmt: error set declaration" {
try testCanonical(
try testCanonical(
\\const E = error{
\\ A,
\\ B,