authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-04-03 18:46:03+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
logcc71003cfcd8af8e037dd127ea627113fbc17103
tree8adc4b5ee6916bc955b182c0cfcba8863abb197b
parentd85259989e7c8f0f28fa80dc7970792b6411e1ed

autodoc: improved rendering container fields and fixed rendering of func

args

1 files changed, 42 insertions(+), 25 deletions(-)

lib/docs/main.js+42-25
...@@ -391,8 +391,35 @@ var zigAnalysis;...@@ -391,8 +391,35 @@ var zigAnalysis;
391 return isType(x) && typeKindIsContainer(/** @type {Type} */(x).kind) ;391 return isType(x) && typeKindIsContainer(/** @type {Type} */(x).kind) ;
392 }392 }
393393
394 /** @param {Type} type */394 /** @param {WalkResult} wr */
395 function typeShorthandName(type) {395 function typeShorthandName(wr) {
396 let resolvedWr = resolveValue(wr);
397 if (!("type" in resolvedWr)) {
398 return null;
399 }
400 let type = /** @type {Type} */(zigAnalysis.types[resolvedWr.type]);
401
402 outer: for (let i = 0; i < 10000; i += 1) {
403 switch (type.kind) {
404 case typeKinds.Optional:
405 case typeKinds.Pointer:
406 let child = /** @type {PointerType | OptionalType} */(type).child;
407 let resolvedChild = resolveValue(child);
408 if ("type" in resolvedChild) {
409 type = zigAnalysis.types[resolvedChild.type];
410 continue;
411 } else {
412 return null;
413 }
414 default:
415 break outer;
416 }
417
418 if (i == 9999) throw "Exhausted typeShorthandName quota";
419 }
420
421
422
396 let name = undefined;423 let name = undefined;
397 if (type.kind === typeKinds.Struct) {424 if (type.kind === typeKinds.Struct) {
398 name = "struct";425 name = "struct";
...@@ -401,8 +428,10 @@ var zigAnalysis;...@@ -401,8 +428,10 @@ var zigAnalysis;
401 } else if (type.kind === typeKinds.Union) {428 } else if (type.kind === typeKinds.Union) {
402 name = "union";429 name = "union";
403 } else {430 } else {
404 name = /** @type {any} */(type).name;431 console.log("TODO: unhalndled case in typeShortName");
432 return null;
405 }433 }
434
406 return escapeHtml(name);435 return escapeHtml(name);
407 }436 }
408437
...@@ -954,8 +983,7 @@ var zigAnalysis;...@@ -954,8 +983,7 @@ var zigAnalysis;
954 */983 */
955 function resizeDomListDl(dlDom, desiredLen) {984 function resizeDomListDl(dlDom, desiredLen) {
956 // add the missing dom entries985 // add the missing dom entries
957 let i, ev;986 for (let i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
958 for (i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
959 dlDom.insertAdjacentHTML('beforeend', '<dt></dt><dd></dd>');987 dlDom.insertAdjacentHTML('beforeend', '<dt></dt><dd></dd>');
960 }988 }
961 // remove extra dom entries989 // remove extra dom entries
...@@ -972,8 +1000,7 @@ var zigAnalysis;...@@ -972,8 +1000,7 @@ var zigAnalysis;
972 */1000 */
973 function resizeDomList(listDom, desiredLen, templateHtml) {1001 function resizeDomList(listDom, desiredLen, templateHtml) {
974 // add the missing dom entries1002 // add the missing dom entries
975 let i, ev;1003 for (let i = listDom.childElementCount; i < desiredLen; i += 1) {
976 for (i = listDom.childElementCount; i < desiredLen; i += 1) {
977 listDom.insertAdjacentHTML('beforeend', templateHtml);1004 listDom.insertAdjacentHTML('beforeend', templateHtml);
978 }1005 }
979 // remove extra dom entries1006 // remove extra dom entries
...@@ -1050,7 +1077,6 @@ var zigAnalysis;...@@ -1050,7 +1077,6 @@ var zigAnalysis;
1050 console.assert("type" in typeValue)1077 console.assert("type" in typeValue)
1051 let typeIndex = typeValue.type;1078 let typeIndex = typeValue.type;
1052 let typeObj = zigAnalysis.types[typeIndex];1079 let typeObj = zigAnalysis.types[typeIndex];
1053 let declNameOk = declCanRepresentTypeKind(typeObj.kind);
1054 if (wantLink) {1080 if (wantLink) {
1055 let declIndex = getCanonTypeDecl(typeIndex);1081 let declIndex = getCanonTypeDecl(typeIndex);
1056 let declPath = getCanonDeclPath(declIndex);1082 let declPath = getCanonDeclPath(declIndex);
...@@ -1359,7 +1385,6 @@ var zigAnalysis;...@@ -1359,7 +1385,6 @@ var zigAnalysis;
13591385
1360 let value = fnObj.params[i];1386 let value = fnObj.params[i];
1361 let paramValue = resolveValue(value);1387 let paramValue = resolveValue(value);
1362 let isCte = "comptimeExpr" in paramValue;
13631388
1364 if (fields != null) {1389 if (fields != null) {
1365 let paramNode = zigAnalysis.astNodes[fields[i]];1390 let paramNode = zigAnalysis.astNodes[fields[i]];
...@@ -1402,7 +1427,7 @@ var zigAnalysis;...@@ -1402,7 +1427,7 @@ var zigAnalysis;
1402 payloadHtml += '</a>';1427 payloadHtml += '</a>';
14031428
1404 } else if ("type" in value) {1429 } else if ("type" in value) {
1405 let name = typeValueName(value, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);1430 let name = typeValueName(value, false, false, fnDecl, linkFnNameDecl);
1406 payloadHtml += '<span class="tok-kw">' + escapeHtml(name) + '</span>';1431 payloadHtml += '<span class="tok-kw">' + escapeHtml(name) + '</span>';
1407 } else if ("comptimeExpr" in value) {1432 } else if ("comptimeExpr" in value) {
1408 payloadHtml += '<span class="tok-kw">[ComptimeExpr]</span>';1433 payloadHtml += '<span class="tok-kw">[ComptimeExpr]</span>';
...@@ -1815,10 +1840,15 @@ var zigAnalysis;...@@ -1815,10 +1840,15 @@ var zigAnalysis;
1815 if (container.kind === typeKinds.Enum) {1840 if (container.kind === typeKinds.Enum) {
1816 html += ' = <span class="tok-number">' + fieldName + '</span>';1841 html += ' = <span class="tok-number">' + fieldName + '</span>';
1817 } else {1842 } else {
1818 let field = container.fields[i];1843 let fieldTypeWr = container.fields[i];
1819 html += ": ";1844 html += ": ";
1820 let name = typeValueName(field, false, false);1845 let name = typeValueName(fieldTypeWr, false, false);
1821 html += '<span class="tok-kw">'+ name +'</span>';1846 html += '<span class="tok-kw">'+ name +'</span>';
1847 let tsn = typeShorthandName(fieldTypeWr);
1848 if (tsn) {
1849 html += '<span> ('+ tsn +')</span>';
1850
1851 }
1822 }1852 }
18231853
1824 html += ',</pre></div>';1854 html += ',</pre></div>';
...@@ -2751,18 +2781,5 @@ function byNameProperty(a, b) {...@@ -2751,18 +2781,5 @@ function byNameProperty(a, b) {
2751}2781}
27522782
27532783
2754/**
2755 * @template T
2756 * @param {T} obj
2757 * @returns {T}
2758 */
2759function clone(obj) {
2760 let res = /** @type T */({});
2761 for (let key in obj) {
2762 res[key] = obj[key];
2763 }
2764 return res;
2765}
2766
27672784
2768})();2785})();