-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Title: Proposal: Add -fgen-api-json
flag to zig build docs
for machine-readable documentation output
Problem
The current zig build docs
command is invaluable for generating human-readable HTML documentation. However, the lack of a machine-readable output format creates a significant barrier for developers building modern tooling around Zig, such as:
- AI-powered coding assistants and chatbots
- Advanced IDE plugins and language servers
- Custom documentation browsers and search interfaces
- Automated code analysis and linting tools
These tools are currently forced to either:
- Scrape the generated HTML, which is fragile, inefficient, and breaks with styling changes.
- Re-parse the entire standard library source code using
std.zig.Ast
, duplicating the complex parsing work already performed by the documentation builder.
Proposed Solution
Add a new compiler flag, -fgen-api-json
, to the zig build docs
command. When enabled, this flag would direct the compiler to generate a comprehensive, machine-readable JSON representation of the API documentation alongside the traditional HTML output.
Suggested Flag Behavior:
zig build docs -fgen-api-json
: Generates a single, consolidatedstd-docs.json
file.zig build docs -fgen-api-json=per_module
: Generates a structured directory of JSON files (e.g.,std/array_list.json
,std/mem.json
) for finer-grained consumption.
Desired Output Format (Conceptual):
The JSON output should provide structured data for all public declarations. For example, a function could be represented as:
{
"name": "ArrayList.init",
"signature": "fn init(allocator: std.mem.Allocator) ArrayList(T)",
"documentation": "Creates a new ArrayList which will use the provided allocator for its internal memory.",
"file": "lib/std/array_list.zig",
"line": 123,
"type": "fn",
"parameters": [
{
"name": "allocator",
"type": "std.mem.Allocator"
}
],
"return_type": "ArrayList(T)"
}
The same structured approach would apply to structs, enums, types, and other constructs, capturing their names, fields, methods, and documentation.
Benefits
- Ecosystem Enablement: Dramatically lowers the barrier to creating high-quality, intelligent development tools that deeply understand the Zig standard library, fostering a richer ecosystem.
- Robustness & Stability: Tools can rely on a stable, structured data interface maintained by the Zig compiler itself, eliminating the need for fragile scraping techniques or re-implementing complex AST parsing logic.
- Performance: Building external tools and knowledge bases becomes a simple and efficient matter of parsing JSON, rather than processing heavy HTML or raw source code.
- Official Source of Truth: The generated data is guaranteed to be perfectly synchronized with the official HTML documentation and the compiler's own understanding of the APIs.
This feature would be a powerful investment in the Zig ecosystem, making it significantly easier to build the next generation of developer tools around the language.
Let me know your thoughts on this proposal.