authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-03-24 18:52:07+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log36c4b1aac995a5b0ef273c02c0b2c0271cab6b94
tree45ea2bfae183be0ca36c825d29fde4a1481b4550
parentdf3074aa985da82a01f94ba6b9a43535c7d438a9

autodoc: improve rendering and add "show priv decls" checkbox


3 files changed, 154 insertions(+), 165 deletions(-)

lib/docs/index.html+40-37
...@@ -26,17 +26,17 @@...@@ -26,17 +26,17 @@
26 --search-sh-color: rgba(0, 0, 0, 0.18);26 --search-sh-color: rgba(0, 0, 0, 0.18);
27 --help-sh-color: rgba(0, 0, 0, 0.75);27 --help-sh-color: rgba(0, 0, 0, 0.75);
28 }28 }
29 29
30 html, body { margin: 0; padding:0; height: 100%; }30 html, body { margin: 0; padding:0; height: 100%; }
3131
32 a {32 a {
33 text-decoration: none;33 text-decoration: none;
34 }34 }
35 35
36 a:hover {36 a:hover {
37 text-decoration: underline;37 text-decoration: underline;
38 }38 }
39 39
40 .hidden {40 .hidden {
41 display: none;41 display: none;
42 }42 }
...@@ -58,7 +58,7 @@...@@ -58,7 +58,7 @@
58 width: 100%;58 width: 100%;
59 height: 100%;59 height: 100%;
60 justify-content: center;60 justify-content: center;
61 61
62 z-index: 100;62 z-index: 100;
63 }63 }
6464
...@@ -76,7 +76,7 @@...@@ -76,7 +76,7 @@
76 overflow-wrap: break-word;76 overflow-wrap: break-word;
77 flex-shrink: 0;77 flex-shrink: 0;
78 flex-grow: 0;78 flex-grow: 0;
79 79
80 z-index: 300;80 z-index: 300;
81 }81 }
8282
...@@ -86,7 +86,7 @@...@@ -86,7 +86,7 @@
86 -webkit-overflow-scrolling: touch;86 -webkit-overflow-scrolling: touch;
87 flex-grow: 1;87 flex-grow: 1;
88 flex-shrink: 1;88 flex-shrink: 1;
89 89
90 z-index: 200;90 z-index: 200;
91 }91 }
9292
...@@ -95,44 +95,44 @@...@@ -95,44 +95,44 @@
95 max-width: 85vw;95 max-width: 85vw;
96 flex-shrink: 1;96 flex-shrink: 1;
97 }97 }
98 98
99 .help-modal {99 .help-modal {
100 z-index: 400;100 z-index: 400;
101 }101 }
102 102
103 /* sidebar */103 /* sidebar */
104 .sidebar {104 .sidebar {
105 font-size: 1rem;105 font-size: 1rem;
106 background-color: var(--bg-color);106 background-color: var(--bg-color);
107 box-shadow: 0 0 1rem var(--sidebar-sh-color);107 box-shadow: 0 0 1rem var(--sidebar-sh-color);
108 }108 }
109 109
110 .sidebar .logo {110 .sidebar .logo {
111 padding: 1rem 0.35rem 0.35rem 0.35rem;111 padding: 1rem 0.35rem 0.35rem 0.35rem;
112 }112 }
113 113
114 .sidebar .logo > svg {114 .sidebar .logo > svg {
115 display: block;115 display: block;
116 overflow: visible;116 overflow: visible;
117 }117 }
118 118
119 .sidebar h2 {119 .sidebar h2 {
120 margin: 0.5rem;120 margin: 0.5rem;
121 padding: 0;121 padding: 0;
122 font-size: 1.2rem;122 font-size: 1.2rem;
123 }123 }
124 124
125 .sidebar h2 > span {125 .sidebar h2 > span {
126 border-bottom: 0.125rem dotted var(--tx-color);126 border-bottom: 0.125rem dotted var(--tx-color);
127 }127 }
128 128
129 .sidebar .packages {129 .sidebar .packages {
130 list-style-type: none;130 list-style-type: none;
131 margin: 0;131 margin: 0;
132 padding: 0;132 padding: 0;
133 background-color: var(--sidebar-pkg-bg-color);133 background-color: var(--sidebar-pkg-bg-color);
134 }134 }
135 135
136 .sidebar .packages > li > a {136 .sidebar .packages > li > a {
137 display: block;137 display: block;
138 padding: 0.5rem 1rem;138 padding: 0.5rem 1rem;
...@@ -140,17 +140,17 @@...@@ -140,17 +140,17 @@
140 background-color: var(--sidebar-pkglnk-bg-color);140 background-color: var(--sidebar-pkglnk-bg-color);
141 text-decoration: none;141 text-decoration: none;
142 }142 }
143 143
144 .sidebar .packages > li > a:hover {144 .sidebar .packages > li > a:hover {
145 color: var(--sidebar-pkglnk-tx-color-hover);145 color: var(--sidebar-pkglnk-tx-color-hover);
146 background-color: var(--sidebar-pkglnk-bg-color-hover);146 background-color: var(--sidebar-pkglnk-bg-color-hover);
147 }147 }
148 148
149 .sidebar .packages > li > a.active {149 .sidebar .packages > li > a.active {
150 color: var(--sidebar-pkglnk-tx-color-active);150 color: var(--sidebar-pkglnk-tx-color-active);
151 background-color: var(--sidebar-pkglnk-bg-color-active);151 background-color: var(--sidebar-pkglnk-bg-color-active);
152 }152 }
153 153
154 .sidebar p.str {154 .sidebar p.str {
155 margin: 0.5rem;155 margin: 0.5rem;
156 font-family: var(--mono);156 font-family: var(--mono);
...@@ -183,28 +183,28 @@...@@ -183,28 +183,28 @@
183 border-radius: 0;183 border-radius: 0;
184 -webkit-appearance: none;184 -webkit-appearance: none;
185 }185 }
186 186
187 .docs .search:focus {187 .docs .search:focus {
188 background-color: var(--search-bg-color-focus);188 background-color: var(--search-bg-color-focus);
189 border-bottom-color: #ffbb4d;189 border-bottom-color: #ffbb4d;
190 box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color);190 box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color);
191 }191 }
192 192
193 .docs .search::placeholder {193 .docs .search::placeholder {
194 font-size: 1rem;194 font-size: 1rem;
195 font-family: var(--ui);195 font-family: var(--ui);
196 color: var(--tx-color);196 color: var(--tx-color);
197 opacity: 0.5;197 opacity: 0.5;
198 }198 }
199 199
200 .docs a {200 .docs a {
201 color: var(--link-color);201 color: var(--link-color);
202 }202 }
203 203
204 .docs p {204 .docs p {
205 margin: 0.8rem 0;205 margin: 0.8rem 0;
206 }206 }
207 207
208 .docs pre {208 .docs pre {
209 font-family: var(--mono);209 font-family: var(--mono);
210 font-size:1em;210 font-size:1em;
...@@ -212,19 +212,19 @@...@@ -212,19 +212,19 @@
212 padding:1em;212 padding:1em;
213 overflow-x: auto;213 overflow-x: auto;
214 }214 }
215 215
216 .docs code {216 .docs code {
217 font-family: var(--mono);217 font-family: var(--mono);
218 font-size: 1em;218 font-size: 1em;
219 }219 }
220 220
221 .docs h1 {221 .docs h1 {
222 font-size: 1.4em;222 font-size: 1.4em;
223 margin: 0.8em 0;223 margin: 0.8em 0;
224 padding: 0;224 padding: 0;
225 border-bottom: 0.0625rem dashed;225 border-bottom: 0.0625rem dashed;
226 }226 }
227 227
228 .docs h2 {228 .docs h2 {
229 font-size: 1.3em;229 font-size: 1.3em;
230 margin: 0.5em 0;230 margin: 0.5em 0;
...@@ -264,7 +264,7 @@...@@ -264,7 +264,7 @@
264 #tableFnErrors dt {264 #tableFnErrors dt {
265 font-weight: bold;265 font-weight: bold;
266 }266 }
267 267
268 .examples {268 .examples {
269 list-style-type: none;269 list-style-type: none;
270 margin: 0;270 margin: 0;
...@@ -275,7 +275,7 @@...@@ -275,7 +275,7 @@
275 white-space: nowrap;275 white-space: nowrap;
276 overflow-x: auto;276 overflow-x: auto;
277 }277 }
278 278
279 .docs td {279 .docs td {
280 margin: 0;280 margin: 0;
281 padding: 0.5em;281 padding: 0.5em;
...@@ -283,7 +283,7 @@...@@ -283,7 +283,7 @@
283 text-overflow: ellipsis;283 text-overflow: ellipsis;
284 overflow-x: hidden;284 overflow-x: hidden;
285 }285 }
286 286
287 /* help dialog */287 /* help dialog */
288 .help-modal {288 .help-modal {
289 display: flex;289 display: flex;
...@@ -308,23 +308,23 @@...@@ -308,23 +308,23 @@
308 border: 0.125rem solid #000;308 border: 0.125rem solid #000;
309 box-shadow: 0 0.5rem 2.5rem 0.3rem var(--help-sh-color);309 box-shadow: 0 0.5rem 2.5rem 0.3rem var(--help-sh-color);
310 }310 }
311 311
312 .help-modal h1 {312 .help-modal h1 {
313 margin: 0.75em 2.5em 1em 2.5em;313 margin: 0.75em 2.5em 1em 2.5em;
314 font-size: 1.5em;314 font-size: 1.5em;
315 text-align: center;315 text-align: center;
316 }316 }
317 317
318 .help-modal dt, .help-modal dd {318 .help-modal dt, .help-modal dd {
319 display: inline;319 display: inline;
320 margin: 0 0.2em;320 margin: 0 0.2em;
321 }321 }
322 322
323 .help-modal dl {323 .help-modal dl {
324 margin-left: 0.5em;324 margin-left: 0.5em;
325 margin-right: 0.5em;325 margin-right: 0.5em;
326 }326 }
327 327
328 .help-modal kbd {328 .help-modal kbd {
329 display: inline-block;329 display: inline-block;
330 padding: 0.3em 0.2em;330 padding: 0.3em 0.2em;
...@@ -341,7 +341,7 @@...@@ -341,7 +341,7 @@
341 box-shadow: inset 0 -0.0625em 0 #c6cbd1;341 box-shadow: inset 0 -0.0625em 0 #c6cbd1;
342 cursor: default;342 cursor: default;
343 }343 }
344 344
345 /* tokens */345 /* tokens */
346 .tok-kw {346 .tok-kw {
347 color: #333;347 color: #333;
...@@ -371,10 +371,10 @@...@@ -371,10 +371,10 @@
371 color: #458;371 color: #458;
372 font-weight: bold;372 font-weight: bold;
373 }373 }
374 374
375 /* dark mode */375 /* dark mode */
376 @media (prefers-color-scheme: dark) {376 @media (prefers-color-scheme: dark) {
377 377
378 :root {378 :root {
379 --tx-color: #bbb;379 --tx-color: #bbb;
380 --bg-color: #111;380 --bg-color: #111;
...@@ -392,7 +392,7 @@...@@ -392,7 +392,7 @@
392 --search-sh-color: rgba(255, 255, 255, 0.28);392 --search-sh-color: rgba(255, 255, 255, 0.28);
393 --help-sh-color: rgba(142, 142, 142, 0.5);393 --help-sh-color: rgba(142, 142, 142, 0.5);
394 }394 }
395 395
396 .docs pre {396 .docs pre {
397 background-color:#2A2A2A;397 background-color:#2A2A2A;
398 }398 }
...@@ -440,7 +440,7 @@...@@ -440,7 +440,7 @@
440 .tok-type {440 .tok-type {
441 color: #68f;441 color: #68f;
442 }442 }
443 443
444 }444 }
445445
446 @media only screen and (max-width: 750px) {446 @media only screen and (max-width: 750px) {
...@@ -545,6 +545,9 @@...@@ -545,6 +545,9 @@
545 <h2><span>Target</span></h2>545 <h2><span>Target</span></h2>
546 <p class="str" id="tdTarget"></p>546 <p class="str" id="tdTarget"></p>
547 </div>547 </div>
548 <div>
549 <input id="privDeclsBox" type="checkbox"/> Show Private Decls
550 </div>
548 </nav>551 </nav>
549 </div>552 </div>
550 <div class="flex-right">553 <div class="flex-right">
lib/docs/main.js+108-127
...@@ -32,18 +32,6 @@...@@ -32,18 +32,6 @@
32 } TypeKind32 } TypeKind
33*/33*/
3434
35/**
36 * @typedef {
37 | WalkResult
38 | { unspecified: {} }
39 | { anytype: {} }
40 | { type: number }
41 | { comptimeExpr: number }
42 | { call: number }
43 | { hasCte: boolean; declPath: number[] }
44 } TypeRef
45*/
46
47/**35/**
48 * @typedef {36 * @typedef {
49 | { void: {} }37 | { void: {} }
...@@ -52,16 +40,16 @@...@@ -52,16 +40,16 @@
52 | { type: number }40 | { type: number }
53 | { comptimeExpr: number }41 | { comptimeExpr: number }
54 | { call: number }42 | { call: number }
55 | { int: { typeRef: TypeRef; value: number } }43 | { int: { typeRef: WalkResult; value: number } }
56 | { float: { typeRef: TypeRef; value: number } }44 | { float: { typeRef: WalkResult; value: number } }
57 | { bool: boolean }45 | { bool: boolean }
58 | { undefined: TypeRef }46 | { undefined: WalkResult }
59 | { null: TypeRef }47 | { null: WalkResult }
60 | { typeOf: WalkResult }48 | { typeOf: WalkResult }
61 | { compileError: string }49 | { compileError: string }
62 | { string: string }50 | { string: string }
63 | { struct: Struct }51 | { struct: Struct }
64 | { hasCte: boolean; declPath: number[] }52 | { refPath: WalkResult[] }
65 | { array: ZigArray }53 | { array: ZigArray }
66 | { enumLiteral: string }54 | { enumLiteral: string }
67 } WalkResult55 } WalkResult
...@@ -75,8 +63,8 @@...@@ -75,8 +63,8 @@
75 | { len: WalkResult; child: TypeRef } // Array63 | { len: WalkResult; child: TypeRef } // Array
76 | { name: string; fields: { name: string; docs: string }[] } // ErrorSet64 | { name: string; fields: { name: string; docs: string }[] } // ErrorSet
77 | { size: "One" | "Many" | "Slice" | "C"; child: TypeRef } // Pointer65 | { size: "One" | "Many" | "Slice" | "C"; child: TypeRef } // Pointer
78 | { name: string; src?: number; privDecls: number[]; pubDecls: number[]; fields?: TypeRef[] } // Struct, Enum, Union66 | { name: string; src: number; privDecls: number[]; pubDecls: number[]; fields: WalkResult[] } // Struct, Enum, Union
79 | { name: string; src?: number; ret: TypeRef; params?: TypeRef[] } // Fn67 | { name: string; src: number; ret: WalkResult; params: WalkResult[] } // Fn
80 )68 )
81 } Type69 } Type
82*/70*/
...@@ -85,14 +73,14 @@...@@ -85,14 +73,14 @@
85 * @typedef {{73 * @typedef {{
86 name: string,74 name: string,
87 src: number | null,75 src: number | null,
88 ret: TypeRef,76 ret: WalkResult,
89 params: TypeRef[] | null,77 params: WalkResult[] | null,
90 }} Fn78 }} Fn
91*/79*/
9280
93/**81/**
94 * @typedef {{82 * @typedef {{
95 func: TypeRef,83 func: WalkResult,
96 args: WalkResult[],84 args: WalkResult[],
97 ret: WalkResult,85 ret: WalkResult,
98 }} Call86 }} Call
...@@ -135,21 +123,21 @@...@@ -135,21 +123,21 @@
135 src?: number,123 src?: number,
136 privDecls: number[],124 privDecls: number[],
137 pubDecls: number[],125 pubDecls: number[],
138 fields?: TypeRef[],126 fields?: WalkResult[],
139 }} Struct127 }} Struct
140*/128*/
141129
142/**130/**
143 * @typedef {{131 * @typedef {{
144 len: WalkResult,132 len: WalkResult,
145 child: TypeRef,133 child: WalkResult,
146 }} ZigArray134 }} ZigArray
147*/135*/
148136
149/**137/**
150 * @typedef {{138 * @typedef {{
151 code: string,139 code: string,
152 typeRef: TypeRef,140 typeRef: WalkResult,
153 }} ComptimeExpr141 }} ComptimeExpr
154*/142*/
155143
...@@ -219,6 +207,7 @@ var zigAnalysis;...@@ -219,6 +207,7 @@ var zigAnalysis;
219 var domSectSearchNoResults = document.getElementById("sectSearchNoResults");207 var domSectSearchNoResults = document.getElementById("sectSearchNoResults");
220 var domSectInfo = document.getElementById("sectInfo");208 var domSectInfo = document.getElementById("sectInfo");
221 var domTdTarget = document.getElementById("tdTarget");209 var domTdTarget = document.getElementById("tdTarget");
210 var domPrivDeclsBox = document.getElementById("privDeclsBox");
222 var domTdZigVer = document.getElementById("tdZigVer");211 var domTdZigVer = document.getElementById("tdZigVer");
223 var domHdrName = document.getElementById("hdrName");212 var domHdrName = document.getElementById("hdrName");
224 var domHelpModal = document.getElementById("helpDialog");213 var domHelpModal = document.getElementById("helpDialog");
...@@ -238,6 +227,7 @@ var zigAnalysis;...@@ -238,6 +227,7 @@ var zigAnalysis;
238 var canonTypeDecls = null; // lazy; use getCanonTypeDecl227 var canonTypeDecls = null; // lazy; use getCanonTypeDecl
239228
240 var curNav = {229 var curNav = {
230 showPrivDecls: false,
241 // each element is a package name, e.g. @import("a") then within there @import("b")231 // each element is a package name, e.g. @import("a") then within there @import("b")
242 // starting implicitly from root package232 // starting implicitly from root package
243 pkgNames: [],233 pkgNames: [],
...@@ -264,6 +254,18 @@ var zigAnalysis;...@@ -264,6 +254,18 @@ var zigAnalysis;
264 // var nodesToCallsMap = indexNodesToCalls();254 // var nodesToCallsMap = indexNodesToCalls();
265255
266 domSearch.addEventListener('keydown', onSearchKeyDown, false);256 domSearch.addEventListener('keydown', onSearchKeyDown, false);
257 domPrivDeclsBox.addEventListener('change', function() {
258 if (this.checked != curNav.showPrivDecls) {
259 if (this.checked && location.hash.length > 1 && location.hash[1] != '*'){
260 location.hash = "#*" + location.hash.substring(1);
261 return;
262 }
263 if (!this.checked && location.hash.length > 1 && location.hash[1] == '*') {
264 location.hash = "#" + location.hash.substring(2);
265 return;
266 }
267 }
268 }, false);
267 window.addEventListener('hashchange', onHashChange, false);269 window.addEventListener('hashchange', onHashChange, false);
268 window.addEventListener('keydown', onWindowKeyDown, false);270 window.addEventListener('keydown', onWindowKeyDown, false);
269 onHashChange();271 onHashChange();
...@@ -323,19 +325,13 @@ var zigAnalysis;...@@ -323,19 +325,13 @@ var zigAnalysis;
323 return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind);325 return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind);
324 }326 }
325327
326 function findCteInDeclPath(path) {328 function findCteInRefPath(path) {
327 for (var i = path.length - 1; i >= 0; i -= 1) {329 for (var i = path.length - 1; i >= 0; i -= 1) {
328 const decl = zigAnalysis.decls[path[i]];330 const ref = path[i];
329 if ("comptimeExpr" in decl.value) {331 if ("string" in ref) continue;
330 return decl;332 if ("comptimeExpr" in ref) return ref;
331 }333 if ("refPath" in ref) return findCteinRefPath(ref.refPath);
332334 return null;
333 if ("declPath" in decl.value) {
334 const res = findCteInDeclPath(decl.value.declPath);
335 if (res !== null) {
336 return res;
337 }
338 }
339 }335 }
340336
341 return null;337 return null;
...@@ -346,14 +342,15 @@ var zigAnalysis;...@@ -346,14 +342,15 @@ var zigAnalysis;
346 while(i < 1000) {342 while(i < 1000) {
347 i += 1;343 i += 1;
348344
349 if ("declPath" in value) {345 if ("refPath" in value) {
350 if (value.hasCte) {346 value = value.refPath[value.refPath.length -1];
351 return findCteInDeclPath(value.declPath).value;
352 }
353 value = zigAnalysis.decls[value.declPath[0]].value;
354 continue;347 continue;
355 }348 }
356349
350 if ("declRef" in value) {
351 value = zigAnalysis.decls[value.declRef].value;
352 }
353
357 return value;354 return value;
358355
359 }356 }
...@@ -369,13 +366,15 @@ var zigAnalysis;...@@ -369,13 +366,15 @@ var zigAnalysis;
369 return { type: typeTypeId };366 return { type: typeTypeId };
370 }367 }
371368
372 if ("declPath" in decl.value) {369 if ("refPath" in decl.value) {
373 if (decl.value.hasCte) {370 decl = {
374 decl = findCteInDeclPath(decl.value.declPath);371 value: decl.value.refPath[decl.value.refPath.length -1]
375 } else {372 };
376 decl = zigAnalysis.decls[decl.value.declPath[0]];373 continue;
377 }374 }
378375
376 if ("declRef" in decl.value) {
377 decl = zigAnalysis.decls[decl.value.declRef];
379 continue;378 continue;
380 }379 }
381380
...@@ -402,8 +401,14 @@ var zigAnalysis;...@@ -402,8 +401,14 @@ var zigAnalysis;
402401
403 if ("call" in decl.value) {402 if ("call" in decl.value) {
404 const fn_call = zigAnalysis.calls[decl.value.call];403 const fn_call = zigAnalysis.calls[decl.value.call];
405 console.assert("declPath" in fn_call.func);404 var fn_decl = undefined;
406 const fn_decl = zigAnalysis.decls[fn_call.func.declPath[0]];405 if ("declRef" in fn_call.func) {
406 fn_decl = zigAnalysis.decls[fn_call.func.declRef];
407 } else if ("refPath" in fn_call.func) {
408 console.assert("declRef" in fn_call.func.refPath[fn_call.func.refPath.length -1]);
409 fn_decl = zigAnalysis.decls[fn_call.func.refPath[fn_call.func.refPath.length -1].declRef.value];
410 } else throw {};
411
407 const fn_decl_value = resolveValue(fn_decl.value);412 const fn_decl_value = resolveValue(fn_decl.value);
408 console.assert("type" in fn_decl_value); //TODO handle comptimeExpr413 console.assert("type" in fn_decl_value); //TODO handle comptimeExpr
409 const fn_type = zigAnalysis.types[fn_decl_value.type];414 const fn_type = zigAnalysis.types[fn_decl_value.type];
...@@ -456,6 +461,8 @@ var zigAnalysis;...@@ -456,6 +461,8 @@ var zigAnalysis;
456 renderInfo();461 renderInfo();
457 renderPkgList();462 renderPkgList();
458463
464 domPrivDeclsBox.checked = curNav.showPrivDecls;
465
459 if (curNavSearch !== "") {466 if (curNavSearch !== "") {
460 return renderSearch();467 return renderSearch();
461 }468 }
...@@ -547,7 +554,7 @@ var zigAnalysis;...@@ -547,7 +554,7 @@ var zigAnalysis;
547 var typeObj = zigAnalysis.types[typeIndex];554 var typeObj = zigAnalysis.types[typeIndex];
548 if (typeObj.kind !== typeKinds.Struct)555 if (typeObj.kind !== typeKinds.Struct)
549 return false;556 return false;
550 return !typeObj.fields;557 return typeObj.fields.length == 0;
551 }558 }
552559
553 function typeIsGenericFn(typeIndex) {560 function typeIsGenericFn(typeIndex) {
...@@ -850,22 +857,14 @@ var zigAnalysis;...@@ -850,22 +857,14 @@ var zigAnalysis;
850 if ("comptimeExpr" in typeValue) {857 if ("comptimeExpr" in typeValue) {
851 return "[ComptimeExpr]";858 return "[ComptimeExpr]";
852 }859 }
853 if ("declPath" in typeValue) {860 if ("refPath" in typeValue) {
854 var result = "";861 var result = "";
855 for (var j = typeValue.declPath.length - 1; j >= 0; j--) {862 for (var j = 0; j < typeValue.refPath.length; j++) {
856 var decl = zigAnalysis.decls[typeValue.declPath[j]];863
857864 var name = "[RefPath]";
858 // TODO: handle nested decl paths properly!
859 if (typeValue.hasCte) {
860 if (wantHtml)
861 result += "<a href=\"\">[ComptimeExpr]</a>";
862 else
863 result += "[ComptimeExpr]";
864 break;
865 }
866 var name = escapeHtml(decl.name);
867 if (wantHtml) {865 if (wantHtml) {
868 result += '<a href="'+navLinkDecl(decl.name)+'">';866 //result += '<a href="'+navLinkDecl(decl.name)+'">';
867 result += '<a href="">';
869 result += '<span class="tok-kw" style="color:lightblue;">' +868 result += '<span class="tok-kw" style="color:lightblue;">' +
870 name + '</span>';869 name + '</span>';
871 result += '</a>';870 result += '</a>';
...@@ -1182,24 +1181,11 @@ var zigAnalysis;...@@ -1182,24 +1181,11 @@ var zigAnalysis;
11821181
1183 if (isVarArgs && i === typeObj.params.length - 1) {1182 if (isVarArgs && i === typeObj.params.length - 1) {
1184 payloadHtml += '...';1183 payloadHtml += '...';
1185 } else if ("declPath" in value) {1184 } else if ("refPath" in value) {
1186 if (value.hasCte) {1185 payloadHtml += '<a href="">';
1187 var cte = findCteInDeclPath(value.declPath);1186 payloadHtml += '<span class="tok-kw" style="color:lightblue;">[Ref Path]</span>';
1188 payloadHtml += "[ComptimeExpr]";1187 payloadHtml += '</a>';
1189 } else {1188
1190 var decl = zigAnalysis.decls[value.declPath[0]];
1191 var val = resolveValue(decl.value);
1192 if ("comptimeExpr" in val) {
1193 payloadHtml += "[ComptimeExpr]";
1194 } else {
1195 console.assert("type" in val);
1196 var valType = zigAnalysis.types[val.type];
1197 var valTypeName = typeShorthandName(valType);
1198 payloadHtml += '<a href="'+navLinkDecl(decl.name)+'">';
1199 payloadHtml += '<span class="tok-kw" style="color:lightblue;">' + escapeHtml(decl.name) + '</span>';
1200 payloadHtml += '</a>';
1201 }
1202 }
1203 } else if ("type" in value) {1189 } else if ("type" in value) {
1204 var name = typeValueName(value, false);1190 var name = typeValueName(value, false);
1205 payloadHtml += '<span class="tok-kw">' + escapeHtml(name) + '</span>';1191 payloadHtml += '<span class="tok-kw">' + escapeHtml(name) + '</span>';
...@@ -1422,17 +1408,13 @@ var zigAnalysis;...@@ -1422,17 +1408,13 @@ var zigAnalysis;
1422 domFnProto.classList.remove("hidden");1408 domFnProto.classList.remove("hidden");
1423 }1409 }
14241410
1425 function renderContainer(container) {
1426 var typesList = [];
1427 var namespacesList = [];
1428 var errSetsList = [];
1429 var fnsList = [];
1430 var varsList = [];
1431 var valsList = [];
14321411
1433 var declLen = container.pubDecls ? container.pubDecls.length : 0;1412 function categorizeDecls(decls,
1434 for (var i = 0; i < declLen; i += 1) {1413 typesList, namespacesList, errSetsList,
1435 var decl = zigAnalysis.decls[container.pubDecls[i]];1414 fnsList, varsList, valsList) {
1415
1416 for (var i = 0; i < decls.length; i += 1) {
1417 var decl = zigAnalysis.decls[decls[i]];
1436 var declValue = resolveValue(decl.value);1418 var declValue = resolveValue(decl.value);
14371419
1438 if (decl.kind === 'var') {1420 if (decl.kind === 'var') {
...@@ -1441,7 +1423,19 @@ var zigAnalysis;...@@ -1441,7 +1423,19 @@ var zigAnalysis;
1441 }1423 }
14421424
1443 if (decl.kind === 'const') {1425 if (decl.kind === 'const') {
1444 if (!("type" in declValue)){1426 if ("call" in declValue) {
1427 let c = zigAnalysis.calls[declValue.call];
1428 console.assert("comptimeExpr" in c.ret);
1429 let fDecl = resolveValue(c.func);
1430 console.assert("type" in fDecl);
1431 let fType = zigAnalysis.types[fDecl.type];
1432 console.assert("type" in fType.ret);
1433 if (fType.ret.type === typeTypeId) {
1434 typesList.push(decl);
1435 } else {
1436 valsList.push(decl);
1437 }
1438 } else if (!("type" in declValue)){
1445 valsList.push(decl);1439 valsList.push(decl);
1446 } else {1440 } else {
1447 var value = zigAnalysis.types[declValue.type];1441 var value = zigAnalysis.types[declValue.type];
...@@ -1465,42 +1459,23 @@ var zigAnalysis;...@@ -1465,42 +1459,23 @@ var zigAnalysis;
1465 }1459 }
1466 }1460 }
1467 }1461 }
1462 }
14681463
1469 declLen = container.privDecls ? container.privDecls.length : 0;1464 function renderContainer(container) {
1470 for (var i = 0; i < declLen; i += 1) {1465 var typesList = [];
1471 var decl = zigAnalysis.decls[container.privDecls[i]];1466 var namespacesList = [];
1472 var declValue = resolveValue(decl.value);1467 var errSetsList = [];
14731468 var fnsList = [];
1474 if (decl.kind === 'var') {1469 var varsList = [];
1475 varsList.push(decl);1470 var valsList = [];
1476 continue;
1477 }
14781471
1479 if (decl.kind === 'const') {1472 categorizeDecls(container.pubDecls,
1480 if (!("type" in declValue)){1473 typesList, namespacesList, errSetsList,
1481 valsList.push(decl);1474 fnsList, varsList, valsList);
1482 } else {1475 if (curNav.showPrivDecls) categorizeDecls(container.privDecls,
1483 var value = zigAnalysis.types[declValue.type];1476 typesList, namespacesList, errSetsList,
1484 var kind = value.kind;1477 fnsList, varsList, valsList);
1485 if (kind === typeKinds.Fn) {
1486 // TODO: handle CTE return types when we know their type.
1487 const resVal = resolveValue(value.ret);
1488 if ("type" in resVal && resVal.type == typeTypeId) {
1489 typesList.push(decl);
1490 } else {
1491 fnsList.push(decl);
1492 }
14931478
1494 } else if (typeIsErrSet(declValue.type)) {
1495 errSetsList.push(decl);
1496 } else if (typeIsStructWithNoFields(declValue.type)) {
1497 namespacesList.push(decl);
1498 } else {
1499 typesList.push(decl);
1500 }
1501 }
1502 }
1503 }
15041479
1505 typesList.sort(byNameProperty);1480 typesList.sort(byNameProperty);
1506 namespacesList.sort(byNameProperty);1481 namespacesList.sort(byNameProperty);
...@@ -1712,6 +1687,7 @@ var zigAnalysis;...@@ -1712,6 +1687,7 @@ var zigAnalysis;
17121687
1713 function updateCurNav() {1688 function updateCurNav() {
1714 curNav = {1689 curNav = {
1690 showPrivDecls: false,
1715 pkgNames: [],1691 pkgNames: [],
1716 pkgObjs: [],1692 pkgObjs: [],
1717 declNames: [],1693 declNames: [],
...@@ -1721,6 +1697,11 @@ var zigAnalysis;...@@ -1721,6 +1697,11 @@ var zigAnalysis;
17211697
1722 if (location.hash[0] === '#' && location.hash.length > 1) {1698 if (location.hash[0] === '#' && location.hash.length > 1) {
1723 var query = location.hash.substring(1);1699 var query = location.hash.substring(1);
1700 if (query[0] === '*') {
1701 curNav.showPrivDecls = true;
1702 query = query.substring(1);
1703 }
1704
1724 var qpos = query.indexOf("?");1705 var qpos = query.indexOf("?");
1725 var nonSearchPart;1706 var nonSearchPart;
1726 if (qpos === -1) {1707 if (qpos === -1) {
src/Autodoc.zig+6-1
...@@ -608,6 +608,7 @@ const DocData = struct {...@@ -608,6 +608,7 @@ const DocData = struct {
608 \\, "value": {s}1 }} }}608 \\, "value": {s}1 }} }}
609 , .{neg});609 , .{neg});
610 // TODO: uncomment once float panic is fixed in stdlib610 // TODO: uncomment once float panic is fixed in stdlib
611 // See: https://github.com/ziglang/zig/issues/11283
611 // try w.print(612 // try w.print(
612 // \\, "value": {s}{e} }} }}613 // \\, "value": {s}{e} }} }}
613 // , .{ neg, v.value });614 // , .{ neg, v.value });
...@@ -621,7 +622,6 @@ const DocData = struct {...@@ -621,7 +622,6 @@ const DocData = struct {
621 .@"null" => |v| try std.json.stringify(v, options, w),622 .@"null" => |v| try std.json.stringify(v, options, w),
622 .typeOf, .sizeOf => |v| try std.json.stringify(v, options, w),623 .typeOf, .sizeOf => |v| try std.json.stringify(v, options, w),
623 .compileError => |v| try std.json.stringify(v, options, w),624 .compileError => |v| try std.json.stringify(v, options, w),
624 .string => |v| try std.json.stringify(v, options, w),
625 .fieldRef => |v| try std.json.stringify(625 .fieldRef => |v| try std.json.stringify(
626 struct { fieldRef: FieldRef }{ .fieldRef = v },626 struct { fieldRef: FieldRef }{ .fieldRef = v },
627 options,627 options,
...@@ -645,6 +645,11 @@ const DocData = struct {...@@ -645,6 +645,11 @@ const DocData = struct {
645 options,645 options,
646 w,646 w,
647 ),647 ),
648 .string => |v| try std.json.stringify(
649 struct { string: []const u8 }{ .string = v },
650 options,
651 w,
652 ),
648 .enumLiteral => |v| try std.json.stringify(653 .enumLiteral => |v| try std.json.stringify(
649 struct { @"enumLiteral": []const u8 }{ .@"enumLiteral" = v },654 struct { @"enumLiteral": []const u8 }{ .@"enumLiteral" = v },
650 options,655 options,