authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-03-22 17:31:02-04:00
committergravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-03-25 17:30:51-04:00
logc818a1e61f702e1990af3e0773b3954d0e29d0ca
treef49bb16b26a111842472d9b89c9062f89e8b275c
parented3ca0f570e052adbed291a79e9a11bba5d3f7d0

zig fmt: handle `skip` space for multiline strings


2 files changed, 19 insertions(+), 1 deletions(-)

lib/std/zig/Ast/Render.zig+8-1
......@@ -338,9 +338,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
338338 try ais.maybeInsertNewline();
339339
340340 const first_tok, const last_tok = tree.nodeData(node).token_and_token;
341 for (first_tok..last_tok + 1) |i| {
341 for (first_tok..last_tok) |i| {
342342 try renderToken(r, @intCast(i), .newline);
343343 }
344 if (space != .skip) {
345 try renderToken(r, last_tok, .newline);
346 } else {
347 try renderToken(r, last_tok, .skip);
348 try ais.insertNewline(); // A newline is part of the token, so it still needs
349 // rendered here.
350 }
344351
345352 const next_token = last_tok + 1;
346353 const next_token_tag = tree.tokenTag(next_token);
lib/std/zig/parser_test.zig+11
......@@ -6881,6 +6881,17 @@ test "zig fmt: asm with zig fmt on" {
68816881 );
68826882}
68836883
6884test "zig fmt: array init with multiline string literal with fmt on/off" {
6885 try testCanonical(
6886 \\const array = .{
6887 \\ \\
6888 \\ // zig fmt: on
6889 \\ // zig fmt: off
6890 \\};
6891 \\
6892 );
6893}
6894
68846895test "recovery: top level" {
68856896 try testError(
68866897 \\test "" {inline}