output: print doc comments for all container fields and var decl

this was a big omission from when adapting the original
std/zig/render.zig: renderDocComments was a the very top which i
completely forgot about.

with it, double newlines are gone now, too.
0.10
alex 2 years ago
parent 802fda7cf7
commit e90e5eefbb

@ -24,7 +24,7 @@ pub fn search(alloc: std.mem.Allocator, ais: *output.Ais, source: [:0]const u8,
continue;
}
if (insert_newline) {
try ais.insertNewline();
try output.renderExtraNewline(ais, tree, decl);
}
try output.renderPubMember(alloc, ais, tree, decl, .newline);
insert_newline = true;

@ -76,23 +76,34 @@ pub fn renderPubMember(gpa: Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Inde
const mtok = main_tokens[decl];
// todo: move this to analyze.isPublic?
if (mtok > 0 and token_tags[mtok - 1] == .keyword_pub) {
try renderDocComments(ais, tree, tree.firstToken(decl));
try renderToken(ais, tree, mtok - 1, .space); // pub
try renderToken(ais, tree, mtok, .space); // usingnamespace
const expr = datas[decl].lhs;
try renderExpression(gpa, ais, tree, expr, .none);
return renderToken(ais, tree, tree.lastToken(expr) + 1, space); // ;
try renderToken(ais, tree, tree.lastToken(expr) + 1, space); // ;
}
},
//.global_var_decl => return renderVarDecl(gpa, ais, tree, tree.globalVarDecl(decl)),
.simple_var_decl => {
if (analyze.isPublic(tree, decl)) {
try renderDocComments(ais, tree, tree.firstToken(decl));
try renderVarDecl(gpa, ais, tree, tree.simpleVarDecl(decl));
}
},
.container_field_init => return renderContainerField(gpa, ais, tree, tree.containerFieldInit(decl), space),
.container_field_align => return renderContainerField(gpa, ais, tree, tree.containerFieldAlign(decl), space),
.container_field => return renderContainerField(gpa, ais, tree, tree.containerField(decl), space),
.container_field_init => {
try renderDocComments(ais, tree, tree.firstToken(decl));
try renderContainerField(gpa, ais, tree, tree.containerFieldInit(decl), space);
},
.container_field_align => {
try renderDocComments(ais, tree, tree.firstToken(decl));
try renderContainerField(gpa, ais, tree, tree.containerFieldAlign(decl), space);
},
.container_field => {
try renderDocComments(ais, tree, tree.firstToken(decl));
try renderContainerField(gpa, ais, tree, tree.containerField(decl), space);
},
.test_decl => return,
@ -2381,7 +2392,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) anyerror!bool
return index != start;
}
fn renderExtraNewline(ais: *Ais, tree: Ast, node: Ast.Node.Index) anyerror!void {
pub fn renderExtraNewline(ais: *Ais, tree: Ast, node: Ast.Node.Index) anyerror!void {
return renderExtraNewlineToken(ais, tree, tree.firstToken(node));
}

Loading…
Cancel
Save