mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
std.zig.render: fix newlines before DocComments
This commit is contained in:
parent
b717df786b
commit
de9933761c
@ -373,6 +373,35 @@ test "zig fmt: correctly move doc comments on struct fields" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: correctly space struct fields with doc comments" {
|
||||
try testTransform(
|
||||
\\pub const S = struct {
|
||||
\\ /// A
|
||||
\\ a: u8,
|
||||
\\ /// B
|
||||
\\ /// B (cont)
|
||||
\\ b: u8,
|
||||
\\
|
||||
\\
|
||||
\\ /// C
|
||||
\\ c: u8,
|
||||
\\};
|
||||
\\
|
||||
,
|
||||
\\pub const S = struct {
|
||||
\\ /// A
|
||||
\\ a: u8,
|
||||
\\ /// B
|
||||
\\ /// B (cont)
|
||||
\\ b: u8,
|
||||
\\
|
||||
\\ /// C
|
||||
\\ c: u8,
|
||||
\\};
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: doc comments on param decl" {
|
||||
try testCanonical(
|
||||
\\pub const Allocator = struct {
|
||||
|
||||
@ -187,12 +187,16 @@ fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *as
|
||||
const first_token = node.firstToken();
|
||||
var prev_token = first_token;
|
||||
if (prev_token == 0) return;
|
||||
var newline_threshold: usize = 2;
|
||||
while (tree.tokens.at(prev_token - 1).id == .DocComment) {
|
||||
if (tree.tokenLocation(tree.tokens.at(prev_token - 1).end, prev_token).line == 1) {
|
||||
newline_threshold += 1;
|
||||
}
|
||||
prev_token -= 1;
|
||||
}
|
||||
const prev_token_end = tree.tokens.at(prev_token - 1).end;
|
||||
const loc = tree.tokenLocation(prev_token_end, first_token);
|
||||
if (loc.line >= 2) {
|
||||
if (loc.line >= newline_threshold) {
|
||||
try stream.writeByte('\n');
|
||||
start_col.* = 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user