mirror of
https://github.com/ziglang/zig.git
synced 2026-02-17 14:59:14 +00:00
Merge pull request #12374 from vesim987/autodoc-links
autodoc: links to source code
This commit is contained in:
commit
6e794938b8
@ -51,8 +51,10 @@ var zigAnalysis;
|
||||
const domHdrName = document.getElementById("hdrName");
|
||||
const domHelpModal = document.getElementById("helpModal");
|
||||
const domSearchPlaceholder = document.getElementById("searchPlaceholder");
|
||||
const sourceFileUrlTemplate = "/src-viewer/{{file}}#L{{line}}"
|
||||
const domLangRefLink = document.getElementById("langRefLink");
|
||||
|
||||
let lineCounter = 1;
|
||||
let searchTimer = null;
|
||||
let searchTrimResults = true;
|
||||
|
||||
@ -411,6 +413,8 @@ var zigAnalysis;
|
||||
if (curNavSearch !== "") {
|
||||
return renderSearch();
|
||||
}
|
||||
|
||||
lineCounter = 1;
|
||||
|
||||
let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
|
||||
let pkg = rootPkg;
|
||||
@ -441,6 +445,10 @@ var zigAnalysis;
|
||||
}
|
||||
|
||||
currentType = childDecl;
|
||||
if ("src" in currentType) {
|
||||
const ast_node = zigAnalysis.astNodes[currentType.src];
|
||||
lineCounter += ast_node.line;
|
||||
}
|
||||
curNav.declObjs.push(currentType);
|
||||
}
|
||||
|
||||
@ -981,7 +989,7 @@ var zigAnalysis;
|
||||
"switch(" +
|
||||
cond +
|
||||
") {" +
|
||||
'<a href="https://github.com/ziglang/zig/tree/master/lib/std/' +
|
||||
'<a href="/src-viewer/' +
|
||||
file_name +
|
||||
"#L" +
|
||||
line +
|
||||
@ -2268,6 +2276,13 @@ var zigAnalysis;
|
||||
}
|
||||
}
|
||||
}
|
||||
function renderSourceFileLink(decl) {
|
||||
let srcNode = zigAnalysis.astNodes[decl.src];
|
||||
|
||||
return "<a style=\"float: right;\" href=\"" +
|
||||
sourceFileUrlTemplate.replace("{{file}}",
|
||||
zigAnalysis.files[srcNode.file]).replace("{{line}}", lineCounter + srcNode.line) + "\">[src]</a>";
|
||||
}
|
||||
|
||||
function renderContainer(container) {
|
||||
let typesList = [];
|
||||
@ -2386,13 +2401,12 @@ var zigAnalysis;
|
||||
|
||||
let declType = resolveValue(decl.value);
|
||||
console.assert("type" in declType.expr);
|
||||
|
||||
tdFnCode.innerHTML = exprName(declType.expr, {
|
||||
wantHtml: true,
|
||||
wantLink: true,
|
||||
fnDecl: decl,
|
||||
linkFnNameDecl: navLinkDecl(decl.name),
|
||||
});
|
||||
}) + renderSourceFileLink(decl);
|
||||
|
||||
let docs = zigAnalysis.astNodes[decl.src].docs;
|
||||
if (docs != null) {
|
||||
|
||||
@ -2824,8 +2824,8 @@ fn walkDecls(
|
||||
const ast_node_index = idx: {
|
||||
const idx = self.ast_nodes.items.len;
|
||||
try self.ast_nodes.append(self.arena, .{
|
||||
.file = 0,
|
||||
.line = line,
|
||||
.file = self.files.getIndex(file) orelse unreachable,
|
||||
.line = line, // TODO: calculate absolute line
|
||||
.col = 0,
|
||||
.docs = doc_comment,
|
||||
.fields = null, // walkInstruction will fill `fields` if necessary
|
||||
@ -3902,13 +3902,13 @@ fn cteTodo(self: *Autodoc, msg: []const u8) error{OutOfMemory}!DocData.WalkResul
|
||||
}
|
||||
|
||||
fn writeFileTableToJson(map: std.AutoArrayHashMapUnmanaged(*File, usize), jsw: anytype) !void {
|
||||
try jsw.beginObject();
|
||||
try jsw.beginArray();
|
||||
var it = map.iterator();
|
||||
while (it.next()) |entry| {
|
||||
try jsw.objectField(entry.key_ptr.*.sub_file_path);
|
||||
try jsw.emitNumber(entry.value_ptr.*);
|
||||
try jsw.arrayElem();
|
||||
try jsw.emitString(entry.key_ptr.*.sub_file_path);
|
||||
}
|
||||
try jsw.endObject();
|
||||
try jsw.endArray();
|
||||
}
|
||||
|
||||
fn writePackageTableToJson(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user