fmt: fix first line comment indent in struct init

This commit is contained in:
Shritesh Bhattarai 2019-03-31 21:28:28 -05:00 committed by Andrew Kelley
parent 0563e8e1d4
commit d645500883
2 changed files with 16 additions and 3 deletions

View File

@ -1027,6 +1027,19 @@ test "zig fmt: line comments in struct initializer" {
);
}
test "zig fmt: first line comment in struct initializer" {
try testCanonical(
\\pub async fn acquire(self: *Self) HeldLock {
\\ return HeldLock{
\\ // TODO guaranteed allocation elision
\\ .held = await (async self.lock.acquire() catch unreachable),
\\ .value = &self.private_data,
\\ };
\\}
\\
);
}
test "zig fmt: doc comments before struct field" {
try testCanonical(
\\pub const Allocator = struct {

View File

@ -658,11 +658,11 @@ fn renderExpression(
return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
}
try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
try renderToken(tree, stream, lbrace, indent, start_col, Space.Newline);
const new_indent = indent + indent_delta;
try renderExpression(allocator, stream, tree, new_indent, start_col, suffix_op.lhs, Space.None);
try renderToken(tree, stream, lbrace, new_indent, start_col, Space.Newline);
var it = field_inits.iterator(0);
while (it.next()) |field_init| {
try stream.writeByteNTimes(' ', new_indent);