authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-23 23:01:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-23 23:01:16-07:00
logdb4c15be507a55f63b7f19dd4cdc10717f44eb06
treea8cb11233a939fb1f6187cbbdd60df43c08c1789
parentbf642204b373e01314ecfb0c50a643dc4b05746f

zig fmt: respect extra newline between fn and pub usingnamespace


2 files changed, 18 insertions(+), 12 deletions(-)

lib/std/zig/ast.zig+8-1
......@@ -321,7 +321,6 @@ pub const Tree = struct {
321321 while (true) switch (tags[n]) {
322322 .root => return 0,
323323
324 .@"usingnamespace",
325324 .test_decl,
326325 .@"errdefer",
327326 .@"defer",
......@@ -468,6 +467,14 @@ pub const Tree = struct {
468467 return i - end_offset;
469468 },
470469
470 .@"usingnamespace" => {
471 const main_token = main_tokens[n];
472 if (main_token > 0 and token_tags[main_token - 1] == .keyword_pub) {
473 end_offset += 1;
474 }
475 return main_token - end_offset;
476 },
477
471478 .async_call_one,
472479 .async_call_one_comma,
473480 .async_call,
lib/std/zig/parser_test.zig+10-11
......@@ -4178,17 +4178,16 @@ test "zig fmt: for loop with ptr payload and index" {
41784178// );
41794179//}
41804180
4181// TODO
4182//test "zig fmt: respect extra newline between fn and pub usingnamespace" {
4183// try testCanonical(
4184// \\fn foo() void {
4185// \\ bar();
4186// \\}
4187// \\
4188// \\pub usingnamespace baz;
4189// \\
4190// );
4191//}
4181test "zig fmt: respect extra newline between fn and pub usingnamespace" {
4182 try testCanonical(
4183 \\fn foo() void {
4184 \\ bar();
4185 \\}
4186 \\
4187 \\pub usingnamespace baz;
4188 \\
4189 );
4190}
41924191
41934192// TODO
41944193//test "zig fmt: respect extra newline between switch items" {