output: render top level doc comments

those at the beginning of each file, prefixed with "//!".
0.10
alex 2 years ago
parent 1359c9ecb1
commit 62ab3da52d

@ -15,6 +15,9 @@ pub const Query = union(enum) {
pub fn search(alloc: std.mem.Allocator, ais: *output.Ais, source: [:0]const u8, query: ?Query) !void {
var tree = try std.zig.parse(alloc, source);
defer tree.deinit(alloc);
try output.renderTopLevelDocComments(ais, tree);
var insert_newline = false;
for (tree.rootDecls()) |decl| {
if (!isPublic(tree, decl)) {

@ -21,6 +21,15 @@ pub const indent_delta = 4;
/// Ais is writer type-independent AutoIndentingStream used by all renderXxx funcs.
pub const Ais = AutoIndentingStream(TypeErasedWriter.Writer);
// outputs all the line comments at the beginning of the tree.
pub fn renderTopLevelDocComments(ais: *Ais, tree: Ast) !void {
const comment_end_loc = tree.tokens.items(.start)[0];
_ = try renderComments(ais, tree, 0, comment_end_loc);
if (tree.tokens.items(.tag)[0] == .container_doc_comment) {
try renderContainerDocComments(ais, tree, 0);
}
}
/// renderPubMember prints the given declaration using ais.
/// it outputs anything only if the declaration is public.
pub fn renderPubMember(gpa: Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Index, space: Space) !void {

Loading…
Cancel
Save