Skip to content

Commit

Permalink
Autodoc: only group structs under "namespaces"
Browse files Browse the repository at this point in the history
The old heuristic of checking only for the number of fields has the
downside of classifying all opaque types, such as `std.c.FILE`, as
"namespaces" rather than "types".
  • Loading branch information
ianprime0509 committed Jul 5, 2024
1 parent b3afba8 commit c1bd9b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,12 @@
const member_category = wasm_exports.categorize_decl(member, 0);
switch (member_category) {
case CAT_namespace:
if (wasm_exports.decl_field_count(member) > 0) {
if (!wasm_exports.decl_is_struct(member) || wasm_exports.decl_field_count(member) > 0) {
typesList.push({original: original, member: member});
} else {
namespacesList.push({original: original, member: member});
}
continue member_loop;
case CAT_namespace:
namespacesList.push({original: original, member: member});
continue member_loop;
case CAT_global_variable:
varsList.push(member);
continue member_loop;
Expand Down
15 changes: 15 additions & 0 deletions lib/docs/wasm/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,21 @@ export fn decl_file_path(decl_index: Decl.Index) String {
return String.init(string_result.items);
}

export fn decl_is_struct(decl_index: Decl.Index) bool {
const decl = decl_index.get();
const ast = decl.file.get_ast();
switch (decl.categorize()) {
.namespace => |node| {
const node_tags = ast.nodes.items(.tag);
if (node_tags[node] == .root) return true;
const main_tokens = ast.nodes.items(.main_token);
const token_tags = ast.tokens.items(.tag);
return token_tags[main_tokens[node]] == .keyword_struct;
},
else => return false,
}
}

export fn decl_category_name(decl_index: Decl.Index) String {
const decl = decl_index.get();
const ast = decl.file.get_ast();
Expand Down

0 comments on commit c1bd9b0

Please sign in to comment.