aboutsummaryrefslogtreecommitdiff
path: root/src/target.cpp
diff options
context:
space:
mode:
authoryvt <i@yvt.jp>2019-08-28 15:35:49 +0900
committerAndrew Kelley <andrew@ziglang.org>2019-08-28 11:57:01 -0400
commitc98f792ff8ed7af0d5e427836600c2ed7b30965e (patch)
tree5de21dd53c87442e41e5734d065101ec64dc3f2f /src/target.cpp
parent7139eef4cfc7c75655f9951849a994b116e96abe (diff)
downloadzig-c98f792ff8ed7af0d5e427836600c2ed7b30965e.tar.gz
zig-c98f792ff8ed7af0d5e427836600c2ed7b30965e.zip
Improve the handling of `zig fmt: off/on`
This commit reworks the handling of `zig fmt: off/on`. A motivating example is shown below: const c = d; // zig fmt: off // comment const a = b; // zig fmt: on Before processing the decl `const a = b;`, `renderRoot` looks for `zig fmt: off` that appears between this decl and the previous one. If it finds one, it searches for the next `zig fmt: on` that re-enables reformatting (or EOF if none was found), and copies the input code between `zig fmt: off` and `zig fmt: on` to the output stream. After that, it proceeds to the next decl. The important thing to notice here is that `renderTopLevelDecl` emits line comment tokens that follow the decl. Therefore, when copying code, we must be careful not to copy the line comment tokens that already have been written to the output stream. The original code failed to take this fact into consideration. It did skip `// zig fmt: off`, but not the remaining ones. As a result, when the above example is fed as input, it duplicated the line `// comment`.
Diffstat (limited to 'src/target.cpp')
0 files changed, 0 insertions, 0 deletions