zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c818a1e61f702e1990af3e0773b3954d0e29d0ca (tree)
parent ed3ca0f570e052adbed291a79e9a11bba5d3f7d0
Author: Kendall Condon <goon.pri.low@gmail.com>
Date:   Sun, 22 Mar 2026 17:31:02 -0400

zig fmt: handle `skip` space for multiline strings

Diffstat:
Mlib/std/zig/Ast/Render.zig | 9++++++++-
Mlib/std/zig/parser_test.zig | 11+++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/std/zig/Ast/Render.zig b/lib/std/zig/Ast/Render.zig @@ -338,9 +338,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { try ais.maybeInsertNewline(); const first_tok, const last_tok = tree.nodeData(node).token_and_token; - for (first_tok..last_tok + 1) |i| { + for (first_tok..last_tok) |i| { try renderToken(r, @intCast(i), .newline); } + if (space != .skip) { + try renderToken(r, last_tok, .newline); + } else { + try renderToken(r, last_tok, .skip); + try ais.insertNewline(); // A newline is part of the token, so it still needs + // rendered here. + } const next_token = last_tok + 1; const next_token_tag = tree.tokenTag(next_token); diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig @@ -6881,6 +6881,17 @@ test "zig fmt: asm with zig fmt on" { ); } +test "zig fmt: array init with multiline string literal with fmt on/off" { + try testCanonical( + \\const array = .{ + \\ \\ + \\ // zig fmt: on + \\ // zig fmt: off + \\}; + \\ + ); +} + test "recovery: top level" { try testError( \\test "" {inline}