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