| ... | ... | @@ -7,6 +7,7 @@ const Compilation = @import("Compilation.zig"); |
| 7 | 7 | const Module = @import("Module.zig"); |
| 8 | 8 | const File = Module.File; |
| 9 | 9 | const Package = @import("Package.zig"); |
| 10 | const Tokenizer = std.zig.Tokenizer; |
| 10 | 11 | const Zir = @import("Zir.zig"); |
| 11 | 12 | const Ref = Zir.Inst.Ref; |
| 12 | 13 | const log = std.log.scoped(.autodoc); |
| ... | ... | @@ -214,8 +215,13 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 214 | 215 | .enclosing_type = main_type_index, |
| 215 | 216 | }; |
| 216 | 217 | |
| 217 | | try self.ast_nodes.append(self.arena, .{ .name = "(root)" }); |
| 218 | const maybe_tldoc_comment = try self.getTLDocComment(file); |
| 219 | try self.ast_nodes.append(self.arena, .{ |
| 220 | .name = "(root)", |
| 221 | .docs = maybe_tldoc_comment, |
| 222 | }); |
| 218 | 223 | try self.files.put(self.arena, file, main_type_index); |
| 224 | |
| 219 | 225 | _ = try self.walkInstruction(file, &root_scope, .{}, Zir.main_struct_inst, false); |
| 220 | 226 | |
| 221 | 227 | if (self.ref_paths_pending_on_decls.count() > 0) { |
| ... | ... | @@ -247,21 +253,14 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 247 | 253 | .comptimeExprs = self.comptime_exprs.items, |
| 248 | 254 | }; |
| 249 | 255 | |
| 250 | | if (self.doc_location.directory) |d| { |
| 251 | | d.handle.makeDir( |
| 252 | | self.doc_location.basename, |
| 253 | | ) catch |e| switch (e) { |
| 254 | | error.PathAlreadyExists => {}, |
| 255 | | else => |err| return err, |
| 256 | | }; |
| 257 | | } else { |
| 258 | | self.module.zig_cache_artifact_directory.handle.makeDir( |
| 259 | | self.doc_location.basename, |
| 260 | | ) catch |e| switch (e) { |
| 261 | | error.PathAlreadyExists => {}, |
| 262 | | else => |err| return err, |
| 263 | | }; |
| 264 | | } |
| 256 | const base_dir = self.doc_location.directory orelse |
| 257 | self.module.zig_cache_artifact_directory; |
| 258 | |
| 259 | base_dir.handle.makeDir(self.doc_location.basename) catch |e| switch (e) { |
| 260 | error.PathAlreadyExists => {}, |
| 261 | else => |err| return err, |
| 262 | }; |
| 263 | |
| 265 | 264 | const output_dir = if (self.doc_location.directory) |d| |
| 266 | 265 | try d.handle.openDir(self.doc_location.basename, .{}) |
| 267 | 266 | else |
| ... | ... | @@ -914,7 +913,11 @@ fn walkInstruction( |
| 914 | 913 | .parent = null, |
| 915 | 914 | .enclosing_type = main_type_index, |
| 916 | 915 | }; |
| 917 | | try self.ast_nodes.append(self.arena, .{ .name = "(root)" }); |
| 916 | const maybe_tldoc_comment = try self.getTLDocComment(file); |
| 917 | try self.ast_nodes.append(self.arena, .{ |
| 918 | .name = "(root)", |
| 919 | .docs = maybe_tldoc_comment, |
| 920 | }); |
| 918 | 921 | try self.files.put(self.arena, new_file, main_type_index); |
| 919 | 922 | return self.walkInstruction( |
| 920 | 923 | new_file, |
| ... | ... | @@ -4412,3 +4415,15 @@ fn declIsVar( |
| 4412 | 4415 | // tags[tok_idx] is the token called 'mut token' in AstGen |
| 4413 | 4416 | return (tags[tok_idx] == .keyword_var); |
| 4414 | 4417 | } |
| 4418 | |
| 4419 | fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 { |
| 4420 | const source = (try file.getSource(self.module.gpa)).bytes; |
| 4421 | var tokenizer = Tokenizer.init(source); |
| 4422 | var tok = tokenizer.next(); |
| 4423 | var comment = std.ArrayList(u8).init(self.arena); |
| 4424 | while (tok.tag == .container_doc_comment) : (tok = tokenizer.next()) { |
| 4425 | try comment.appendSlice(source[tok.loc.start + 3 .. tok.loc.end + 1]); |
| 4426 | } |
| 4427 | |
| 4428 | return comment.items; |
| 4429 | } |