| ... | @@ -255,7 +255,7 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -255,7 +255,7 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 255 | | 255 | |
| 256 | var data = DocData{ | 256 | var data = DocData{ |
| 257 | .params = .{}, | 257 | .params = .{}, |
| 258 | .packages = self.packages.values(), | 258 | .packages = self.packages, |
| 259 | .files = self.files, | 259 | .files = self.files, |
| 260 | .calls = self.calls.items, | 260 | .calls = self.calls.items, |
| 261 | .types = self.types.items, | 261 | .types = self.types.items, |
| ... | @@ -313,9 +313,26 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -313,9 +313,26 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 313 | var files_iterator = self.files.iterator(); | 313 | var files_iterator = self.files.iterator(); |
| 314 | | 314 | |
| 315 | while (files_iterator.next()) |entry| { | 315 | while (files_iterator.next()) |entry| { |
| 316 | const new_html_path = try std.mem.concat(self.arena, u8, &.{ entry.key_ptr.*.sub_file_path, ".html" }); | 316 | const sub_file_path = entry.key_ptr.*.sub_file_path; |
| | 317 | const file_package = entry.key_ptr.*.pkg; |
| | 318 | const package_name = (self.packages.get(file_package) orelse continue).name; |
| 317 | | 319 | |
| 318 | const html_file = try createFromPath(html_dir, new_html_path); | 320 | const file_path = std.fs.path.dirname(sub_file_path) orelse ""; |
| | 321 | const file_name = if (file_path.len > 0) sub_file_path[file_path.len + 1 ..] else sub_file_path; |
| | 322 | |
| | 323 | const html_file_name = try std.mem.concat(self.arena, u8, &.{ file_name, ".html" }); |
| | 324 | defer self.arena.free(html_file_name); |
| | 325 | |
| | 326 | const dir_name = try std.fs.path.join(self.arena, &.{ package_name, file_path }); |
| | 327 | defer self.arena.free(dir_name); |
| | 328 | |
| | 329 | var dir = try html_dir.makeOpenPath(dir_name, .{}); |
| | 330 | defer dir.close(); |
| | 331 | |
| | 332 | const html_file = dir.createFile(html_file_name, .{}) catch |err| switch (err) { |
| | 333 | error.PathAlreadyExists => try dir.openFile(html_file_name, .{}), |
| | 334 | else => return err, |
| | 335 | }; |
| 319 | defer html_file.close(); | 336 | defer html_file.close(); |
| 320 | var buffer = std.io.bufferedWriter(html_file.writer()); | 337 | var buffer = std.io.bufferedWriter(html_file.writer()); |
| 321 | | 338 | |
| ... | @@ -333,26 +350,6 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -333,26 +350,6 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 333 | try docs_dir.copyFile("index.html", output_dir, "index.html", .{}); | 350 | try docs_dir.copyFile("index.html", output_dir, "index.html", .{}); |
| 334 | } | 351 | } |
| 335 | | 352 | |
| 336 | fn createFromPath(base_dir: std.fs.Dir, path: []const u8) !std.fs.File { | | |
| 337 | var path_tokens = std.mem.tokenize(u8, path, std.fs.path.sep_str); | | |
| 338 | var dir = base_dir; | | |
| 339 | while (path_tokens.next()) |toc| { | | |
| 340 | if (path_tokens.peek() != null) { | | |
| 341 | dir.makeDir(toc) catch |e| switch (e) { | | |
| 342 | error.PathAlreadyExists => {}, | | |
| 343 | else => |err| return err, | | |
| 344 | }; | | |
| 345 | dir = try dir.openDir(toc, .{}); | | |
| 346 | } else { | | |
| 347 | return dir.createFile(toc, .{}) catch |e| switch (e) { | | |
| 348 | error.PathAlreadyExists => try dir.openFile(toc, .{}), | | |
| 349 | else => |err| return err, | | |
| 350 | }; | | |
| 351 | } | | |
| 352 | } | | |
| 353 | return error.EmptyPath; | | |
| 354 | } | | |
| 355 | | | |
| 356 | /// Represents a chain of scopes, used to resolve decl references to the | 353 | /// Represents a chain of scopes, used to resolve decl references to the |
| 357 | /// corresponding entry in `self.decls`. It also keeps track of whether | 354 | /// corresponding entry in `self.decls`. It also keeps track of whether |
| 358 | /// a given decl has been analyzed or not. | 355 | /// a given decl has been analyzed or not. |
| ... | @@ -417,7 +414,7 @@ const DocData = struct { | ... | @@ -417,7 +414,7 @@ const DocData = struct { |
| 417 | .{ .target = "arst" }, | 414 | .{ .target = "arst" }, |
| 418 | }, | 415 | }, |
| 419 | }, | 416 | }, |
| 420 | packages: []const DocPackage, | 417 | packages: std.AutoArrayHashMapUnmanaged(*Package, DocPackage), |
| 421 | errors: []struct {} = &.{}, | 418 | errors: []struct {} = &.{}, |
| 422 | | 419 | |
| 423 | // non-hardcoded stuff | 420 | // non-hardcoded stuff |
| ... | @@ -449,8 +446,12 @@ const DocData = struct { | ... | @@ -449,8 +446,12 @@ const DocData = struct { |
| 449 | const f_name = @tagName(f); | 446 | const f_name = @tagName(f); |
| 450 | try jsw.objectField(f_name); | 447 | try jsw.objectField(f_name); |
| 451 | switch (f) { | 448 | switch (f) { |
| 452 | .files => try writeFileTableToJson(self.files, &jsw), | 449 | .files => try writeFileTableToJson(self.files, self.packages, &jsw), |
| 453 | .guide_sections => try writeGuidesToJson(self.guide_sections, &jsw), | 450 | .guide_sections => try writeGuidesToJson(self.guide_sections, &jsw), |
| | 451 | .packages => { |
| | 452 | try std.json.stringify(self.packages.values(), opts, w); |
| | 453 | jsw.state_index -= 1; |
| | 454 | }, |
| 454 | else => { | 455 | else => { |
| 455 | try std.json.stringify(@field(self, f_name), opts, w); | 456 | try std.json.stringify(@field(self, f_name), opts, w); |
| 456 | jsw.state_index -= 1; | 457 | jsw.state_index -= 1; |
| ... | @@ -950,7 +951,7 @@ fn walkInstruction( | ... | @@ -950,7 +951,7 @@ fn walkInstruction( |
| 950 | .table = .{}, | 951 | .table = .{}, |
| 951 | }; | 952 | }; |
| 952 | | 953 | |
| 953 | // TODO: Add this package as a dependency to the current pakcage | 954 | // TODO: Add this package as a dependency to the current package |
| 954 | // TODO: this seems something that could be done in bulk | 955 | // TODO: this seems something that could be done in bulk |
| 955 | // at the beginning or the end, or something. | 956 | // at the beginning or the end, or something. |
| 956 | const root_src_dir = other_package.root_src_directory; | 957 | const root_src_dir = other_package.root_src_directory; |
| ... | @@ -4627,12 +4628,21 @@ fn cteTodo(self: *Autodoc, msg: []const u8) error{OutOfMemory}!DocData.WalkResul | ... | @@ -4627,12 +4628,21 @@ fn cteTodo(self: *Autodoc, msg: []const u8) error{OutOfMemory}!DocData.WalkResul |
| 4627 | return DocData.WalkResult{ .expr = .{ .comptimeExpr = cte_slot_index } }; | 4628 | return DocData.WalkResult{ .expr = .{ .comptimeExpr = cte_slot_index } }; |
| 4628 | } | 4629 | } |
| 4629 | | 4630 | |
| 4630 | fn writeFileTableToJson(map: std.AutoArrayHashMapUnmanaged(*File, usize), jsw: anytype) !void { | 4631 | fn writeFileTableToJson( |
| | 4632 | map: std.AutoArrayHashMapUnmanaged(*File, usize), |
| | 4633 | pkgs: std.AutoArrayHashMapUnmanaged(*Package, DocData.DocPackage), |
| | 4634 | jsw: anytype, |
| | 4635 | ) !void { |
| 4631 | try jsw.beginArray(); | 4636 | try jsw.beginArray(); |
| 4632 | var it = map.iterator(); | 4637 | var it = map.iterator(); |
| 4633 | while (it.next()) |entry| { | 4638 | while (it.next()) |entry| { |
| | 4639 | try jsw.arrayElem(); |
| | 4640 | try jsw.beginArray(); |
| 4634 | try jsw.arrayElem(); | 4641 | try jsw.arrayElem(); |
| 4635 | try jsw.emitString(entry.key_ptr.*.sub_file_path); | 4642 | try jsw.emitString(entry.key_ptr.*.sub_file_path); |
| | 4643 | try jsw.arrayElem(); |
| | 4644 | try jsw.emitNumber(pkgs.getIndex(entry.key_ptr.*.pkg) orelse 0); |
| | 4645 | try jsw.endArray(); |
| 4636 | } | 4646 | } |
| 4637 | try jsw.endArray(); | 4647 | try jsw.endArray(); |
| 4638 | } | 4648 | } |