| ... | @@ -7,6 +7,7 @@ const Compilation = @import("Compilation.zig"); | ... | @@ -7,6 +7,7 @@ const Compilation = @import("Compilation.zig"); |
| 7 | const Module = @import("Module.zig"); | 7 | const Module = @import("Module.zig"); |
| 8 | const File = Module.File; | 8 | const File = Module.File; |
| 9 | const Package = @import("Package.zig"); | 9 | const Package = @import("Package.zig"); |
| | 10 | const Tokenizer = std.zig.Tokenizer; |
| 10 | const Zir = @import("Zir.zig"); | 11 | const Zir = @import("Zir.zig"); |
| 11 | const Ref = Zir.Inst.Ref; | 12 | const Ref = Zir.Inst.Ref; |
| 12 | const log = std.log.scoped(.autodoc); | 13 | const log = std.log.scoped(.autodoc); |
| ... | @@ -214,8 +215,13 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -214,8 +215,13 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 214 | .enclosing_type = main_type_index, | 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 | try self.files.put(self.arena, file, main_type_index); | 223 | try self.files.put(self.arena, file, main_type_index); |
| | 224 | |
| 219 | _ = try self.walkInstruction(file, &root_scope, .{}, Zir.main_struct_inst, false); | 225 | _ = try self.walkInstruction(file, &root_scope, .{}, Zir.main_struct_inst, false); |
| 220 | | 226 | |
| 221 | if (self.ref_paths_pending_on_decls.count() > 0) { | 227 | if (self.ref_paths_pending_on_decls.count() > 0) { |
| ... | @@ -247,21 +253,14 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -247,21 +253,14 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 247 | .comptimeExprs = self.comptime_exprs.items, | 253 | .comptimeExprs = self.comptime_exprs.items, |
| 248 | }; | 254 | }; |
| 249 | | 255 | |
| 250 | if (self.doc_location.directory) |d| { | 256 | const base_dir = self.doc_location.directory orelse |
| 251 | d.handle.makeDir( | 257 | self.module.zig_cache_artifact_directory; |
| 252 | self.doc_location.basename, | 258 | |
| 253 | ) catch |e| switch (e) { | 259 | base_dir.handle.makeDir(self.doc_location.basename) catch |e| switch (e) { |
| 254 | error.PathAlreadyExists => {}, | 260 | error.PathAlreadyExists => {}, |
| 255 | else => |err| return err, | 261 | else => |err| return err, |
| 256 | }; | 262 | }; |
| 257 | } else { | 263 | |
| 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 | } | | |
| 265 | const output_dir = if (self.doc_location.directory) |d| | 264 | const output_dir = if (self.doc_location.directory) |d| |
| 266 | try d.handle.openDir(self.doc_location.basename, .{}) | 265 | try d.handle.openDir(self.doc_location.basename, .{}) |
| 267 | else | 266 | else |
| ... | @@ -914,7 +913,11 @@ fn walkInstruction( | ... | @@ -914,7 +913,11 @@ fn walkInstruction( |
| 914 | .parent = null, | 913 | .parent = null, |
| 915 | .enclosing_type = main_type_index, | 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 | try self.files.put(self.arena, new_file, main_type_index); | 921 | try self.files.put(self.arena, new_file, main_type_index); |
| 919 | return self.walkInstruction( | 922 | return self.walkInstruction( |
| 920 | new_file, | 923 | new_file, |
| ... | @@ -4412,3 +4415,15 @@ fn declIsVar( | ... | @@ -4412,3 +4415,15 @@ fn declIsVar( |
| 4412 | // tags[tok_idx] is the token called 'mut token' in AstGen | 4415 | // tags[tok_idx] is the token called 'mut token' in AstGen |
| 4413 | return (tags[tok_idx] == .keyword_var); | 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 | } |