authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-04-25 20:24:40+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-04-25 20:24:40+02:00
loge0ee9d38cf589c70f81444e79b6c7ee551adcf03
tree33f5e2d3acacc24e63f259ce5485fee28243ed44
parent8d88dcdc61c61e3410138f4402482131f5074a80
parent015ea6fd6c0c0deacb42de237f737d208737e3ac
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

autodoc: Change package to module to better reflect the new names

3 files changed, 207 insertions(+), 207 deletions(-)

lib/docs/index.html+38-38
......@@ -14,13 +14,13 @@
1414 --bg-color: #ffffff;
1515 --link-color: #2A6286;
1616 --sidebar-sh-color: rgba(0, 0, 0, 0.09);
17 --sidebar-pkg-bg-color: #f1f1f1;
18 --sidebar-pkglnk-tx-color: #141414;
19 --sidebar-pkglnk-tx-color-hover: #fff;
20 --sidebar-pkglnk-tx-color-active: #000;
21 --sidebar-pkglnk-bg-color: transparent;
22 --sidebar-pkglnk-bg-color-hover: #555;
23 --sidebar-pkglnk-bg-color-active: #FFBB4D;
17 --sidebar-mod-bg-color: #f1f1f1;
18 --sidebar-modlnk-tx-color: #141414;
19 --sidebar-modlnk-tx-color-hover: #fff;
20 --sidebar-modlnk-tx-color-active: #000;
21 --sidebar-modlnk-bg-color: transparent;
22 --sidebar-modlnk-bg-color-hover: #555;
23 --sidebar-modlnk-bg-color-active: #FFBB4D;
2424 --search-bg-color: #f3f3f3;
2525 --search-bg-color-focus: #ffffff;
2626 --search-sh-color: rgba(0, 0, 0, 0.18);
......@@ -130,8 +130,8 @@
130130 .sidebar .guides-api-switch a {
131131 display: block;
132132 padding: 0.5rem 1rem;
133 color: var(--sidebar-pkglnk-tx-color);
134 background-color: var(--sidebar-pkglnk-bg-color);
133 color: var(--sidebar-modlnk-tx-color);
134 background-color: var(--sidebar-modlnk-bg-color);
135135 border: 1px solid var(--tx-color);
136136 }
137137
......@@ -150,13 +150,13 @@
150150 }
151151
152152 #ApiSwitch:hover:not(.active), #guideSwitch:hover:not(.active) {
153 color: var(--sidebar-pkglnk-tx-color-hover);
154 background-color: var(--sidebar-pkglnk-bg-color-hover);
153 color: var(--sidebar-modlnk-tx-color-hover);
154 background-color: var(--sidebar-modlnk-bg-color-hover);
155155 }
156156
157157 .sidebar .guides-api-switch .active {
158 color: var(--sidebar-pkglnk-tx-color-active);
159 background-color: var(--sidebar-pkglnk-bg-color-active);
158 color: var(--sidebar-modlnk-tx-color-active);
159 background-color: var(--sidebar-modlnk-bg-color-active);
160160 }
161161
162162 .sidebar h2 {
......@@ -169,29 +169,29 @@
169169 border-bottom: 0.125rem dotted var(--tx-color);
170170 }
171171
172 .sidebar .packages {
172 .sidebar .modules {
173173 list-style-type: none;
174174 margin: 0;
175175 padding: 0;
176 background-color: var(--sidebar-pkg-bg-color);
176 background-color: var(--sidebar-mod-bg-color);
177177 }
178178
179 .sidebar .packages > li > a {
179 .sidebar .modules > li > a {
180180 display: block;
181181 padding: 0.5rem 1rem;
182 color: var(--sidebar-pkglnk-tx-color);
183 background-color: var(--sidebar-pkglnk-bg-color);
182 color: var(--sidebar-modlnk-tx-color);
183 background-color: var(--sidebar-modlnk-bg-color);
184184 text-decoration: none;
185185 }
186186
187 .sidebar .packages > li > a:hover {
188 color: var(--sidebar-pkglnk-tx-color-hover);
189 background-color: var(--sidebar-pkglnk-bg-color-hover);
187 .sidebar .modules > li > a:hover {
188 color: var(--sidebar-modlnk-tx-color-hover);
189 background-color: var(--sidebar-modlnk-bg-color-hover);
190190 }
191191
192 .sidebar .packages > li > a.active {
193 color: var(--sidebar-pkglnk-tx-color-active);
194 background-color: var(--sidebar-pkglnk-bg-color-active);
192 .sidebar .modules > li > a.active {
193 color: var(--sidebar-modlnk-tx-color-active);
194 background-color: var(--sidebar-modlnk-bg-color-active);
195195 }
196196
197197 .sidebar p.str {
......@@ -495,13 +495,13 @@
495495 --bg-color: #111;
496496 --link-color: #88f;
497497 --sidebar-sh-color: rgba(128, 128, 128, 0.09);
498 --sidebar-pkg-bg-color: #333;
499 --sidebar-pkglnk-tx-color: #fff;
500 --sidebar-pkglnk-tx-color-hover: #fff;
501 --sidebar-pkglnk-tx-color-active: #000;
502 --sidebar-pkglnk-bg-color: transparent;
503 --sidebar-pkglnk-bg-color-hover: #555;
504 --sidebar-pkglnk-bg-color-active: #FFBB4D;
498 --sidebar-mod-bg-color: #333;
499 --sidebar-modlnk-tx-color: #fff;
500 --sidebar-modlnk-tx-color-hover: #fff;
501 --sidebar-modlnk-tx-color-active: #000;
502 --sidebar-modlnk-bg-color: transparent;
503 --sidebar-modlnk-bg-color-hover: #555;
504 --sidebar-modlnk-bg-color-active: #FFBB4D;
505505 --search-bg-color: #3c3c3c;
506506 --search-bg-color-focus: #000;
507507 --search-sh-color: rgba(255, 255, 255, 0.28);
......@@ -590,7 +590,7 @@
590590 padding-right: 1.4rem;
591591 background: transparent;
592592 }
593 .packages {
593 .modules {
594594 display: flex;
595595 flex-wrap: wrap;
596596 }
......@@ -703,15 +703,15 @@
703703 <div id="guidesList"></div>
704704 </div>
705705 <div id="apiMenu" class="hidden">
706 <div id="sectMainPkg" class="hidden">
707 <h2><span>Main Package</span></h2>
708 <ul class="packages">
709 <li><a id="mainPkg" class="" href=""></a></li>
706 <div id="sectMainMod" class="hidden">
707 <h2><span>Main Module</span></h2>
708 <ul class="modules">
709 <li><a id="mainMod" class="" href=""></a></li>
710710 </ul>
711711 </div>
712 <div id="sectPkgs" class="hidden">
712 <div id="sectMods" class="hidden">
713713 <h2><span>Dependencies</span></h2>
714 <ul id="listPkgs" class="packages"></ul>
714 <ul id="listMods" class="modules"></ul>
715715 </div>
716716 <div id="sectInfo" class="hidden">
717717 <h2><span>Zig Version</span></h2>
lib/docs/main.js+109-109
......@@ -17,9 +17,9 @@ const NAV_MODES = {
1717 const domGuidesMenu = document.getElementById("guidesMenu");
1818 const domApiMenu = document.getElementById("apiMenu");
1919 const domGuidesList = document.getElementById("guidesList");
20 const domSectMainPkg = document.getElementById("sectMainPkg");
21 const domSectPkgs = document.getElementById("sectPkgs");
22 const domListPkgs = document.getElementById("listPkgs");
20 const domSectMainMod = document.getElementById("sectMainMod");
21 const domSectMods = document.getElementById("sectMods");
22 const domListMods = document.getElementById("listMods");
2323 const domSectTypes = document.getElementById("sectTypes");
2424 const domListTypes = document.getElementById("listTypes");
2525 const domSectTests = document.getElementById("sectTests");
......@@ -66,7 +66,7 @@ const NAV_MODES = {
6666 const domHdrName = document.getElementById("hdrName");
6767 const domHelpModal = document.getElementById("helpModal");
6868 const domSearchPlaceholder = document.getElementById("searchPlaceholder");
69 const sourceFileUrlTemplate = "src/{{pkg}}/{{file}}.html#L{{line}}"
69 const sourceFileUrlTemplate = "src/{{mod}}/{{file}}.html#L{{line}}"
7070 const domLangRefLink = document.getElementById("langRefLink");
7171
7272 let searchTimer = null;
......@@ -83,27 +83,27 @@ const NAV_MODES = {
8383 let typeTypeId = findTypeTypeId();
8484 let pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 };
8585
86 // for each package, is an array with packages to get to this one
87 let canonPkgPaths = computeCanonicalPackagePaths();
86 // for each module, is an array with modules to get to this one
87 let canonModPaths = computeCanonicalModulePaths();
8888
89 // for each decl, is an array with {declNames, pkgNames} to get to this one
89 // for each decl, is an array with {declNames, modNames} to get to this one
9090
9191 let canonDeclPaths = null; // lazy; use getCanonDeclPath
9292
93 // for each type, is an array with {declNames, pkgNames} to get to this one
93 // for each type, is an array with {declNames, modNames} to get to this one
9494
9595 let canonTypeDecls = null; // lazy; use getCanonTypeDecl
9696
9797 let curNav = {
9898 mode: NAV_MODES.API,
9999 activeGuide: "",
100 // each element is a package name, e.g. @import("a") then within there @import("b")
101 // starting implicitly from root package
102 pkgNames: [],
103 // same as above except actual packages, not names
104 pkgObjs: [],
100 // each element is a module name, e.g. @import("a") then within there @import("b")
101 // starting implicitly from root module
102 modNames: [],
103 // same as above except actual modules, not names
104 modObjs: [],
105105 // Each element is a decl name, `a.b.c`, a is 0, b is 1, c is 2, etc.
106 // empty array means refers to the package itself
106 // empty array means refers to the module itself
107107 declNames: [],
108108 // these will be all types, except the last one may be a type or a decl
109109 declObjs: [],
......@@ -190,9 +190,9 @@ const NAV_MODES = {
190190 switch (curNav.mode) {
191191 case NAV_MODES.API:
192192 case NAV_MODES.API_INTERNAL:
193 let list = curNav.pkgNames.concat(curNav.declNames);
193 let list = curNav.modNames.concat(curNav.declNames);
194194 if (list.length === 0) {
195 document.title = zigAnalysis.packages[zigAnalysis.rootPkg].name + suffix;
195 document.title = zigAnalysis.modules[zigAnalysis.rootMod].name + suffix;
196196 } else {
197197 document.title = list.join(".") + suffix;
198198 }
......@@ -406,7 +406,7 @@ const NAV_MODES = {
406406
407407 // sidebar guides list
408408 const section_list = zigAnalysis.guide_sections;
409 resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="packages"></ul></div>');
409 resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="modules"></ul></div>');
410410 for (let j = 0; j < section_list.length; j += 1) {
411411 const section = section_list[j];
412412 const domSectionName = domGuidesList.children[j].children[0].children[0];
......@@ -445,7 +445,7 @@ const NAV_MODES = {
445445 }
446446
447447 if (activeGuide == undefined) {
448 const root_file_idx = zigAnalysis.packages[zigAnalysis.rootPkg].file;
448 const root_file_idx = zigAnalysis.modules[zigAnalysis.rootMod].file;
449449 const root_file_name = getFile(root_file_idx).name;
450450 domGuides.innerHTML = markdown(`
451451 # Zig Guides
......@@ -492,8 +492,8 @@ const NAV_MODES = {
492492 domFnProto.classList.add("hidden");
493493 domSectParams.classList.add("hidden");
494494 domTldDocs.classList.add("hidden");
495 domSectMainPkg.classList.add("hidden");
496 domSectPkgs.classList.add("hidden");
495 domSectMainMod.classList.add("hidden");
496 domSectMods.classList.add("hidden");
497497 domSectTypes.classList.add("hidden");
498498 domSectTests.classList.add("hidden");
499499 domSectDocTests.classList.add("hidden");
......@@ -518,7 +518,7 @@ const NAV_MODES = {
518518
519519 renderTitle();
520520 renderInfo();
521 renderPkgList();
521 renderModList();
522522
523523 domPrivDeclsBox.checked = curNav.mode == NAV_MODES.API_INTERNAL;
524524
......@@ -526,19 +526,19 @@ const NAV_MODES = {
526526 return renderSearch();
527527 }
528528
529 let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
530 let pkg = rootPkg;
531 curNav.pkgObjs = [pkg];
532 for (let i = 1; i < curNav.pkgNames.length; i += 1) {
533 let childPkg = zigAnalysis.packages[pkg.table[curNav.pkgNames[i]]];
534 if (childPkg == null) {
529 let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
530 let mod = rootMod;
531 curNav.modObjs = [mod];
532 for (let i = 1; i < curNav.modNames.length; i += 1) {
533 let childMod = zigAnalysis.modules[mod.table[curNav.modNames[i]]];
534 if (childMod == null) {
535535 return render404();
536536 }
537 pkg = childPkg;
538 curNav.pkgObjs.push(pkg);
537 mod = childMod;
538 curNav.modObjs.push(mod);
539539 }
540540
541 let currentType = getType(pkg.main);
541 let currentType = getType(mod.main);
542542 curNav.declObjs = [currentType];
543543 for (let i = 0; i < curNav.declNames.length; i += 1) {
544544 let childDecl = findSubDecl(currentType, curNav.declNames[i]);
......@@ -818,24 +818,24 @@ const NAV_MODES = {
818818 }
819819
820820 function renderNav() {
821 let len = curNav.pkgNames.length + curNav.declNames.length;
821 let len = curNav.modNames.length + curNav.declNames.length;
822822 resizeDomList(domListNav, len, '<li><a href="#"></a></li>');
823823 let list = [];
824 let hrefPkgNames = [];
824 let hrefModNames = [];
825825 let hrefDeclNames = [];
826 for (let i = 0; i < curNav.pkgNames.length; i += 1) {
827 hrefPkgNames.push(curNav.pkgNames[i]);
828 let name = curNav.pkgNames[i];
826 for (let i = 0; i < curNav.modNames.length; i += 1) {
827 hrefModNames.push(curNav.modNames[i]);
828 let name = curNav.modNames[i];
829829 list.push({
830830 name: name,
831 link: navLink(hrefPkgNames, hrefDeclNames),
831 link: navLink(hrefModNames, hrefDeclNames),
832832 });
833833 }
834834 for (let i = 0; i < curNav.declNames.length; i += 1) {
835835 hrefDeclNames.push(curNav.declNames[i]);
836836 list.push({
837837 name: curNav.declNames[i],
838 link: navLink(hrefPkgNames, hrefDeclNames),
838 link: navLink(hrefModNames, hrefDeclNames),
839839 });
840840 }
841841
......@@ -866,29 +866,29 @@ const NAV_MODES = {
866866 domStatus.classList.remove("hidden");
867867 }
868868
869 function renderPkgList() {
870 const rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
869 function renderModList() {
870 const rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
871871 let list = [];
872 for (let key in rootPkg.table) {
873 let pkgIndex = rootPkg.table[key];
874 if (zigAnalysis.packages[pkgIndex] == null) continue;
875 if (key == rootPkg.name) continue;
872 for (let key in rootMod.table) {
873 let modIndex = rootMod.table[key];
874 if (zigAnalysis.modules[modIndex] == null) continue;
875 if (key == rootMod.name) continue;
876876 list.push({
877877 name: key,
878 pkg: pkgIndex,
878 mod: modIndex,
879879 });
880880 }
881881
882882 {
883 let aDom = domSectMainPkg.children[1].children[0].children[0];
884 aDom.textContent = rootPkg.name;
885 aDom.setAttribute("href", navLinkPkg(zigAnalysis.rootPkg));
886 if (rootPkg.name === curNav.pkgNames[0]) {
883 let aDom = domSectMainMod.children[1].children[0].children[0];
884 aDom.textContent = rootMod.name;
885 aDom.setAttribute("href", navLinkMod(zigAnalysis.rootMod));
886 if (rootMod.name === curNav.modNames[0]) {
887887 aDom.classList.add("active");
888888 } else {
889889 aDom.classList.remove("active");
890890 }
891 domSectMainPkg.classList.remove("hidden");
891 domSectMainMod.classList.remove("hidden");
892892 }
893893
894894 list.sort(function (a, b) {
......@@ -896,45 +896,45 @@ const NAV_MODES = {
896896 });
897897
898898 if (list.length !== 0) {
899 resizeDomList(domListPkgs, list.length, '<li><a href="#"></a></li>');
899 resizeDomList(domListMods, list.length, '<li><a href="#"></a></li>');
900900 for (let i = 0; i < list.length; i += 1) {
901 let liDom = domListPkgs.children[i];
901 let liDom = domListMods.children[i];
902902 let aDom = liDom.children[0];
903903 aDom.textContent = list[i].name;
904 aDom.setAttribute("href", navLinkPkg(list[i].pkg));
905 if (list[i].name === curNav.pkgNames[0]) {
904 aDom.setAttribute("href", navLinkMod(list[i].mod));
905 if (list[i].name === curNav.modNames[0]) {
906906 aDom.classList.add("active");
907907 } else {
908908 aDom.classList.remove("active");
909909 }
910910 }
911911
912 domSectPkgs.classList.remove("hidden");
912 domSectMods.classList.remove("hidden");
913913 }
914914 }
915915
916 function navLink(pkgNames, declNames, callName) {
916 function navLink(modNames, declNames, callName) {
917917 let base = curNav.mode;
918918
919 if (pkgNames.length === 0 && declNames.length === 0) {
919 if (modNames.length === 0 && declNames.length === 0) {
920920 return base;
921921 } else if (declNames.length === 0 && callName == null) {
922 return base + pkgNames.join(".");
922 return base + modNames.join(".");
923923 } else if (callName == null) {
924 return base + pkgNames.join(".") + ":" + declNames.join(".");
924 return base + modNames.join(".") + ":" + declNames.join(".");
925925 } else {
926926 return (
927 base + pkgNames.join(".") + ":" + declNames.join(".") + ";" + callName
927 base + modNames.join(".") + ":" + declNames.join(".") + ";" + callName
928928 );
929929 }
930930 }
931931
932 function navLinkPkg(pkgIndex) {
933 return navLink(canonPkgPaths[pkgIndex], []);
932 function navLinkMod(modIndex) {
933 return navLink(canonModPaths[modIndex], []);
934934 }
935935
936936 function navLinkDecl(childName) {
937 return navLink(curNav.pkgNames, curNav.declNames.concat([childName]));
937 return navLink(curNav.modNames, curNav.declNames.concat([childName]));
938938 }
939939
940940 function findDeclNavLink(declName) {
......@@ -946,12 +946,12 @@ const NAV_MODES = {
946946 const curDeclName = curNav.declNames[i - 1];
947947 if (curDeclName == declName) {
948948 const declPath = curNav.declNames.slice(0, i);
949 return navLink(curNav.pkgNames, declPath);
949 return navLink(curNav.modNames, declPath);
950950 }
951951
952952 if (findSubDecl(curDecl, declName) != null) {
953953 const declPath = curNav.declNames.slice(0, i).concat([declName]);
954 return navLink(curNav.pkgNames, declPath);
954 return navLink(curNav.modNames, declPath);
955955 }
956956 }
957957
......@@ -972,7 +972,7 @@ const NAV_MODES = {
972972 // callName += ')';
973973
974974 // declNamesCopy.push(callName);
975 // return navLink(curNav.pkgNames, declNamesCopy);
975 // return navLink(curNav.modNames, declNamesCopy);
976976 // }
977977
978978 function resizeDomListDl(dlDom, desiredLen) {
......@@ -2396,7 +2396,7 @@ const NAV_MODES = {
23962396 if (
23972397 rootIsStd &&
23982398 typeObj ===
2399 getType(zigAnalysis.packages[zigAnalysis.rootPkg].main)
2399 getType(zigAnalysis.modules[zigAnalysis.rootMod].main)
24002400 ) {
24012401 name = "std";
24022402 } else {
......@@ -2702,7 +2702,7 @@ const NAV_MODES = {
27022702 const srcNode = getAstNode(decl.src);
27032703 const srcFile = getFile(srcNode.file);
27042704 return sourceFileUrlTemplate.
2705 replace("{{pkg}}", zigAnalysis.packages[srcFile.pkgIndex].name).
2705 replace("{{mod}}", zigAnalysis.modules[srcFile.modIndex].name).
27062706 replace("{{file}}", srcFile.name).
27072707 replace("{{line}}", srcNode.line + 1);
27082708 }
......@@ -3050,14 +3050,14 @@ const NAV_MODES = {
30503050 }
30513051
30523052 function detectRootIsStd() {
3053 let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
3054 if (rootPkg.table["std"] == null) {
3055 // no std mapped into the root package
3053 let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
3054 if (rootMod.table["std"] == null) {
3055 // no std mapped into the root module
30563056 return false;
30573057 }
3058 let stdPkg = zigAnalysis.packages[rootPkg.table["std"]];
3059 if (stdPkg == null) return false;
3060 return rootPkg.file === stdPkg.file;
3058 let stdMod = zigAnalysis.modules[rootMod.table["std"]];
3059 if (stdMod == null) return false;
3060 return rootMod.file === stdMod.file;
30613061 }
30623062
30633063 function indexTypeKinds() {
......@@ -3112,8 +3112,8 @@ const NAV_MODES = {
31123112 function updateCurNav() {
31133113 curNav = {
31143114 mode: NAV_MODES.API,
3115 pkgNames: [],
3116 pkgObjs: [],
3115 modNames: [],
3116 modObjs: [],
31173117 declNames: [],
31183118 declObjs: [],
31193119 callName: null,
......@@ -3123,11 +3123,11 @@ const NAV_MODES = {
31233123 const mode = location.hash.substring(0, 3);
31243124 let query = location.hash.substring(3);
31253125
3126 const DEFAULT_HASH = NAV_MODES.API + zigAnalysis.packages[zigAnalysis.rootPkg].name;
3126 const DEFAULT_HASH = NAV_MODES.API + zigAnalysis.modules[zigAnalysis.rootMod].name;
31273127 switch (mode) {
31283128 case NAV_MODES.API:
31293129 case NAV_MODES.API_INTERNAL:
3130 // #A;PACKAGE:decl.decl.decl?search-term
3130 // #A;MODULE:decl.decl.decl?search-term
31313131 curNav.mode = mode;
31323132
31333133 let qpos = query.indexOf("?");
......@@ -3143,7 +3143,7 @@ const NAV_MODES = {
31433143 if (parts[0] == "") {
31443144 location.hash = DEFAULT_HASH;
31453145 } else {
3146 curNav.pkgNames = decodeURIComponent(parts[0]).split(".");
3146 curNav.modNames = decodeURIComponent(parts[0]).split(".");
31473147 }
31483148
31493149 if (parts[1] != null) {
......@@ -3249,30 +3249,30 @@ const NAV_MODES = {
32493249 return null;
32503250 }
32513251
3252 function computeCanonicalPackagePaths() {
3253 let list = new Array(zigAnalysis.packages.length);
3254 // Now we try to find all the packages from root.
3255 let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
3252 function computeCanonicalModulePaths() {
3253 let list = new Array(zigAnalysis.modules.length);
3254 // Now we try to find all the modules from root.
3255 let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
32563256 // Breadth-first to keep the path shortest possible.
32573257 let stack = [
32583258 {
32593259 path: [],
3260 pkg: rootPkg,
3260 mod: rootMod,
32613261 },
32623262 ];
32633263 while (stack.length !== 0) {
32643264 let item = stack.shift();
3265 for (let key in item.pkg.table) {
3266 let childPkgIndex = item.pkg.table[key];
3267 if (list[childPkgIndex] != null) continue;
3268 let childPkg = zigAnalysis.packages[childPkgIndex];
3269 if (childPkg == null) continue;
3265 for (let key in item.mod.table) {
3266 let childModIndex = item.mod.table[key];
3267 if (list[childModIndex] != null) continue;
3268 let childMod = zigAnalysis.modules[childModIndex];
3269 if (childMod == null) continue;
32703270
32713271 let newPath = item.path.concat([key]);
3272 list[childPkgIndex] = newPath;
3272 list[childModIndex] = newPath;
32733273 stack.push({
32743274 path: newPath,
3275 pkg: childPkg,
3275 mod: childMod,
32763276 });
32773277 }
32783278 }
......@@ -3283,15 +3283,15 @@ const NAV_MODES = {
32833283 let list = new Array(zigAnalysis.decls.length);
32843284 canonTypeDecls = new Array(zigAnalysis.types.length);
32853285
3286 for (let pkgI = 0; pkgI < zigAnalysis.packages.length; pkgI += 1) {
3287 let pkg = zigAnalysis.packages[pkgI];
3288 let pkgNames = canonPkgPaths[pkgI];
3289 if (pkgNames === undefined) continue;
3286 for (let modI = 0; modI < zigAnalysis.modules.length; modI += 1) {
3287 let mod = zigAnalysis.modules[modI];
3288 let modNames = canonModPaths[modI];
3289 if (modNames === undefined) continue;
32903290
32913291 let stack = [
32923292 {
32933293 declNames: [],
3294 type: getType(pkg.main),
3294 type: getType(mod.main),
32953295 },
32963296 ];
32973297 while (stack.length !== 0) {
......@@ -3323,12 +3323,12 @@ const NAV_MODES = {
33233323 if (childDecl.is_uns) {
33243324 unsDeclList.push(childDecl);
33253325 } else {
3326 addDeclToSearchResults(childDecl, childDeclIndex, pkgNames, item, list, stack);
3326 addDeclToSearchResults(childDecl, childDeclIndex, modNames, item, list, stack);
33273327 }
33283328 }
33293329 }
33303330 } else {
3331 addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack);
3331 addDeclToSearchResults(decl, declIndex, modNames, item, list, stack);
33323332 }
33333333 }
33343334 }
......@@ -3337,13 +3337,13 @@ const NAV_MODES = {
33373337 return list;
33383338 }
33393339
3340function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
3340function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
33413341 let declVal = resolveValue(decl.value);
33423342 let declNames = item.declNames.concat([decl.name]);
33433343
33443344 if (list[declIndex] != null) return;
33453345 list[declIndex] = {
3346 pkgNames: pkgNames,
3346 modNames: modNames,
33473347 declNames: declNames,
33483348 };
33493349
......@@ -3677,8 +3677,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
36773677 const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx);
36783678 if (!canonPath) return;
36793679
3680 let lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];
3681 let fullPath = lastPkgName + ":" + canonPath.declNames.join(".");
3680 let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
3681 let fullPath = lastModName + ":" + canonPath.declNames.join(".");
36823682
36833683 separator = '.';
36843684 result = "#A;" + fullPath;
......@@ -3688,8 +3688,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
36883688 }
36893689
36903690 if (!curDeclOrType) {
3691 for (let i = 0; i < zigAnalysis.packages.length; i += 1){
3692 const p = zigAnalysis.packages[i];
3691 for (let i = 0; i < zigAnalysis.modules.length; i += 1){
3692 const p = zigAnalysis.modules[i];
36933693 if (p.name == components[0]) {
36943694 curDeclOrType = getType(p.main);
36953695 result += "#A;" + components[0];
......@@ -4005,9 +4005,9 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
40054005 if (canonPath == null) continue;
40064006
40074007 let decl = getDecl(declIndex);
4008 let lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];
4008 let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
40094009 let fullPathSearchText =
4010 lastPkgName + "." + canonPath.declNames.join(".");
4010 lastModName + "." + canonPath.declNames.join(".");
40114011 let astNode = getAstNode(decl.src);
40124012 let fileAndDocs = ""; //zigAnalysis.files[astNode.file];
40134013 // TODO: understand what this piece of code is trying to achieve
......@@ -4074,10 +4074,10 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
40744074
40754075 for (let i = 0; i < matchedItems.length; i += 1) {
40764076 const match = matchedItems[i];
4077 const lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1];
4077 const lastModName = match.path.modNames[match.path.modNames.length - 1];
40784078
4079 const text = lastPkgName + "." + match.path.declNames.join(".");
4080 const href = navLink(match.path.pkgNames, match.path.declNames);
4079 const text = lastModName + "." + match.path.declNames.join(".");
4080 const href = navLink(match.path.modNames, match.path.declNames);
40814081
40824082 matchedItemsHTML += "<li><a href=\"" + href + "\">" + text + "</a></li>";
40834083 }
......@@ -4156,7 +4156,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
41564156 const file = zigAnalysis.files[idx];
41574157 return {
41584158 name: file[0],
4159 pkgIndex: file[1],
4159 modIndex: file[1],
41604160 };
41614161 }
41624162
src/Autodoc.zig+60-60
......@@ -4,23 +4,23 @@ const build_options = @import("build_options");
44const Ast = std.zig.Ast;
55const Autodoc = @This();
66const Compilation = @import("Compilation.zig");
7const Module = @import("Module.zig");
8const File = Module.File;
9const Package = @import("Package.zig");
7const CompilationModule = @import("Module.zig");
8const File = CompilationModule.File;
9const Module = @import("Package.zig");
1010const Tokenizer = std.zig.Tokenizer;
1111const Zir = @import("Zir.zig");
1212const Ref = Zir.Inst.Ref;
1313const log = std.log.scoped(.autodoc);
14const Docgen = @import("autodoc/render_source.zig");
14const renderer = @import("autodoc/render_source.zig");
1515
16module: *Module,
16comp_module: *CompilationModule,
1717doc_location: Compilation.EmitLoc,
1818arena: std.mem.Allocator,
1919
2020// The goal of autodoc is to fill up these arrays
2121// that will then be serialized as JSON and consumed
2222// by the JS frontend.
23packages: std.AutoArrayHashMapUnmanaged(*Package, DocData.DocPackage) = .{},
23modules: std.AutoArrayHashMapUnmanaged(*Module, DocData.DocModule) = .{},
2424files: std.AutoArrayHashMapUnmanaged(*File, usize) = .{},
2525calls: std.ArrayListUnmanaged(DocData.Call) = .{},
2626types: std.ArrayListUnmanaged(DocData.Type) = .{},
......@@ -74,10 +74,10 @@ const Section = struct {
7474};
7575
7676var arena_allocator: std.heap.ArenaAllocator = undefined;
77pub fn init(m: *Module, doc_location: Compilation.EmitLoc) Autodoc {
77pub fn init(m: *CompilationModule, doc_location: Compilation.EmitLoc) Autodoc {
7878 arena_allocator = std.heap.ArenaAllocator.init(m.gpa);
7979 return .{
80 .module = m,
80 .comp_module = m,
8181 .doc_location = doc_location,
8282 .arena = arena_allocator.allocator(),
8383 };
......@@ -97,15 +97,15 @@ pub fn generateZirData(self: *Autodoc) !void {
9797
9898 log.debug("Ref map size: {}", .{Ref.typed_value_map.len});
9999
100 const root_src_dir = self.module.main_pkg.root_src_directory;
101 const root_src_path = self.module.main_pkg.root_src_path;
100 const root_src_dir = self.comp_module.main_pkg.root_src_directory;
101 const root_src_path = self.comp_module.main_pkg.root_src_path;
102102 const joined_src_path = try root_src_dir.join(self.arena, &.{root_src_path});
103103 defer self.arena.free(joined_src_path);
104104
105105 const abs_root_src_path = try std.fs.path.resolve(self.arena, &.{ ".", joined_src_path });
106106 defer self.arena.free(abs_root_src_path);
107107
108 const file = self.module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table
108 const file = self.comp_module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table
109109 // Append all the types in Zir.Inst.Ref.
110110 {
111111 try self.types.append(self.arena, .{
......@@ -207,20 +207,20 @@ pub fn generateZirData(self: *Autodoc) !void {
207207 }
208208
209209 const rootName = blk: {
210 const rootName = std.fs.path.basename(self.module.main_pkg.root_src_path);
210 const rootName = std.fs.path.basename(self.comp_module.main_pkg.root_src_path);
211211 break :blk rootName[0 .. rootName.len - 4];
212212 };
213213
214214 const main_type_index = self.types.items.len;
215215 {
216 try self.packages.put(self.arena, self.module.main_pkg, .{
216 try self.modules.put(self.arena, self.comp_module.main_pkg, .{
217217 .name = rootName,
218218 .main = main_type_index,
219219 .table = .{},
220220 });
221 try self.packages.entries.items(.value)[0].table.put(
221 try self.modules.entries.items(.value)[0].table.put(
222222 self.arena,
223 self.module.main_pkg,
223 self.comp_module.main_pkg,
224224 .{
225225 .name = rootName,
226226 .value = 0,
......@@ -257,7 +257,7 @@ pub fn generateZirData(self: *Autodoc) !void {
257257
258258 var data = DocData{
259259 .params = .{},
260 .packages = self.packages,
260 .modules = self.modules,
261261 .files = self.files,
262262 .calls = self.calls.items,
263263 .types = self.types.items,
......@@ -269,7 +269,7 @@ pub fn generateZirData(self: *Autodoc) !void {
269269 };
270270
271271 const base_dir = self.doc_location.directory orelse
272 self.module.zig_cache_artifact_directory;
272 self.comp_module.zig_cache_artifact_directory;
273273
274274 base_dir.handle.makeDir(self.doc_location.basename) catch |e| switch (e) {
275275 error.PathAlreadyExists => {},
......@@ -279,7 +279,7 @@ pub fn generateZirData(self: *Autodoc) !void {
279279 const output_dir = if (self.doc_location.directory) |d|
280280 try d.handle.openDir(self.doc_location.basename, .{})
281281 else
282 try self.module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{});
282 try self.comp_module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{});
283283
284284 {
285285 const data_js_f = try output_dir.createFile("data.js", .{});
......@@ -316,8 +316,8 @@ pub fn generateZirData(self: *Autodoc) !void {
316316
317317 while (files_iterator.next()) |entry| {
318318 const sub_file_path = entry.key_ptr.*.sub_file_path;
319 const file_package = entry.key_ptr.*.pkg;
320 const package_name = (self.packages.get(file_package) orelse continue).name;
319 const file_module = entry.key_ptr.*.pkg;
320 const module_name = (self.modules.get(file_module) orelse continue).name;
321321
322322 const file_path = std.fs.path.dirname(sub_file_path) orelse "";
323323 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 {
325325 const html_file_name = try std.mem.concat(self.arena, u8, &.{ file_name, ".html" });
326326 defer self.arena.free(html_file_name);
327327
328 const dir_name = try std.fs.path.join(self.arena, &.{ package_name, file_path });
328 const dir_name = try std.fs.path.join(self.arena, &.{ module_name, file_path });
329329 defer self.arena.free(dir_name);
330330
331331 var dir = try html_dir.makeOpenPath(dir_name, .{});
......@@ -340,13 +340,13 @@ pub fn generateZirData(self: *Autodoc) !void {
340340
341341 const out = buffer.writer();
342342
343 try Docgen.genHtml(self.module.gpa, entry.key_ptr.*, out);
343 try renderer.genHtml(self.comp_module.gpa, entry.key_ptr.*, out);
344344 try buffer.flush();
345345 }
346346 }
347347
348348 // copy main.js, index.html
349 var docs_dir = try self.module.comp.zig_lib_directory.handle.openDir("docs", .{});
349 var docs_dir = try self.comp_module.comp.zig_lib_directory.handle.openDir("docs", .{});
350350 defer docs_dir.close();
351351 try docs_dir.copyFile("main.js", output_dir, "main.js", .{});
352352 try docs_dir.copyFile("index.html", output_dir, "index.html", .{});
......@@ -407,7 +407,7 @@ const Scope = struct {
407407/// The output of our analysis process.
408408const DocData = struct {
409409 typeKinds: []const []const u8 = std.meta.fieldNames(DocTypeKinds),
410 rootPkg: u32 = 0,
410 rootMod: u32 = 0,
411411 params: struct {
412412 zigId: []const u8 = "arst",
413413 zigVersion: []const u8 = build_options.version,
......@@ -416,7 +416,7 @@ const DocData = struct {
416416 .{ .target = "arst" },
417417 },
418418 },
419 packages: std.AutoArrayHashMapUnmanaged(*Package, DocPackage),
419 modules: std.AutoArrayHashMapUnmanaged(*Module, DocModule),
420420 errors: []struct {} = &.{},
421421
422422 // non-hardcoded stuff
......@@ -448,10 +448,10 @@ const DocData = struct {
448448 const f_name = @tagName(f);
449449 try jsw.objectField(f_name);
450450 switch (f) {
451 .files => try writeFileTableToJson(self.files, self.packages, &jsw),
451 .files => try writeFileTableToJson(self.files, self.modules, &jsw),
452452 .guide_sections => try writeGuidesToJson(self.guide_sections, &jsw),
453 .packages => {
454 try std.json.stringify(self.packages.values(), opts, w);
453 .modules => {
454 try std.json.stringify(self.modules.values(), opts, w);
455455 jsw.state_index -= 1;
456456 },
457457 else => {
......@@ -477,18 +477,18 @@ const DocData = struct {
477477 const ComptimeExpr = struct {
478478 code: []const u8,
479479 };
480 const DocPackage = struct {
480 const DocModule = struct {
481481 name: []const u8 = "(root)",
482482 file: usize = 0, // index into `files`
483483 main: usize = 0, // index into `types`
484 table: std.AutoHashMapUnmanaged(*Package, TableEntry),
484 table: std.AutoHashMapUnmanaged(*Module, TableEntry),
485485 pub const TableEntry = struct {
486486 name: []const u8,
487487 value: usize,
488488 };
489489
490490 pub fn jsonStringify(
491 self: DocPackage,
491 self: DocModule,
492492 opts: std.json.StringifyOptions,
493493 w: anytype,
494494 ) !void {
......@@ -496,11 +496,11 @@ const DocData = struct {
496496 if (opts.whitespace) |ws| jsw.whitespace = ws;
497497
498498 try jsw.beginObject();
499 inline for (comptime std.meta.tags(std.meta.FieldEnum(DocPackage))) |f| {
499 inline for (comptime std.meta.tags(std.meta.FieldEnum(DocModule))) |f| {
500500 const f_name = @tagName(f);
501501 try jsw.objectField(f_name);
502502 switch (f) {
503 .table => try writePackageTableToJson(self.table, &jsw),
503 .table => try writeModuleTableToJson(self.table, &jsw),
504504 else => {
505505 try std.json.stringify(@field(self, f_name), opts, w);
506506 jsw.state_index -= 1;
......@@ -917,23 +917,23 @@ fn walkInstruction(
917917
918918 // importFile cannot error out since all files
919919 // are already loaded at this point
920 if (file.pkg.table.get(path)) |other_package| {
921 const result = try self.packages.getOrPut(self.arena, other_package);
920 if (file.pkg.table.get(path)) |other_module| {
921 const result = try self.modules.getOrPut(self.arena, other_module);
922922
923 // Immediately add this package to the import table of our
924 // current package, regardless of wether it's new or not.
925 if (self.packages.getPtr(file.pkg)) |current_package| {
923 // Immediately add this module to the import table of our
924 // current module, regardless of wether it's new or not.
925 if (self.modules.getPtr(file.pkg)) |current_module| {
926926 // TODO: apparently, in the stdlib a file gets analized before
927 // its package gets added. I guess we're importing a file
928 // that belongs to another package through its file path?
929 // (ie not through its package name).
927 // its module gets added. I guess we're importing a file
928 // that belongs to another module through its file path?
929 // (ie not through its module name).
930930 // We're bailing for now, but maybe we shouldn't?
931 _ = try current_package.table.getOrPutValue(
931 _ = try current_module.table.getOrPutValue(
932932 self.arena,
933 other_package,
933 other_module,
934934 .{
935935 .name = path,
936 .value = self.packages.getIndex(other_package).?,
936 .value = self.modules.getIndex(other_module).?,
937937 },
938938 );
939939 }
......@@ -945,7 +945,7 @@ fn walkInstruction(
945945 };
946946 }
947947
948 // create a new package entry
948 // create a new module entry
949949 const main_type_index = self.types.items.len;
950950 result.value_ptr.* = .{
951951 .name = path,
......@@ -953,18 +953,18 @@ fn walkInstruction(
953953 .table = .{},
954954 };
955955
956 // TODO: Add this package as a dependency to the current package
956 // TODO: Add this module as a dependency to the current module
957957 // TODO: this seems something that could be done in bulk
958958 // at the beginning or the end, or something.
959 const root_src_dir = other_package.root_src_directory;
960 const root_src_path = other_package.root_src_path;
959 const root_src_dir = other_module.root_src_directory;
960 const root_src_path = other_module.root_src_path;
961961 const joined_src_path = try root_src_dir.join(self.arena, &.{root_src_path});
962962 defer self.arena.free(joined_src_path);
963963
964964 const abs_root_src_path = try std.fs.path.resolve(self.arena, &.{ ".", joined_src_path });
965965 defer self.arena.free(abs_root_src_path);
966966
967 const new_file = self.module.import_table.get(abs_root_src_path).?;
967 const new_file = self.comp_module.import_table.get(abs_root_src_path).?;
968968
969969 var root_scope = Scope{
970970 .parent = null,
......@@ -985,7 +985,7 @@ fn walkInstruction(
985985 );
986986 }
987987
988 const new_file = self.module.importFile(file, path) catch unreachable;
988 const new_file = self.comp_module.importFile(file, path) catch unreachable;
989989 const result = try self.files.getOrPut(self.arena, new_file.file);
990990 if (result.found_existing) {
991991 return DocData.WalkResult{
......@@ -3189,7 +3189,7 @@ fn analyzeDecl(
31893189
31903190 // const pl_node = data[Zir.refToIndex(func_index).?].pl_node;
31913191 // const fn_src = try self.srcLocInfo(file, pl_node.src_node, decl_src);
3192 // const tree = try file.getTree(self.module.gpa);
3192 // const tree = try file.getTree(self.comp_module.gpa);
31933193 // const test_source_code = tree.getNodeSource(fn_src.src_node);
31943194
31953195 // const ast_node_index = self.ast_nodes.items.len;
......@@ -4638,7 +4638,7 @@ fn cteTodo(self: *Autodoc, msg: []const u8) error{OutOfMemory}!DocData.WalkResul
46384638
46394639fn writeFileTableToJson(
46404640 map: std.AutoArrayHashMapUnmanaged(*File, usize),
4641 pkgs: std.AutoArrayHashMapUnmanaged(*Package, DocData.DocPackage),
4641 mods: std.AutoArrayHashMapUnmanaged(*Module, DocData.DocModule),
46424642 jsw: anytype,
46434643) !void {
46444644 try jsw.beginArray();
......@@ -4649,7 +4649,7 @@ fn writeFileTableToJson(
46494649 try jsw.arrayElem();
46504650 try jsw.emitString(entry.key_ptr.*.sub_file_path);
46514651 try jsw.arrayElem();
4652 try jsw.emitNumber(pkgs.getIndex(entry.key_ptr.*.pkg) orelse 0);
4652 try jsw.emitNumber(mods.getIndex(entry.key_ptr.*.pkg) orelse 0);
46534653 try jsw.endArray();
46544654 }
46554655 try jsw.endArray();
......@@ -4690,8 +4690,8 @@ fn writeGuidesToJson(sections: std.ArrayListUnmanaged(Section), jsw: anytype) !v
46904690 try jsw.endArray();
46914691}
46924692
4693fn writePackageTableToJson(
4694 map: std.AutoHashMapUnmanaged(*Package, DocData.DocPackage.TableEntry),
4693fn writeModuleTableToJson(
4694 map: std.AutoHashMapUnmanaged(*Module, DocData.DocModule.TableEntry),
46954695 jsw: anytype,
46964696) !void {
46974697 try jsw.beginObject();
......@@ -4710,7 +4710,7 @@ fn srcLocInfo(
47104710 parent_src: SrcLocInfo,
47114711) !SrcLocInfo {
47124712 const sn = @intCast(u32, @intCast(i32, parent_src.src_node) + src_node);
4713 const tree = try file.getTree(self.module.gpa);
4713 const tree = try file.getTree(self.comp_module.gpa);
47144714 const node_idx = @bitCast(Ast.Node.Index, sn);
47154715 const tokens = tree.nodes.items(.main_token);
47164716
......@@ -4731,7 +4731,7 @@ fn declIsVar(
47314731 parent_src: SrcLocInfo,
47324732) !bool {
47334733 const sn = @intCast(u32, @intCast(i32, parent_src.src_node) + src_node);
4734 const tree = try file.getTree(self.module.gpa);
4734 const tree = try file.getTree(self.comp_module.gpa);
47354735 const node_idx = @bitCast(Ast.Node.Index, sn);
47364736 const tokens = tree.nodes.items(.main_token);
47374737 const tags = tree.tokens.items(.tag);
......@@ -4743,7 +4743,7 @@ fn declIsVar(
47434743}
47444744
47454745fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 {
4746 const source = (try file.getSource(self.module.gpa)).bytes;
4746 const source = (try file.getSource(self.comp_module.gpa)).bytes;
47474747 var tokenizer = Tokenizer.init(source);
47484748 var tok = tokenizer.next();
47494749 var comment = std.ArrayList(u8).init(self.arena);
......@@ -4782,9 +4782,9 @@ fn findGuidePaths(self: *Autodoc, file: *File, str: []const u8) !void {
47824782fn addGuide(self: *Autodoc, file: *File, guide_path: []const u8, section: *Section) !void {
47834783 if (guide_path.len == 0) return error.MissingAutodocGuideName;
47844784
4785 const cur_pkg_dir_path = file.pkg.root_src_directory.path orelse ".";
4785 const cur_mod_dir_path = file.pkg.root_src_directory.path orelse ".";
47864786 const resolved_path = try std.fs.path.resolve(self.arena, &[_][]const u8{
4787 cur_pkg_dir_path, file.sub_file_path, "..", guide_path,
4787 cur_mod_dir_path, file.sub_file_path, "..", guide_path,
47884788 });
47894789
47904790 var guide_file = try file.pkg.root_src_directory.handle.openFile(resolved_path, .{});