output: insert empty line between container members

unfortunately, this spits out double newlines between top level
declarations and sometimes in between fields. this is because the
original rendering logic designed to handle a complete source file,
whereas we're printing only public members.

but this makes reading the output of container fields easier.
will take care of double newlines later.
0.10
alex 2 years ago
parent dc51518b13
commit 3fa0f65b54

@ -9,6 +9,7 @@ const Ast = std.zig.Ast;
pub fn search(alloc: std.mem.Allocator, ais: *output.Ais, source: [:0]const u8, query: ?[]const u8) !void {
var tree = try std.zig.parse(alloc, source);
defer tree.deinit(alloc);
var insert_newline = false;
for (tree.rootDecls()) |decl| {
if (!isPublic(tree, decl)) {
continue;
@ -16,8 +17,11 @@ pub fn search(alloc: std.mem.Allocator, ais: *output.Ais, source: [:0]const u8,
if (query != null and !identifierMatch(tree, decl, query.?)) {
continue;
}
if (insert_newline) {
try ais.insertNewline();
}
try output.renderPubMember(alloc, ais, tree, decl, .newline);
try ais.insertNewline();
insert_newline = true;
}
}

@ -90,9 +90,7 @@ pub fn renderPubMember(gpa: Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Inde
try renderVarDecl(gpa, ais, tree, tree.simpleVarDecl(decl));
}
},
.container_field_init => {
try renderContainerField(gpa, ais, tree, tree.containerFieldInit(decl), space);
},
.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),
@ -2433,10 +2431,9 @@ fn renderDocComments(ais: *Ais, tree: Ast, end_token: Ast.TokenIndex) anyerror!v
// Prevent accidental use of `renderDocComments` for a function argument doc comment
assert(prev_token_tag != .l_paren);
// todo: restore original?
//if (prev_token_tag != .l_brace) {
// try renderExtraNewlineToken(ais, tree, first_tok);
//}
if (prev_token_tag != .l_brace) {
try renderExtraNewlineToken(ais, tree, first_tok);
}
}
while (token_tags[tok] == .doc_comment) : (tok += 1) {

Loading…
Cancel
Save