Merge pull request #15414 from der-teufel-programming/autodoc-pkg-mod

autodoc: Change package to module to better reflect the new names
This commit is contained in:
Loris Cro 2023-04-25 20:24:40 +02:00 committed by GitHub
commit e0ee9d38cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 207 additions and 207 deletions

View File

@ -14,13 +14,13 @@
--bg-color: #ffffff;
--link-color: #2A6286;
--sidebar-sh-color: rgba(0, 0, 0, 0.09);
--sidebar-pkg-bg-color: #f1f1f1;
--sidebar-pkglnk-tx-color: #141414;
--sidebar-pkglnk-tx-color-hover: #fff;
--sidebar-pkglnk-tx-color-active: #000;
--sidebar-pkglnk-bg-color: transparent;
--sidebar-pkglnk-bg-color-hover: #555;
--sidebar-pkglnk-bg-color-active: #FFBB4D;
--sidebar-mod-bg-color: #f1f1f1;
--sidebar-modlnk-tx-color: #141414;
--sidebar-modlnk-tx-color-hover: #fff;
--sidebar-modlnk-tx-color-active: #000;
--sidebar-modlnk-bg-color: transparent;
--sidebar-modlnk-bg-color-hover: #555;
--sidebar-modlnk-bg-color-active: #FFBB4D;
--search-bg-color: #f3f3f3;
--search-bg-color-focus: #ffffff;
--search-sh-color: rgba(0, 0, 0, 0.18);
@ -130,8 +130,8 @@
.sidebar .guides-api-switch a {
display: block;
padding: 0.5rem 1rem;
color: var(--sidebar-pkglnk-tx-color);
background-color: var(--sidebar-pkglnk-bg-color);
color: var(--sidebar-modlnk-tx-color);
background-color: var(--sidebar-modlnk-bg-color);
border: 1px solid var(--tx-color);
}
@ -150,13 +150,13 @@
}
#ApiSwitch:hover:not(.active), #guideSwitch:hover:not(.active) {
color: var(--sidebar-pkglnk-tx-color-hover);
background-color: var(--sidebar-pkglnk-bg-color-hover);
color: var(--sidebar-modlnk-tx-color-hover);
background-color: var(--sidebar-modlnk-bg-color-hover);
}
.sidebar .guides-api-switch .active {
color: var(--sidebar-pkglnk-tx-color-active);
background-color: var(--sidebar-pkglnk-bg-color-active);
color: var(--sidebar-modlnk-tx-color-active);
background-color: var(--sidebar-modlnk-bg-color-active);
}
.sidebar h2 {
@ -169,29 +169,29 @@
border-bottom: 0.125rem dotted var(--tx-color);
}
.sidebar .packages {
.sidebar .modules {
list-style-type: none;
margin: 0;
padding: 0;
background-color: var(--sidebar-pkg-bg-color);
background-color: var(--sidebar-mod-bg-color);
}
.sidebar .packages > li > a {
.sidebar .modules > li > a {
display: block;
padding: 0.5rem 1rem;
color: var(--sidebar-pkglnk-tx-color);
background-color: var(--sidebar-pkglnk-bg-color);
color: var(--sidebar-modlnk-tx-color);
background-color: var(--sidebar-modlnk-bg-color);
text-decoration: none;
}
.sidebar .packages > li > a:hover {
color: var(--sidebar-pkglnk-tx-color-hover);
background-color: var(--sidebar-pkglnk-bg-color-hover);
.sidebar .modules > li > a:hover {
color: var(--sidebar-modlnk-tx-color-hover);
background-color: var(--sidebar-modlnk-bg-color-hover);
}
.sidebar .packages > li > a.active {
color: var(--sidebar-pkglnk-tx-color-active);
background-color: var(--sidebar-pkglnk-bg-color-active);
.sidebar .modules > li > a.active {
color: var(--sidebar-modlnk-tx-color-active);
background-color: var(--sidebar-modlnk-bg-color-active);
}
.sidebar p.str {
@ -495,13 +495,13 @@
--bg-color: #111;
--link-color: #88f;
--sidebar-sh-color: rgba(128, 128, 128, 0.09);
--sidebar-pkg-bg-color: #333;
--sidebar-pkglnk-tx-color: #fff;
--sidebar-pkglnk-tx-color-hover: #fff;
--sidebar-pkglnk-tx-color-active: #000;
--sidebar-pkglnk-bg-color: transparent;
--sidebar-pkglnk-bg-color-hover: #555;
--sidebar-pkglnk-bg-color-active: #FFBB4D;
--sidebar-mod-bg-color: #333;
--sidebar-modlnk-tx-color: #fff;
--sidebar-modlnk-tx-color-hover: #fff;
--sidebar-modlnk-tx-color-active: #000;
--sidebar-modlnk-bg-color: transparent;
--sidebar-modlnk-bg-color-hover: #555;
--sidebar-modlnk-bg-color-active: #FFBB4D;
--search-bg-color: #3c3c3c;
--search-bg-color-focus: #000;
--search-sh-color: rgba(255, 255, 255, 0.28);
@ -590,7 +590,7 @@
padding-right: 1.4rem;
background: transparent;
}
.packages {
.modules {
display: flex;
flex-wrap: wrap;
}
@ -703,15 +703,15 @@
<div id="guidesList"></div>
</div>
<div id="apiMenu" class="hidden">
<div id="sectMainPkg" class="hidden">
<h2><span>Main Package</span></h2>
<ul class="packages">
<li><a id="mainPkg" class="" href=""></a></li>
<div id="sectMainMod" class="hidden">
<h2><span>Main Module</span></h2>
<ul class="modules">
<li><a id="mainMod" class="" href=""></a></li>
</ul>
</div>
<div id="sectPkgs" class="hidden">
<div id="sectMods" class="hidden">
<h2><span>Dependencies</span></h2>
<ul id="listPkgs" class="packages"></ul>
<ul id="listMods" class="modules"></ul>
</div>
<div id="sectInfo" class="hidden">
<h2><span>Zig Version</span></h2>

View File

@ -17,9 +17,9 @@ const NAV_MODES = {
const domGuidesMenu = document.getElementById("guidesMenu");
const domApiMenu = document.getElementById("apiMenu");
const domGuidesList = document.getElementById("guidesList");
const domSectMainPkg = document.getElementById("sectMainPkg");
const domSectPkgs = document.getElementById("sectPkgs");
const domListPkgs = document.getElementById("listPkgs");
const domSectMainMod = document.getElementById("sectMainMod");
const domSectMods = document.getElementById("sectMods");
const domListMods = document.getElementById("listMods");
const domSectTypes = document.getElementById("sectTypes");
const domListTypes = document.getElementById("listTypes");
const domSectTests = document.getElementById("sectTests");
@ -66,7 +66,7 @@ const NAV_MODES = {
const domHdrName = document.getElementById("hdrName");
const domHelpModal = document.getElementById("helpModal");
const domSearchPlaceholder = document.getElementById("searchPlaceholder");
const sourceFileUrlTemplate = "src/{{pkg}}/{{file}}.html#L{{line}}"
const sourceFileUrlTemplate = "src/{{mod}}/{{file}}.html#L{{line}}"
const domLangRefLink = document.getElementById("langRefLink");
let searchTimer = null;
@ -83,27 +83,27 @@ const NAV_MODES = {
let typeTypeId = findTypeTypeId();
let pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 };
// for each package, is an array with packages to get to this one
let canonPkgPaths = computeCanonicalPackagePaths();
// for each module, is an array with modules to get to this one
let canonModPaths = computeCanonicalModulePaths();
// for each decl, is an array with {declNames, pkgNames} to get to this one
// for each decl, is an array with {declNames, modNames} to get to this one
let canonDeclPaths = null; // lazy; use getCanonDeclPath
// for each type, is an array with {declNames, pkgNames} to get to this one
// for each type, is an array with {declNames, modNames} to get to this one
let canonTypeDecls = null; // lazy; use getCanonTypeDecl
let curNav = {
mode: NAV_MODES.API,
activeGuide: "",
// each element is a package name, e.g. @import("a") then within there @import("b")
// starting implicitly from root package
pkgNames: [],
// same as above except actual packages, not names
pkgObjs: [],
// each element is a module name, e.g. @import("a") then within there @import("b")
// starting implicitly from root module
modNames: [],
// same as above except actual modules, not names
modObjs: [],
// Each element is a decl name, `a.b.c`, a is 0, b is 1, c is 2, etc.
// empty array means refers to the package itself
// empty array means refers to the module itself
declNames: [],
// these will be all types, except the last one may be a type or a decl
declObjs: [],
@ -190,9 +190,9 @@ const NAV_MODES = {
switch (curNav.mode) {
case NAV_MODES.API:
case NAV_MODES.API_INTERNAL:
let list = curNav.pkgNames.concat(curNav.declNames);
let list = curNav.modNames.concat(curNav.declNames);
if (list.length === 0) {
document.title = zigAnalysis.packages[zigAnalysis.rootPkg].name + suffix;
document.title = zigAnalysis.modules[zigAnalysis.rootMod].name + suffix;
} else {
document.title = list.join(".") + suffix;
}
@ -406,7 +406,7 @@ const NAV_MODES = {
// sidebar guides list
const section_list = zigAnalysis.guide_sections;
resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="packages"></ul></div>');
resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="modules"></ul></div>');
for (let j = 0; j < section_list.length; j += 1) {
const section = section_list[j];
const domSectionName = domGuidesList.children[j].children[0].children[0];
@ -445,7 +445,7 @@ const NAV_MODES = {
}
if (activeGuide == undefined) {
const root_file_idx = zigAnalysis.packages[zigAnalysis.rootPkg].file;
const root_file_idx = zigAnalysis.modules[zigAnalysis.rootMod].file;
const root_file_name = getFile(root_file_idx).name;
domGuides.innerHTML = markdown(`
# Zig Guides
@ -492,8 +492,8 @@ const NAV_MODES = {
domFnProto.classList.add("hidden");
domSectParams.classList.add("hidden");
domTldDocs.classList.add("hidden");
domSectMainPkg.classList.add("hidden");
domSectPkgs.classList.add("hidden");
domSectMainMod.classList.add("hidden");
domSectMods.classList.add("hidden");
domSectTypes.classList.add("hidden");
domSectTests.classList.add("hidden");
domSectDocTests.classList.add("hidden");
@ -518,7 +518,7 @@ const NAV_MODES = {
renderTitle();
renderInfo();
renderPkgList();
renderModList();
domPrivDeclsBox.checked = curNav.mode == NAV_MODES.API_INTERNAL;
@ -526,19 +526,19 @@ const NAV_MODES = {
return renderSearch();
}
let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
let pkg = rootPkg;
curNav.pkgObjs = [pkg];
for (let i = 1; i < curNav.pkgNames.length; i += 1) {
let childPkg = zigAnalysis.packages[pkg.table[curNav.pkgNames[i]]];
if (childPkg == null) {
let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
let mod = rootMod;
curNav.modObjs = [mod];
for (let i = 1; i < curNav.modNames.length; i += 1) {
let childMod = zigAnalysis.modules[mod.table[curNav.modNames[i]]];
if (childMod == null) {
return render404();
}
pkg = childPkg;
curNav.pkgObjs.push(pkg);
mod = childMod;
curNav.modObjs.push(mod);
}
let currentType = getType(pkg.main);
let currentType = getType(mod.main);
curNav.declObjs = [currentType];
for (let i = 0; i < curNav.declNames.length; i += 1) {
let childDecl = findSubDecl(currentType, curNav.declNames[i]);
@ -818,24 +818,24 @@ const NAV_MODES = {
}
function renderNav() {
let len = curNav.pkgNames.length + curNav.declNames.length;
let len = curNav.modNames.length + curNav.declNames.length;
resizeDomList(domListNav, len, '<li><a href="#"></a></li>');
let list = [];
let hrefPkgNames = [];
let hrefModNames = [];
let hrefDeclNames = [];
for (let i = 0; i < curNav.pkgNames.length; i += 1) {
hrefPkgNames.push(curNav.pkgNames[i]);
let name = curNav.pkgNames[i];
for (let i = 0; i < curNav.modNames.length; i += 1) {
hrefModNames.push(curNav.modNames[i]);
let name = curNav.modNames[i];
list.push({
name: name,
link: navLink(hrefPkgNames, hrefDeclNames),
link: navLink(hrefModNames, hrefDeclNames),
});
}
for (let i = 0; i < curNav.declNames.length; i += 1) {
hrefDeclNames.push(curNav.declNames[i]);
list.push({
name: curNav.declNames[i],
link: navLink(hrefPkgNames, hrefDeclNames),
link: navLink(hrefModNames, hrefDeclNames),
});
}
@ -866,29 +866,29 @@ const NAV_MODES = {
domStatus.classList.remove("hidden");
}
function renderPkgList() {
const rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
function renderModList() {
const rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
let list = [];
for (let key in rootPkg.table) {
let pkgIndex = rootPkg.table[key];
if (zigAnalysis.packages[pkgIndex] == null) continue;
if (key == rootPkg.name) continue;
for (let key in rootMod.table) {
let modIndex = rootMod.table[key];
if (zigAnalysis.modules[modIndex] == null) continue;
if (key == rootMod.name) continue;
list.push({
name: key,
pkg: pkgIndex,
mod: modIndex,
});
}
{
let aDom = domSectMainPkg.children[1].children[0].children[0];
aDom.textContent = rootPkg.name;
aDom.setAttribute("href", navLinkPkg(zigAnalysis.rootPkg));
if (rootPkg.name === curNav.pkgNames[0]) {
let aDom = domSectMainMod.children[1].children[0].children[0];
aDom.textContent = rootMod.name;
aDom.setAttribute("href", navLinkMod(zigAnalysis.rootMod));
if (rootMod.name === curNav.modNames[0]) {
aDom.classList.add("active");
} else {
aDom.classList.remove("active");
}
domSectMainPkg.classList.remove("hidden");
domSectMainMod.classList.remove("hidden");
}
list.sort(function (a, b) {
@ -896,45 +896,45 @@ const NAV_MODES = {
});
if (list.length !== 0) {
resizeDomList(domListPkgs, list.length, '<li><a href="#"></a></li>');
resizeDomList(domListMods, list.length, '<li><a href="#"></a></li>');
for (let i = 0; i < list.length; i += 1) {
let liDom = domListPkgs.children[i];
let liDom = domListMods.children[i];
let aDom = liDom.children[0];
aDom.textContent = list[i].name;
aDom.setAttribute("href", navLinkPkg(list[i].pkg));
if (list[i].name === curNav.pkgNames[0]) {
aDom.setAttribute("href", navLinkMod(list[i].mod));
if (list[i].name === curNav.modNames[0]) {
aDom.classList.add("active");
} else {
aDom.classList.remove("active");
}
}
domSectPkgs.classList.remove("hidden");
domSectMods.classList.remove("hidden");
}
}
function navLink(pkgNames, declNames, callName) {
function navLink(modNames, declNames, callName) {
let base = curNav.mode;
if (pkgNames.length === 0 && declNames.length === 0) {
if (modNames.length === 0 && declNames.length === 0) {
return base;
} else if (declNames.length === 0 && callName == null) {
return base + pkgNames.join(".");
return base + modNames.join(".");
} else if (callName == null) {
return base + pkgNames.join(".") + ":" + declNames.join(".");
return base + modNames.join(".") + ":" + declNames.join(".");
} else {
return (
base + pkgNames.join(".") + ":" + declNames.join(".") + ";" + callName
base + modNames.join(".") + ":" + declNames.join(".") + ";" + callName
);
}
}
function navLinkPkg(pkgIndex) {
return navLink(canonPkgPaths[pkgIndex], []);
function navLinkMod(modIndex) {
return navLink(canonModPaths[modIndex], []);
}
function navLinkDecl(childName) {
return navLink(curNav.pkgNames, curNav.declNames.concat([childName]));
return navLink(curNav.modNames, curNav.declNames.concat([childName]));
}
function findDeclNavLink(declName) {
@ -946,12 +946,12 @@ const NAV_MODES = {
const curDeclName = curNav.declNames[i - 1];
if (curDeclName == declName) {
const declPath = curNav.declNames.slice(0, i);
return navLink(curNav.pkgNames, declPath);
return navLink(curNav.modNames, declPath);
}
if (findSubDecl(curDecl, declName) != null) {
const declPath = curNav.declNames.slice(0, i).concat([declName]);
return navLink(curNav.pkgNames, declPath);
return navLink(curNav.modNames, declPath);
}
}
@ -972,7 +972,7 @@ const NAV_MODES = {
// callName += ')';
// declNamesCopy.push(callName);
// return navLink(curNav.pkgNames, declNamesCopy);
// return navLink(curNav.modNames, declNamesCopy);
// }
function resizeDomListDl(dlDom, desiredLen) {
@ -2396,7 +2396,7 @@ const NAV_MODES = {
if (
rootIsStd &&
typeObj ===
getType(zigAnalysis.packages[zigAnalysis.rootPkg].main)
getType(zigAnalysis.modules[zigAnalysis.rootMod].main)
) {
name = "std";
} else {
@ -2702,7 +2702,7 @@ const NAV_MODES = {
const srcNode = getAstNode(decl.src);
const srcFile = getFile(srcNode.file);
return sourceFileUrlTemplate.
replace("{{pkg}}", zigAnalysis.packages[srcFile.pkgIndex].name).
replace("{{mod}}", zigAnalysis.modules[srcFile.modIndex].name).
replace("{{file}}", srcFile.name).
replace("{{line}}", srcNode.line + 1);
}
@ -3050,14 +3050,14 @@ const NAV_MODES = {
}
function detectRootIsStd() {
let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
if (rootPkg.table["std"] == null) {
// no std mapped into the root package
let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
if (rootMod.table["std"] == null) {
// no std mapped into the root module
return false;
}
let stdPkg = zigAnalysis.packages[rootPkg.table["std"]];
if (stdPkg == null) return false;
return rootPkg.file === stdPkg.file;
let stdMod = zigAnalysis.modules[rootMod.table["std"]];
if (stdMod == null) return false;
return rootMod.file === stdMod.file;
}
function indexTypeKinds() {
@ -3112,8 +3112,8 @@ const NAV_MODES = {
function updateCurNav() {
curNav = {
mode: NAV_MODES.API,
pkgNames: [],
pkgObjs: [],
modNames: [],
modObjs: [],
declNames: [],
declObjs: [],
callName: null,
@ -3123,11 +3123,11 @@ const NAV_MODES = {
const mode = location.hash.substring(0, 3);
let query = location.hash.substring(3);
const DEFAULT_HASH = NAV_MODES.API + zigAnalysis.packages[zigAnalysis.rootPkg].name;
const DEFAULT_HASH = NAV_MODES.API + zigAnalysis.modules[zigAnalysis.rootMod].name;
switch (mode) {
case NAV_MODES.API:
case NAV_MODES.API_INTERNAL:
// #A;PACKAGE:decl.decl.decl?search-term
// #A;MODULE:decl.decl.decl?search-term
curNav.mode = mode;
let qpos = query.indexOf("?");
@ -3143,7 +3143,7 @@ const NAV_MODES = {
if (parts[0] == "") {
location.hash = DEFAULT_HASH;
} else {
curNav.pkgNames = decodeURIComponent(parts[0]).split(".");
curNav.modNames = decodeURIComponent(parts[0]).split(".");
}
if (parts[1] != null) {
@ -3249,30 +3249,30 @@ const NAV_MODES = {
return null;
}
function computeCanonicalPackagePaths() {
let list = new Array(zigAnalysis.packages.length);
// Now we try to find all the packages from root.
let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
function computeCanonicalModulePaths() {
let list = new Array(zigAnalysis.modules.length);
// Now we try to find all the modules from root.
let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
// Breadth-first to keep the path shortest possible.
let stack = [
{
path: [],
pkg: rootPkg,
mod: rootMod,
},
];
while (stack.length !== 0) {
let item = stack.shift();
for (let key in item.pkg.table) {
let childPkgIndex = item.pkg.table[key];
if (list[childPkgIndex] != null) continue;
let childPkg = zigAnalysis.packages[childPkgIndex];
if (childPkg == null) continue;
for (let key in item.mod.table) {
let childModIndex = item.mod.table[key];
if (list[childModIndex] != null) continue;
let childMod = zigAnalysis.modules[childModIndex];
if (childMod == null) continue;
let newPath = item.path.concat([key]);
list[childPkgIndex] = newPath;
list[childModIndex] = newPath;
stack.push({
path: newPath,
pkg: childPkg,
mod: childMod,
});
}
}
@ -3283,15 +3283,15 @@ const NAV_MODES = {
let list = new Array(zigAnalysis.decls.length);
canonTypeDecls = new Array(zigAnalysis.types.length);
for (let pkgI = 0; pkgI < zigAnalysis.packages.length; pkgI += 1) {
let pkg = zigAnalysis.packages[pkgI];
let pkgNames = canonPkgPaths[pkgI];
if (pkgNames === undefined) continue;
for (let modI = 0; modI < zigAnalysis.modules.length; modI += 1) {
let mod = zigAnalysis.modules[modI];
let modNames = canonModPaths[modI];
if (modNames === undefined) continue;
let stack = [
{
declNames: [],
type: getType(pkg.main),
type: getType(mod.main),
},
];
while (stack.length !== 0) {
@ -3323,12 +3323,12 @@ const NAV_MODES = {
if (childDecl.is_uns) {
unsDeclList.push(childDecl);
} else {
addDeclToSearchResults(childDecl, childDeclIndex, pkgNames, item, list, stack);
addDeclToSearchResults(childDecl, childDeclIndex, modNames, item, list, stack);
}
}
}
} else {
addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack);
addDeclToSearchResults(decl, declIndex, modNames, item, list, stack);
}
}
}
@ -3337,13 +3337,13 @@ const NAV_MODES = {
return list;
}
function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
let declVal = resolveValue(decl.value);
let declNames = item.declNames.concat([decl.name]);
if (list[declIndex] != null) return;
list[declIndex] = {
pkgNames: pkgNames,
modNames: modNames,
declNames: declNames,
};
@ -3677,8 +3677,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx);
if (!canonPath) return;
let lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];
let fullPath = lastPkgName + ":" + canonPath.declNames.join(".");
let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
let fullPath = lastModName + ":" + canonPath.declNames.join(".");
separator = '.';
result = "#A;" + fullPath;
@ -3688,8 +3688,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
}
if (!curDeclOrType) {
for (let i = 0; i < zigAnalysis.packages.length; i += 1){
const p = zigAnalysis.packages[i];
for (let i = 0; i < zigAnalysis.modules.length; i += 1){
const p = zigAnalysis.modules[i];
if (p.name == components[0]) {
curDeclOrType = getType(p.main);
result += "#A;" + components[0];
@ -4005,9 +4005,9 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
if (canonPath == null) continue;
let decl = getDecl(declIndex);
let lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];
let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
let fullPathSearchText =
lastPkgName + "." + canonPath.declNames.join(".");
lastModName + "." + canonPath.declNames.join(".");
let astNode = getAstNode(decl.src);
let fileAndDocs = ""; //zigAnalysis.files[astNode.file];
// TODO: understand what this piece of code is trying to achieve
@ -4074,10 +4074,10 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
for (let i = 0; i < matchedItems.length; i += 1) {
const match = matchedItems[i];
const lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1];
const lastModName = match.path.modNames[match.path.modNames.length - 1];
const text = lastPkgName + "." + match.path.declNames.join(".");
const href = navLink(match.path.pkgNames, match.path.declNames);
const text = lastModName + "." + match.path.declNames.join(".");
const href = navLink(match.path.modNames, match.path.declNames);
matchedItemsHTML += "<li><a href=\"" + href + "\">" + text + "</a></li>";
}
@ -4156,7 +4156,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
const file = zigAnalysis.files[idx];
return {
name: file[0],
pkgIndex: file[1],
modIndex: file[1],
};
}

View File

@ -4,23 +4,23 @@ const build_options = @import("build_options");
const Ast = std.zig.Ast;
const Autodoc = @This();
const Compilation = @import("Compilation.zig");
const Module = @import("Module.zig");
const File = Module.File;
const Package = @import("Package.zig");
const CompilationModule = @import("Module.zig");
const File = CompilationModule.File;
const Module = @import("Package.zig");
const Tokenizer = std.zig.Tokenizer;
const Zir = @import("Zir.zig");
const Ref = Zir.Inst.Ref;
const log = std.log.scoped(.autodoc);
const Docgen = @import("autodoc/render_source.zig");
const renderer = @import("autodoc/render_source.zig");
module: *Module,
comp_module: *CompilationModule,
doc_location: Compilation.EmitLoc,
arena: std.mem.Allocator,
// The goal of autodoc is to fill up these arrays
// that will then be serialized as JSON and consumed
// by the JS frontend.
packages: std.AutoArrayHashMapUnmanaged(*Package, DocData.DocPackage) = .{},
modules: std.AutoArrayHashMapUnmanaged(*Module, DocData.DocModule) = .{},
files: std.AutoArrayHashMapUnmanaged(*File, usize) = .{},
calls: std.ArrayListUnmanaged(DocData.Call) = .{},
types: std.ArrayListUnmanaged(DocData.Type) = .{},
@ -74,10 +74,10 @@ const Section = struct {
};
var arena_allocator: std.heap.ArenaAllocator = undefined;
pub fn init(m: *Module, doc_location: Compilation.EmitLoc) Autodoc {
pub fn init(m: *CompilationModule, doc_location: Compilation.EmitLoc) Autodoc {
arena_allocator = std.heap.ArenaAllocator.init(m.gpa);
return .{
.module = m,
.comp_module = m,
.doc_location = doc_location,
.arena = arena_allocator.allocator(),
};
@ -97,15 +97,15 @@ pub fn generateZirData(self: *Autodoc) !void {
log.debug("Ref map size: {}", .{Ref.typed_value_map.len});
const root_src_dir = self.module.main_pkg.root_src_directory;
const root_src_path = self.module.main_pkg.root_src_path;
const root_src_dir = self.comp_module.main_pkg.root_src_directory;
const root_src_path = self.comp_module.main_pkg.root_src_path;
const joined_src_path = try root_src_dir.join(self.arena, &.{root_src_path});
defer self.arena.free(joined_src_path);
const abs_root_src_path = try std.fs.path.resolve(self.arena, &.{ ".", joined_src_path });
defer self.arena.free(abs_root_src_path);
const file = self.module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table
const file = self.comp_module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table
// Append all the types in Zir.Inst.Ref.
{
try self.types.append(self.arena, .{
@ -207,20 +207,20 @@ pub fn generateZirData(self: *Autodoc) !void {
}
const rootName = blk: {
const rootName = std.fs.path.basename(self.module.main_pkg.root_src_path);
const rootName = std.fs.path.basename(self.comp_module.main_pkg.root_src_path);
break :blk rootName[0 .. rootName.len - 4];
};
const main_type_index = self.types.items.len;
{
try self.packages.put(self.arena, self.module.main_pkg, .{
try self.modules.put(self.arena, self.comp_module.main_pkg, .{
.name = rootName,
.main = main_type_index,
.table = .{},
});
try self.packages.entries.items(.value)[0].table.put(
try self.modules.entries.items(.value)[0].table.put(
self.arena,
self.module.main_pkg,
self.comp_module.main_pkg,
.{
.name = rootName,
.value = 0,
@ -257,7 +257,7 @@ pub fn generateZirData(self: *Autodoc) !void {
var data = DocData{
.params = .{},
.packages = self.packages,
.modules = self.modules,
.files = self.files,
.calls = self.calls.items,
.types = self.types.items,
@ -269,7 +269,7 @@ pub fn generateZirData(self: *Autodoc) !void {
};
const base_dir = self.doc_location.directory orelse
self.module.zig_cache_artifact_directory;
self.comp_module.zig_cache_artifact_directory;
base_dir.handle.makeDir(self.doc_location.basename) catch |e| switch (e) {
error.PathAlreadyExists => {},
@ -279,7 +279,7 @@ pub fn generateZirData(self: *Autodoc) !void {
const output_dir = if (self.doc_location.directory) |d|
try d.handle.openDir(self.doc_location.basename, .{})
else
try self.module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{});
try self.comp_module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{});
{
const data_js_f = try output_dir.createFile("data.js", .{});
@ -316,8 +316,8 @@ pub fn generateZirData(self: *Autodoc) !void {
while (files_iterator.next()) |entry| {
const sub_file_path = entry.key_ptr.*.sub_file_path;
const file_package = entry.key_ptr.*.pkg;
const package_name = (self.packages.get(file_package) orelse continue).name;
const file_module = entry.key_ptr.*.pkg;
const module_name = (self.modules.get(file_module) orelse continue).name;
const file_path = std.fs.path.dirname(sub_file_path) orelse "";
const file_name = if (file_path.len > 0) sub_file_path[file_path.len + 1 ..] else sub_file_path;
@ -325,7 +325,7 @@ pub fn generateZirData(self: *Autodoc) !void {
const html_file_name = try std.mem.concat(self.arena, u8, &.{ file_name, ".html" });
defer self.arena.free(html_file_name);
const dir_name = try std.fs.path.join(self.arena, &.{ package_name, file_path });
const dir_name = try std.fs.path.join(self.arena, &.{ module_name, file_path });
defer self.arena.free(dir_name);
var dir = try html_dir.makeOpenPath(dir_name, .{});
@ -340,13 +340,13 @@ pub fn generateZirData(self: *Autodoc) !void {
const out = buffer.writer();
try Docgen.genHtml(self.module.gpa, entry.key_ptr.*, out);
try renderer.genHtml(self.comp_module.gpa, entry.key_ptr.*, out);
try buffer.flush();
}
}
// copy main.js, index.html
var docs_dir = try self.module.comp.zig_lib_directory.handle.openDir("docs", .{});
var docs_dir = try self.comp_module.comp.zig_lib_directory.handle.openDir("docs", .{});
defer docs_dir.close();
try docs_dir.copyFile("main.js", output_dir, "main.js", .{});
try docs_dir.copyFile("index.html", output_dir, "index.html", .{});
@ -407,7 +407,7 @@ const Scope = struct {
/// The output of our analysis process.
const DocData = struct {
typeKinds: []const []const u8 = std.meta.fieldNames(DocTypeKinds),
rootPkg: u32 = 0,
rootMod: u32 = 0,
params: struct {
zigId: []const u8 = "arst",
zigVersion: []const u8 = build_options.version,
@ -416,7 +416,7 @@ const DocData = struct {
.{ .target = "arst" },
},
},
packages: std.AutoArrayHashMapUnmanaged(*Package, DocPackage),
modules: std.AutoArrayHashMapUnmanaged(*Module, DocModule),
errors: []struct {} = &.{},
// non-hardcoded stuff
@ -448,10 +448,10 @@ const DocData = struct {
const f_name = @tagName(f);
try jsw.objectField(f_name);
switch (f) {
.files => try writeFileTableToJson(self.files, self.packages, &jsw),
.files => try writeFileTableToJson(self.files, self.modules, &jsw),
.guide_sections => try writeGuidesToJson(self.guide_sections, &jsw),
.packages => {
try std.json.stringify(self.packages.values(), opts, w);
.modules => {
try std.json.stringify(self.modules.values(), opts, w);
jsw.state_index -= 1;
},
else => {
@ -477,18 +477,18 @@ const DocData = struct {
const ComptimeExpr = struct {
code: []const u8,
};
const DocPackage = struct {
const DocModule = struct {
name: []const u8 = "(root)",
file: usize = 0, // index into `files`
main: usize = 0, // index into `types`
table: std.AutoHashMapUnmanaged(*Package, TableEntry),
table: std.AutoHashMapUnmanaged(*Module, TableEntry),
pub const TableEntry = struct {
name: []const u8,
value: usize,
};
pub fn jsonStringify(
self: DocPackage,
self: DocModule,
opts: std.json.StringifyOptions,
w: anytype,
) !void {
@ -496,11 +496,11 @@ const DocData = struct {
if (opts.whitespace) |ws| jsw.whitespace = ws;
try jsw.beginObject();
inline for (comptime std.meta.tags(std.meta.FieldEnum(DocPackage))) |f| {
inline for (comptime std.meta.tags(std.meta.FieldEnum(DocModule))) |f| {
const f_name = @tagName(f);
try jsw.objectField(f_name);
switch (f) {
.table => try writePackageTableToJson(self.table, &jsw),
.table => try writeModuleTableToJson(self.table, &jsw),
else => {
try std.json.stringify(@field(self, f_name), opts, w);
jsw.state_index -= 1;
@ -917,23 +917,23 @@ fn walkInstruction(
// importFile cannot error out since all files
// are already loaded at this point
if (file.pkg.table.get(path)) |other_package| {
const result = try self.packages.getOrPut(self.arena, other_package);
if (file.pkg.table.get(path)) |other_module| {
const result = try self.modules.getOrPut(self.arena, other_module);
// Immediately add this package to the import table of our
// current package, regardless of wether it's new or not.
if (self.packages.getPtr(file.pkg)) |current_package| {
// Immediately add this module to the import table of our
// current module, regardless of wether it's new or not.
if (self.modules.getPtr(file.pkg)) |current_module| {
// TODO: apparently, in the stdlib a file gets analized before
// its package gets added. I guess we're importing a file
// that belongs to another package through its file path?
// (ie not through its package name).
// its module gets added. I guess we're importing a file
// that belongs to another module through its file path?
// (ie not through its module name).
// We're bailing for now, but maybe we shouldn't?
_ = try current_package.table.getOrPutValue(
_ = try current_module.table.getOrPutValue(
self.arena,
other_package,
other_module,
.{
.name = path,
.value = self.packages.getIndex(other_package).?,
.value = self.modules.getIndex(other_module).?,
},
);
}
@ -945,7 +945,7 @@ fn walkInstruction(
};
}
// create a new package entry
// create a new module entry
const main_type_index = self.types.items.len;
result.value_ptr.* = .{
.name = path,
@ -953,18 +953,18 @@ fn walkInstruction(
.table = .{},
};
// TODO: Add this package as a dependency to the current package
// TODO: Add this module as a dependency to the current module
// TODO: this seems something that could be done in bulk
// at the beginning or the end, or something.
const root_src_dir = other_package.root_src_directory;
const root_src_path = other_package.root_src_path;
const root_src_dir = other_module.root_src_directory;
const root_src_path = other_module.root_src_path;
const joined_src_path = try root_src_dir.join(self.arena, &.{root_src_path});
defer self.arena.free(joined_src_path);
const abs_root_src_path = try std.fs.path.resolve(self.arena, &.{ ".", joined_src_path });
defer self.arena.free(abs_root_src_path);
const new_file = self.module.import_table.get(abs_root_src_path).?;
const new_file = self.comp_module.import_table.get(abs_root_src_path).?;
var root_scope = Scope{
.parent = null,
@ -985,7 +985,7 @@ fn walkInstruction(
);
}
const new_file = self.module.importFile(file, path) catch unreachable;
const new_file = self.comp_module.importFile(file, path) catch unreachable;
const result = try self.files.getOrPut(self.arena, new_file.file);
if (result.found_existing) {
return DocData.WalkResult{
@ -3189,7 +3189,7 @@ fn analyzeDecl(
// const pl_node = data[Zir.refToIndex(func_index).?].pl_node;
// const fn_src = try self.srcLocInfo(file, pl_node.src_node, decl_src);
// const tree = try file.getTree(self.module.gpa);
// const tree = try file.getTree(self.comp_module.gpa);
// const test_source_code = tree.getNodeSource(fn_src.src_node);
// const ast_node_index = self.ast_nodes.items.len;
@ -4638,7 +4638,7 @@ fn cteTodo(self: *Autodoc, msg: []const u8) error{OutOfMemory}!DocData.WalkResul
fn writeFileTableToJson(
map: std.AutoArrayHashMapUnmanaged(*File, usize),
pkgs: std.AutoArrayHashMapUnmanaged(*Package, DocData.DocPackage),
mods: std.AutoArrayHashMapUnmanaged(*Module, DocData.DocModule),
jsw: anytype,
) !void {
try jsw.beginArray();
@ -4649,7 +4649,7 @@ fn writeFileTableToJson(
try jsw.arrayElem();
try jsw.emitString(entry.key_ptr.*.sub_file_path);
try jsw.arrayElem();
try jsw.emitNumber(pkgs.getIndex(entry.key_ptr.*.pkg) orelse 0);
try jsw.emitNumber(mods.getIndex(entry.key_ptr.*.pkg) orelse 0);
try jsw.endArray();
}
try jsw.endArray();
@ -4690,8 +4690,8 @@ fn writeGuidesToJson(sections: std.ArrayListUnmanaged(Section), jsw: anytype) !v
try jsw.endArray();
}
fn writePackageTableToJson(
map: std.AutoHashMapUnmanaged(*Package, DocData.DocPackage.TableEntry),
fn writeModuleTableToJson(
map: std.AutoHashMapUnmanaged(*Module, DocData.DocModule.TableEntry),
jsw: anytype,
) !void {
try jsw.beginObject();
@ -4710,7 +4710,7 @@ fn srcLocInfo(
parent_src: SrcLocInfo,
) !SrcLocInfo {
const sn = @intCast(u32, @intCast(i32, parent_src.src_node) + src_node);
const tree = try file.getTree(self.module.gpa);
const tree = try file.getTree(self.comp_module.gpa);
const node_idx = @bitCast(Ast.Node.Index, sn);
const tokens = tree.nodes.items(.main_token);
@ -4731,7 +4731,7 @@ fn declIsVar(
parent_src: SrcLocInfo,
) !bool {
const sn = @intCast(u32, @intCast(i32, parent_src.src_node) + src_node);
const tree = try file.getTree(self.module.gpa);
const tree = try file.getTree(self.comp_module.gpa);
const node_idx = @bitCast(Ast.Node.Index, sn);
const tokens = tree.nodes.items(.main_token);
const tags = tree.tokens.items(.tag);
@ -4743,7 +4743,7 @@ fn declIsVar(
}
fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 {
const source = (try file.getSource(self.module.gpa)).bytes;
const source = (try file.getSource(self.comp_module.gpa)).bytes;
var tokenizer = Tokenizer.init(source);
var tok = tokenizer.next();
var comment = std.ArrayList(u8).init(self.arena);
@ -4782,9 +4782,9 @@ fn findGuidePaths(self: *Autodoc, file: *File, str: []const u8) !void {
fn addGuide(self: *Autodoc, file: *File, guide_path: []const u8, section: *Section) !void {
if (guide_path.len == 0) return error.MissingAutodocGuideName;
const cur_pkg_dir_path = file.pkg.root_src_directory.path orelse ".";
const cur_mod_dir_path = file.pkg.root_src_directory.path orelse ".";
const resolved_path = try std.fs.path.resolve(self.arena, &[_][]const u8{
cur_pkg_dir_path, file.sub_file_path, "..", guide_path,
cur_mod_dir_path, file.sub_file_path, "..", guide_path,
});
var guide_file = try file.pkg.root_src_directory.handle.openFile(resolved_path, .{});