generated docs: canonical package paths

This commit is contained in:
Andrew Kelley 2019-10-05 18:01:01 -04:00
parent 0e40fc46d1
commit 571123465b
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -15,6 +15,9 @@
var typeKindFnId;
findTypeKinds();
// for each package, is an array with packages to get to this one
var canonPkgPaths = computeCanonicalPackagePaths();
var curNav = {
// each element is a package name, e.g. @import("a") then within there @import("b")
// starting implicitly from root package
@ -180,7 +183,7 @@
var liDom = domListPkgs.children[i];
var aDom = liDom.children[0];
aDom.textContent = list[i].name;
aDom.setAttribute('href', navLinkPkg(list[i].name));
aDom.setAttribute('href', navLinkPkg(list[i].pkg));
}
domSectPkgs.classList.remove("hidden");
@ -197,8 +200,8 @@
}
}
function navLinkPkg(childName) {
return navLink(curNav.pkgNames.concat([childName]), []);
function navLinkPkg(pkgIndex) {
return navLink(canonPkgPaths[pkgIndex], []);
}
function navLinkDecl(childName) {
@ -349,4 +352,31 @@
}
return null;
}
function computeCanonicalPackagePaths() {
var list = new Array(zigAnalysis.packages.length);
// Now we try to find all the packages from root.
var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
// Breadth-first to keep the path shortest possible.
var stack = [{
path: [],
pkg: rootPkg,
}];
while (stack.length !== 0) {
var item = stack.pop();
for (var key in item.pkg.table) {
var childPkgIndex = item.pkg.table[key];
if (list[childPkgIndex] != null) continue;
var newPath = item.path.concat([key])
list[childPkgIndex] = newPath;
var childPkg = zigAnalysis.packages[childPkgIndex];
stack.push({
path: newPath,
pkg: childPkg,
});
}
}
return list;
}
})();