mirror of
https://github.com/ziglang/zig.git
synced 2026-01-10 17:35:12 +00:00
autodoc: restore support for zig version + cleanup & init work to fix packages
This commit is contained in:
parent
20b861d805
commit
a5e7b0e4db
@ -527,15 +527,45 @@
|
||||
<div class="flex-left sidebar">
|
||||
<nav>
|
||||
<div class="logo">
|
||||
<svg version="1.1" viewBox="0 0 150 80" xmlns="http://www.w3.org/2000/svg">
|
||||
<g fill="#f7a41d">
|
||||
<path d="m0,-0.08899l0,80l19,0l6,-10l12,-10l-17,0l0,-40l15,0l0,-20l-35,0zm40,0l0,20l62,0l0,-20l-62,0zm91,0l-6,10l-12,10l17,0l0,40l-15,0l0,20l35,0l0,-80l-19,0zm-83,60l0,20l62,0l0,-20l-62,0z" shape-rendering="crispEdges"></path>
|
||||
<path d="m37,59.91101l-18,20l0,-15l18,-5z"></path>
|
||||
<path d="m113,19.91101l18,-20l0,15l-18,5z"></path>
|
||||
<path d="m96.98,0.54101l36.28,-10.4l-80.29,89.17l-36.28,10.4l80.29,-89.17z"></path>
|
||||
</g>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 140">
|
||||
<g fill="#F7A41D">
|
||||
<g>
|
||||
<polygon points="46,22 28,44 19,30"/>
|
||||
<polygon points="46,22 33,33 28,44 22,44 22,95 31,95 20,100 12,117 0,117 0,22" shape-rendering="crispEdges"/>
|
||||
<polygon points="31,95 12,117 4,106"/>
|
||||
</g>
|
||||
<g>
|
||||
<polygon points="56,22 62,36 37,44"/>
|
||||
<polygon points="56,22 111,22 111,44 37,44 56,32" shape-rendering="crispEdges"/>
|
||||
<polygon points="116,95 97,117 90,104"/>
|
||||
<polygon points="116,95 100,104 97,117 42,117 42,95" shape-rendering="crispEdges"/>
|
||||
<polygon points="150,0 52,117 3,140 101,22"/>
|
||||
</g>
|
||||
<g>
|
||||
<polygon points="141,22 140,40 122,45"/>
|
||||
<polygon points="153,22 153,117 106,117 120,105 125,95 131,95 131,45 122,45 132,36 141,22" shape-rendering="crispEdges"/>
|
||||
<polygon points="125,95 130,110 106,117"/>
|
||||
</g>
|
||||
</g>
|
||||
<style>
|
||||
#text { fill: #121212 }
|
||||
@media (prefers-color-scheme: dark) { #text { fill: #f2f2f2 } }
|
||||
</style>
|
||||
<g id="text">
|
||||
<g>
|
||||
<polygon points="260,22 260,37 229,40 177,40 177,22" shape-rendering="crispEdges"/>
|
||||
<polygon points="260,37 207,99 207,103 176,103 229,40 229,37"/>
|
||||
<polygon points="261,99 261,117 176,117 176,103 206,99" shape-rendering="crispEdges"/>
|
||||
</g>
|
||||
<rect x="272" y="22" shape-rendering="crispEdges" width="22" height="95"/>
|
||||
<g>
|
||||
<polygon points="394,67 394,106 376,106 376,81 360,70 346,67" shape-rendering="crispEdges"/>
|
||||
<polygon points="360,68 376,81 346,67"/>
|
||||
<path d="M394,106c-10.2,7.3-24,12-37.7,12c-29,0-51.1-20.8-51.1-48.3c0-27.3,22.5-48.1,52-48.1 c14.3,0,29.2,5.5,38.9,14l-13,15c-7.1-6.3-16.8-10-25.9-10c-17,0-30.2,12.9-30.2,29.5c0,16.8,13.3,29.6,30.3,29.6 c5.7,0,12.8-2.3,19-5.5L394,106z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
<div id="sectMainPkg" class="hidden">
|
||||
<h2><span>Main Package</span></h2>
|
||||
<ul class="packages">
|
||||
@ -549,11 +579,10 @@
|
||||
<div id="sectInfo" class="hidden">
|
||||
<h2><span>Zig Version</span></h2>
|
||||
<p class="str" id="tdZigVer"></p>
|
||||
<h2><span>Target</span></h2>
|
||||
<p class="str" id="tdTarget"></p>
|
||||
</div>
|
||||
<div>
|
||||
<input id="privDeclsBox" type="checkbox"/> Internal Documentation Mode
|
||||
<input id="privDeclsBox" type="checkbox"/>
|
||||
Internal Doc Mode
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@ -937,6 +937,7 @@ var zigAnalysis;
|
||||
for (let key in rootPkg.table) {
|
||||
let pkgIndex = rootPkg.table[key];
|
||||
if (zigAnalysis.packages[pkgIndex] == null) continue;
|
||||
if (key == zigAnalysis.params.rootName) continue;
|
||||
list.push({
|
||||
name: key,
|
||||
pkg: pkgIndex,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const build_options = @import("build_options");
|
||||
const Autodoc = @This();
|
||||
const Compilation = @import("Compilation.zig");
|
||||
const Module = @import("Module.zig");
|
||||
@ -13,6 +14,7 @@ arena: std.mem.Allocator,
|
||||
// The goal of autodoc is to fill up these arrays
|
||||
// that will then be serialized as JSON and consumed
|
||||
// by the JS frontend.
|
||||
pkgs: std.ArrayListUnmanaged(DocData.Package) = .{},
|
||||
files: std.AutoHashMapUnmanaged(*File, usize) = .{},
|
||||
calls: std.ArrayListUnmanaged(DocData.Call) = .{},
|
||||
types: std.ArrayListUnmanaged(DocData.Type) = .{},
|
||||
@ -169,8 +171,28 @@ pub fn generateZirData(self: *Autodoc) !void {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const main_type_index = self.types.items.len;
|
||||
const rootName = blk: {
|
||||
const rootName = std.fs.path.basename(self.module.main_pkg.root_src_path);
|
||||
break :blk rootName[0..rootName.len - 4];
|
||||
};
|
||||
|
||||
try self.pkgs.append(self.arena, .{
|
||||
.name = rootName,
|
||||
.table = .{.data = std.StringHashMapUnmanaged(usize){}},
|
||||
});
|
||||
|
||||
|
||||
{
|
||||
const rootPkg: *DocData.Package = &self.pkgs.items[0];
|
||||
try rootPkg.table.data.put(self.arena, rootName, 0);
|
||||
|
||||
rootPkg.main = main_type_index;
|
||||
rootPkg.name = rootName;
|
||||
}
|
||||
var root_scope = Scope{ .parent = null, .enclosing_type = main_type_index };
|
||||
try self.ast_nodes.append(self.arena, .{ .name = "(root)" });
|
||||
try self.files.put(self.arena, file, main_type_index);
|
||||
@ -187,8 +209,12 @@ pub fn generateZirData(self: *Autodoc) !void {
|
||||
if (self.pending_ref_paths.count() > 0) {
|
||||
@panic("some decl paths were never fully analized");
|
||||
}
|
||||
|
||||
|
||||
|
||||
var data = DocData{
|
||||
.params = .{ .rootName = rootName },
|
||||
.packages = self.pkgs.items,
|
||||
.files = .{ .data = self.files },
|
||||
.calls = self.calls.items,
|
||||
.types = self.types.items,
|
||||
@ -198,7 +224,7 @@ pub fn generateZirData(self: *Autodoc) !void {
|
||||
.comptimeExprs = self.comptime_exprs.items,
|
||||
};
|
||||
|
||||
data.packages[0].main = main_type_index;
|
||||
|
||||
|
||||
if (self.doc_location.directory) |d| {
|
||||
d.handle.makeDir(
|
||||
@ -282,14 +308,14 @@ const DocData = struct {
|
||||
rootPkg: u32 = 0,
|
||||
params: struct {
|
||||
zigId: []const u8 = "arst",
|
||||
zigVersion: []const u8 = "arst",
|
||||
zigVersion: []const u8 = build_options.version,
|
||||
target: []const u8 = "arst",
|
||||
rootName: []const u8 = "arst",
|
||||
rootName: []const u8,
|
||||
builds: []const struct { target: []const u8 } = &.{
|
||||
.{ .target = "arst" },
|
||||
},
|
||||
} = .{},
|
||||
packages: [1]Package = .{.{}},
|
||||
},
|
||||
packages: []const Package,
|
||||
errors: []struct {} = &.{},
|
||||
|
||||
// non-hardcoded stuff
|
||||
@ -378,12 +404,52 @@ const DocData = struct {
|
||||
code: []const u8,
|
||||
};
|
||||
const Package = struct {
|
||||
name: []const u8 = "root",
|
||||
name: []const u8 = "(root)",
|
||||
file: usize = 0, // index into `files`
|
||||
main: usize = 0, // index into `decls`
|
||||
table: struct { root: usize } = .{
|
||||
.root = 0,
|
||||
},
|
||||
table: struct {
|
||||
// this struct is a temporary hack to support json serialization
|
||||
data: std.StringHashMapUnmanaged(usize),
|
||||
pub fn jsonStringify(
|
||||
self: @This(),
|
||||
opt: std.json.StringifyOptions,
|
||||
w: anytype,
|
||||
) !void {
|
||||
var idx: usize = 0;
|
||||
var it = self.data.iterator();
|
||||
try w.writeAll("{\n");
|
||||
|
||||
var options = opt;
|
||||
if (options.whitespace) |*ws| ws.indent_level += 1;
|
||||
while (it.next()) |kv| : (idx += 1) {
|
||||
if (options.whitespace) |ws| try ws.outputIndent(w);
|
||||
const builtin = @import("builtin");
|
||||
if (builtin.target.os.tag == .windows) {
|
||||
try w.print("\"", .{});
|
||||
for (kv.key_ptr.*) |c| {
|
||||
if (c == '\\') {
|
||||
try w.print("\\\\", .{});
|
||||
} else {
|
||||
try w.print("{c}", .{c});
|
||||
}
|
||||
}
|
||||
try w.print("\"", .{});
|
||||
try w.print(": {d}", .{
|
||||
kv.value_ptr.*,
|
||||
});
|
||||
} else {
|
||||
try w.print("\"{s}\": {d}", .{
|
||||
kv.key_ptr.*,
|
||||
kv.value_ptr.*,
|
||||
});
|
||||
}
|
||||
if (idx != self.data.count() - 1) try w.writeByte(',');
|
||||
try w.writeByte('\n');
|
||||
}
|
||||
if (opt.whitespace) |ws| try ws.outputIndent(w);
|
||||
try w.writeAll("}");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const Decl = struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user