authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-05 18:01:01-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-05 18:01:01-04:00
log571123465b2e030b7b9cf42732ed30f77192fbcd
tree5243744124d7c7dfd327da36dbb437f1e2f692a1
parent0e40fc46d1e96a96f9cb751ef4a47bf1d4df215b
signaturelock-open Commit is signed but in an unrecognized format.

generated docs: canonical package paths


1 files changed, 33 insertions(+), 3 deletions(-)

lib/std/special/doc/main.js+33-3
......@@ -15,6 +15,9 @@
1515 var typeKindFnId;
1616 findTypeKinds();
1717
18 // for each package, is an array with packages to get to this one
19 var canonPkgPaths = computeCanonicalPackagePaths();
20
1821 var curNav = {
1922 // each element is a package name, e.g. @import("a") then within there @import("b")
2023 // starting implicitly from root package
......@@ -180,7 +183,7 @@
180183 var liDom = domListPkgs.children[i];
181184 var aDom = liDom.children[0];
182185 aDom.textContent = list[i].name;
183 aDom.setAttribute('href', navLinkPkg(list[i].name));
186 aDom.setAttribute('href', navLinkPkg(list[i].pkg));
184187 }
185188
186189 domSectPkgs.classList.remove("hidden");
......@@ -197,8 +200,8 @@
197200 }
198201 }
199202
200 function navLinkPkg(childName) {
201 return navLink(curNav.pkgNames.concat([childName]), []);
203 function navLinkPkg(pkgIndex) {
204 return navLink(canonPkgPaths[pkgIndex], []);
202205 }
203206
204207 function navLinkDecl(childName) {
......@@ -349,4 +352,31 @@
349352 }
350353 return null;
351354 }
355
356 function computeCanonicalPackagePaths() {
357 var list = new Array(zigAnalysis.packages.length);
358 // Now we try to find all the packages from root.
359 var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
360 // Breadth-first to keep the path shortest possible.
361 var stack = [{
362 path: [],
363 pkg: rootPkg,
364 }];
365 while (stack.length !== 0) {
366 var item = stack.pop();
367 for (var key in item.pkg.table) {
368 var childPkgIndex = item.pkg.table[key];
369 if (list[childPkgIndex] != null) continue;
370
371 var newPath = item.path.concat([key])
372 list[childPkgIndex] = newPath;
373 var childPkg = zigAnalysis.packages[childPkgIndex];
374 stack.push({
375 path: newPath,
376 pkg: childPkg,
377 });
378 }
379 }
380 return list;
381 }
352382})();