diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2021-04-17 23:34:59 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-17 20:10:20 -0400 |
| commit | 4081e0a475670cf3c0301c795c67e1bc692024e1 (patch) | |
| tree | f992406e5315d31f6572223dcd0b09666bd61ad0 /lib/std | |
| parent | 8e6865c8eeff477375113f3c56f378d0e40ffecd (diff) | |
| download | zig-4081e0a475670cf3c0301c795c67e1bc692024e1.tar.gz zig-4081e0a475670cf3c0301c795c67e1bc692024e1.zip | |
zig fmt: bypass auto indentation for `// zig fmt: on`
Currently an indented `// zig fmt: on` will be indented an additional
time on every run of zig fmt.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/parser_test.zig | 21 | ||||
| -rw-r--r-- | lib/std/zig/render.zig | 4 |
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 1bed86f42d..c433ee5ad8 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -1315,6 +1315,27 @@ test "zig fmt: 'zig fmt: (off|on)' works in the middle of code" { ); } +test "zig fmt: 'zig fmt: on' indentation is unchanged" { + try testCanonical( + \\fn initOptionsAndLayouts(output: *Output, context: *Context) !void { + \\ // zig fmt: off + \\ try output.main_amount.init(output, "main_amount"); errdefer optput.main_amount.deinit(); + \\ try output.main_factor.init(output, "main_factor"); errdefer optput.main_factor.deinit(); + \\ try output.view_padding.init(output, "view_padding"); errdefer optput.view_padding.deinit(); + \\ try output.outer_padding.init(output, "outer_padding"); errdefer optput.outer_padding.deinit(); + \\ // zig fmt: on + \\ + \\ // zig fmt: off + \\ try output.top.init(output, .top); errdefer optput.top.deinit(); + \\ try output.right.init(output, .right); errdefer optput.right.deinit(); + \\ try output.bottom.init(output, .bottom); errdefer optput.bottom.deinit(); + \\ try output.left.init(output, .left); errdefer optput.left.deinit(); + \\ // zig fmt: on + \\} + \\ + ); +} + test "zig fmt: pointer of unknown length" { try testCanonical( \\fn foo(ptr: [*]u8) void {} diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 71d5e51bb9..9291f63e2f 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -2311,9 +2311,9 @@ fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!boo // to the underlying writer, fixing up invaild whitespace. const disabled_source = tree.source[ais.disabled_offset.?..comment_start]; try writeFixingWhitespace(ais.underlying_writer, disabled_source); - ais.disabled_offset = null; // Write with the canonical single space. - try ais.writer().writeAll("// zig fmt: on\n"); + try ais.underlying_writer.writeAll("// zig fmt: on\n"); + ais.disabled_offset = null; } else if (ais.disabled_offset == null and mem.eql(u8, comment_content, "zig fmt: off")) { // Write with the canonical single space. try ais.writer().writeAll("// zig fmt: off\n"); |
