| ... | ... | @@ -2352,18 +2352,24 @@ fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!boo |
| 2352 | 2352 | } |
| 2353 | 2353 | } |
| 2354 | 2354 | |
| 2355 | | try ais.writer().print("{s}\n", .{trimmed_comment}); |
| 2356 | | index = 1 + (newline orelse return true); |
| 2357 | | |
| 2358 | | if (ais.disabled_offset) |disabled_offset| { |
| 2359 | | if (mem.eql(u8, trimmed_comment, "// zig fmt: on")) { |
| 2360 | | // write the source for which formatting was disabled directly |
| 2361 | | // to the underlying writer, fixing up invaild whitespace |
| 2362 | | try writeFixingWhitespace(ais.underlying_writer, tree.source[disabled_offset..index]); |
| 2363 | | ais.disabled_offset = null; |
| 2364 | | } |
| 2365 | | } else if (mem.eql(u8, trimmed_comment, "// zig fmt: off")) { |
| 2355 | index = 1 + (newline orelse end - 1); |
| 2356 | |
| 2357 | const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.spaces); |
| 2358 | if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) { |
| 2359 | // Write the source for which formatting was disabled directly |
| 2360 | // to the underlying writer, fixing up invaild whitespace. |
| 2361 | const disabled_source = tree.source[ais.disabled_offset.?..comment_start]; |
| 2362 | try writeFixingWhitespace(ais.underlying_writer, disabled_source); |
| 2363 | ais.disabled_offset = null; |
| 2364 | // Write with the canonical single space. |
| 2365 | try ais.writer().writeAll("// zig fmt: on\n"); |
| 2366 | } else if (ais.disabled_offset == null and mem.eql(u8, comment_content, "zig fmt: off")) { |
| 2367 | // Write with the canonical single space. |
| 2368 | try ais.writer().writeAll("// zig fmt: off\n"); |
| 2366 | 2369 | ais.disabled_offset = index; |
| 2370 | } else { |
| 2371 | // Write the comment minus trailing whitespace. |
| 2372 | try ais.writer().print("{s}\n", .{trimmed_comment}); |
| 2367 | 2373 | } |
| 2368 | 2374 | } |
| 2369 | 2375 | |