From 571123465b2e030b7b9cf42732ed30f77192fbcd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 5 Oct 2019 18:01:01 -0400 Subject: generated docs: canonical package paths --- lib/std/special/doc/main.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'lib/std') diff --git a/lib/std/special/doc/main.js b/lib/std/special/doc/main.js index e0f4d210be..50002f6841 100644 --- a/lib/std/special/doc/main.js +++ b/lib/std/special/doc/main.js @@ -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; + } })(); -- cgit v1.2.3