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;
391391 return isType(x) && typeKindIsContainer(/** @type {Type} */(x).kind) ;
392392 }
393393
394 /** @param {Type} type */
395 function typeShorthandName(type) {
394 /** @param {WalkResult} wr */
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
396423 let name = undefined;
397424 if (type.kind === typeKinds.Struct) {
398425 name = "struct";
......@@ -401,8 +428,10 @@ var zigAnalysis;
401428 } else if (type.kind === typeKinds.Union) {
402429 name = "union";
403430 } else {
404 name = /** @type {any} */(type).name;
431 console.log("TODO: unhalndled case in typeShortName");
432 return null;
405433 }
434
406435 return escapeHtml(name);
407436 }
408437
......@@ -954,8 +983,7 @@ var zigAnalysis;
954983 */
955984 function resizeDomListDl(dlDom, desiredLen) {
956985 // add the missing dom entries
957 let i, ev;
958 for (i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
986 for (let i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
959987 dlDom.insertAdjacentHTML('beforeend', '<dt></dt><dd></dd>');
960988 }
961989 // remove extra dom entries
......@@ -972,8 +1000,7 @@ var zigAnalysis;
9721000 */
9731001 function resizeDomList(listDom, desiredLen, templateHtml) {
9741002 // add the missing dom entries
975 let i, ev;
976 for (i = listDom.childElementCount; i < desiredLen; i += 1) {
1003 for (let i = listDom.childElementCount; i < desiredLen; i += 1) {
9771004 listDom.insertAdjacentHTML('beforeend', templateHtml);
9781005 }
9791006 // remove extra dom entries
......@@ -1050,7 +1077,6 @@ var zigAnalysis;
10501077 console.assert("type" in typeValue)
10511078 let typeIndex = typeValue.type;
10521079 let typeObj = zigAnalysis.types[typeIndex];
1053 let declNameOk = declCanRepresentTypeKind(typeObj.kind);
10541080 if (wantLink) {
10551081 let declIndex = getCanonTypeDecl(typeIndex);
10561082 let declPath = getCanonDeclPath(declIndex);
......@@ -1359,7 +1385,6 @@ var zigAnalysis;
13591385
13601386 let value = fnObj.params[i];
13611387 let paramValue = resolveValue(value);
1362 let isCte = "comptimeExpr" in paramValue;
13631388
13641389 if (fields != null) {
13651390 let paramNode = zigAnalysis.astNodes[fields[i]];
......@@ -1402,7 +1427,7 @@ var zigAnalysis;
14021427 payloadHtml += '</a>';
14031428
14041429 } else if ("type" in value) {
1405 let name = typeValueName(value, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
1430 let name = typeValueName(value, false, false, fnDecl, linkFnNameDecl);
14061431 payloadHtml += '<span class="tok-kw">' + escapeHtml(name) + '</span>';
14071432 } else if ("comptimeExpr" in value) {
14081433 payloadHtml += '<span class="tok-kw">[ComptimeExpr]</span>';
......@@ -1815,10 +1840,15 @@ var zigAnalysis;
18151840 if (container.kind === typeKinds.Enum) {
18161841 html += ' = <span class="tok-number">' + fieldName + '</span>';
18171842 } else {
1818 let field = container.fields[i];
1843 let fieldTypeWr = container.fields[i];
18191844 html += ": ";
1820 let name = typeValueName(field, false, false);
1845 let name = typeValueName(fieldTypeWr, false, false);
18211846 html += '<span class="tok-kw">'+ name +'</span>';
1847 let tsn = typeShorthandName(fieldTypeWr);
1848 if (tsn) {
1849 html += '<span> ('+ tsn +')</span>';
1850
1851 }
18221852 }
18231853
18241854 html += ',</pre></div>';
......@@ -2751,18 +2781,5 @@ function byNameProperty(a, b) {
27512781}
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
27682785})();