| author | |
| committer | |
| log | a5e7b0e4dbc49bfd57d974296862cc19e9c71115 |
| tree | c4ec0c52097f803250d778332c4d7b371a6c4682 |
| parent | 20b861d805b6beea4f24f15e0ce314f8fa8d61d4 |
3 files changed, 117 insertions(+), 21 deletions(-)
lib/docs/index.html+40-11| ... | ... | @@ -527,15 +527,45 @@ |
| 527 | 527 | <div class="flex-left sidebar"> |
| 528 | 528 | <nav> |
| 529 | 529 | <div class="logo"> |
| 530 | <svg version="1.1" viewBox="0 0 150 80" xmlns="http://www.w3.org/2000/svg"> | |
| 531 | <g fill="#f7a41d"> | |
| 532 | <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> | |
| 533 | <path d="m37,59.91101l-18,20l0,-15l18,-5z"></path> | |
| 534 | <path d="m113,19.91101l18,-20l0,15l-18,5z"></path> | |
| 535 | <path d="m96.98,0.54101l36.28,-10.4l-80.29,89.17l-36.28,10.4l80.29,-89.17z"></path> | |
| 536 | </g> | |
| 530 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 140"> | |
| 531 | <g fill="#F7A41D"> | |
| 532 | 	<g> | |
| 533 | 		<polygon points="46,22 28,44 19,30"/> | |
| 534 | 		<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"/> | |
| 535 | 		<polygon points="31,95 12,117 4,106"/> | |
| 536 | 	</g> | |
| 537 | 	<g> | |
| 538 | 		<polygon points="56,22 62,36 37,44"/> | |
| 539 | 		<polygon points="56,22 111,22 111,44 37,44 56,32" shape-rendering="crispEdges"/> | |
| 540 | 		<polygon points="116,95 97,117 90,104"/> | |
| 541 | 		<polygon points="116,95 100,104 97,117 42,117 42,95" shape-rendering="crispEdges"/> | |
| 542 | 		<polygon points="150,0 52,117 3,140 101,22"/> | |
| 543 | 	</g> | |
| 544 | 	<g> | |
| 545 | 		<polygon points="141,22 140,40 122,45"/> | |
| 546 | 		<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"/> | |
| 547 | 		<polygon points="125,95 130,110 106,117"/> | |
| 548 | 	</g> | |
| 549 | </g> | |
| 550 | <style> | |
| 551 | #text { fill: #121212 } | |
| 552 | @media (prefers-color-scheme: dark) { #text { fill: #f2f2f2 } } | |
| 553 | </style> | |
| 554 | <g id="text"> | |
| 555 | 	<g> | |
| 556 | 		<polygon points="260,22 260,37 229,40 177,40 177,22" shape-rendering="crispEdges"/> | |
| 557 | 		<polygon points="260,37 207,99 207,103 176,103 229,40 229,37"/> | |
| 558 | 		<polygon points="261,99 261,117 176,117 176,103 206,99" shape-rendering="crispEdges"/> | |
| 559 | 	</g> | |
| 560 | 	<rect x="272" y="22" shape-rendering="crispEdges" width="22" height="95"/> | |
| 561 | 	<g> | |
| 562 | 		<polygon points="394,67 394,106 376,106 376,81 360,70 346,67" shape-rendering="crispEdges"/> | |
| 563 | 		<polygon points="360,68 376,81 346,67"/> | |
| 564 | 		<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"/> | |
| 565 | 	</g> | |
| 566 | </g> | |
| 537 | 567 | </svg> |
| 538 | </div> | |
| 568 | </div> | |
| 539 | 569 | <div id="sectMainPkg" class="hidden"> |
| 540 | 570 | <h2><span>Main Package</span></h2> |
| 541 | 571 | <ul class="packages"> |
| ... | ... | @@ -549,11 +579,10 @@ |
| 549 | 579 | <div id="sectInfo" class="hidden"> |
| 550 | 580 | <h2><span>Zig Version</span></h2> |
| 551 | 581 | <p class="str" id="tdZigVer"></p> |
| 552 | <h2><span>Target</span></h2> | |
| 553 | <p class="str" id="tdTarget"></p> | |
| 554 | 582 | </div> |
| 555 | 583 | 		 <div> |
| 556 | 			<input id="privDeclsBox" type="checkbox"/> Internal Documentation Mode | |
| 584 | 			 <input id="privDeclsBox" type="checkbox"/> | |
| 585 | Internal Doc Mode | |
| 557 | 586 | 		 </div> |
| 558 | 587 | </nav> |
| 559 | 588 | </div> |
lib/docs/main.js+1| ... | ... | @@ -937,6 +937,7 @@ var zigAnalysis; |
| 937 | 937 | for (let key in rootPkg.table) { |
| 938 | 938 | let pkgIndex = rootPkg.table[key]; |
| 939 | 939 | if (zigAnalysis.packages[pkgIndex] == null) continue; |
| 940 | if (key == zigAnalysis.params.rootName) continue; | |
| 940 | 941 | list.push({ |
| 941 | 942 | name: key, |
| 942 | 943 | pkg: pkgIndex, |
src/Autodoc.zig+76-10| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const build_options = @import("build_options"); | |
| 2 | 3 | const Autodoc = @This(); |
| 3 | 4 | const Compilation = @import("Compilation.zig"); |
| 4 | 5 | const Module = @import("Module.zig"); |
| ... | ... | @@ -13,6 +14,7 @@ arena: std.mem.Allocator, |
| 13 | 14 | // The goal of autodoc is to fill up these arrays |
| 14 | 15 | // that will then be serialized as JSON and consumed |
| 15 | 16 | // by the JS frontend. |
| 17 | pkgs: std.ArrayListUnmanaged(DocData.Package) = .{}, | |
| 16 | 18 | files: std.AutoHashMapUnmanaged(*File, usize) = .{}, |
| 17 | 19 | calls: std.ArrayListUnmanaged(DocData.Call) = .{}, |
| 18 | 20 | types: std.ArrayListUnmanaged(DocData.Type) = .{}, |
| ... | ... | @@ -169,8 +171,28 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 169 | 171 | ); |
| 170 | 172 | } |
| 171 | 173 | } |
| 172 | ||
| 174 | ||
| 175 | ||
| 176 | ||
| 173 | 177 | const main_type_index = self.types.items.len; |
| 178 | const rootName = blk: { | |
| 179 | const rootName = std.fs.path.basename(self.module.main_pkg.root_src_path); | |
| 180 | break :blk rootName[0..rootName.len - 4]; | |
| 181 | }; | |
| 182 | ||
| 183 | try self.pkgs.append(self.arena, .{ | |
| 184 | .name = rootName, | |
| 185 | .table = .{.data = std.StringHashMapUnmanaged(usize){}}, | |
| 186 | }); | |
| 187 | ||
| 188 | ||
| 189 | { | |
| 190 | const rootPkg: *DocData.Package = &self.pkgs.items[0]; | |
| 191 | try rootPkg.table.data.put(self.arena, rootName, 0); | |
| 192 | ||
| 193 | rootPkg.main = main_type_index; | |
| 194 | rootPkg.name = rootName; | |
| 195 | } | |
| 174 | 196 | var root_scope = Scope{ .parent = null, .enclosing_type = main_type_index }; |
| 175 | 197 | try self.ast_nodes.append(self.arena, .{ .name = "(root)" }); |
| 176 | 198 | try self.files.put(self.arena, file, main_type_index); |
| ... | ... | @@ -187,8 +209,12 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 187 | 209 | if (self.pending_ref_paths.count() > 0) { |
| 188 | 210 | @panic("some decl paths were never fully analized"); |
| 189 | 211 | } |
| 212 | ||
| 190 | 213 | |
| 214 | ||
| 191 | 215 | var data = DocData{ |
| 216 | .params = .{ .rootName = rootName }, | |
| 217 | .packages = self.pkgs.items, | |
| 192 | 218 | .files = .{ .data = self.files }, |
| 193 | 219 | .calls = self.calls.items, |
| 194 | 220 | .types = self.types.items, |
| ... | ... | @@ -198,7 +224,7 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 198 | 224 | .comptimeExprs = self.comptime_exprs.items, |
| 199 | 225 | }; |
| 200 | 226 | |
| 201 | data.packages[0].main = main_type_index; | |
| 227 | ||
| 202 | 228 | |
| 203 | 229 | if (self.doc_location.directory) |d| { |
| 204 | 230 | d.handle.makeDir( |
| ... | ... | @@ -282,14 +308,14 @@ const DocData = struct { |
| 282 | 308 | rootPkg: u32 = 0, |
| 283 | 309 | params: struct { |
| 284 | 310 | zigId: []const u8 = "arst", |
| 285 | zigVersion: []const u8 = "arst", | |
| 311 | zigVersion: []const u8 = build_options.version, | |
| 286 | 312 | target: []const u8 = "arst", |
| 287 | rootName: []const u8 = "arst", | |
| 313 | rootName: []const u8, | |
| 288 | 314 | builds: []const struct { target: []const u8 } = &.{ |
| 289 | 315 | .{ .target = "arst" }, |
| 290 | 316 | }, |
| 291 | } = .{}, | |
| 292 | packages: [1]Package = .{.{}}, | |
| 317 | }, | |
| 318 | packages: []const Package, | |
| 293 | 319 | errors: []struct {} = &.{}, |
| 294 | 320 | |
| 295 | 321 | // non-hardcoded stuff |
| ... | ... | @@ -378,12 +404,52 @@ const DocData = struct { |
| 378 | 404 | code: []const u8, |
| 379 | 405 | }; |
| 380 | 406 | const Package = struct { |
| 381 | name: []const u8 = "root", | |
| 407 | name: []const u8 = "(root)", | |
| 382 | 408 | file: usize = 0, // index into `files` |
| 383 | 409 | main: usize = 0, // index into `decls` |
| 384 | table: struct { root: usize } = .{ | |
| 385 | .root = 0, | |
| 386 | }, | |
| 410 | table: struct { | |
| 411 | // this struct is a temporary hack to support json serialization | |
| 412 | data: std.StringHashMapUnmanaged(usize), | |
| 413 | pub fn jsonStringify( | |
| 414 | self: @This(), | |
| 415 | opt: std.json.StringifyOptions, | |
| 416 | w: anytype, | |
| 417 | ) !void { | |
| 418 | var idx: usize = 0; | |
| 419 | var it = self.data.iterator(); | |
| 420 | try w.writeAll("{\n"); | |
| 421 | ||
| 422 | var options = opt; | |
| 423 | if (options.whitespace) |*ws| ws.indent_level += 1; | |
| 424 | while (it.next()) |kv| : (idx += 1) { | |
| 425 | if (options.whitespace) |ws| try ws.outputIndent(w); | |
| 426 | const builtin = @import("builtin"); | |
| 427 | if (builtin.target.os.tag == .windows) { | |
| 428 | try w.print("\"", .{}); | |
| 429 | for (kv.key_ptr.*) |c| { | |
| 430 | if (c == '\\') { | |
| 431 | try w.print("\\\\", .{}); | |
| 432 | } else { | |
| 433 | try w.print("{c}", .{c}); | |
| 434 | } | |
| 435 | } | |
| 436 | try w.print("\"", .{}); | |
| 437 | try w.print(": {d}", .{ | |
| 438 | kv.value_ptr.*, | |
| 439 | }); | |
| 440 | } else { | |
| 441 | try w.print("\"{s}\": {d}", .{ | |
| 442 | kv.key_ptr.*, | |
| 443 | kv.value_ptr.*, | |
| 444 | }); | |
| 445 | } | |
| 446 | if (idx != self.data.count() - 1) try w.writeByte(','); | |
| 447 | try w.writeByte('\n'); | |
| 448 | } | |
| 449 | if (opt.whitespace) |ws| try ws.outputIndent(w); | |
| 450 | try w.writeAll("}"); | |
| 451 | } | |
| 452 | }, | |
| 387 | 453 | }; |
| 388 | 454 | |
| 389 | 455 | const Decl = struct { |