Commit cc71003cfc

Loris Cro <kappaloris@gmail.com>
2022-04-03 18:46:03
autodoc: improved rendering container fields and fixed rendering of func args
1 parent d852599
Changed files (1)
lib
docs
lib/docs/main.js
@@ -391,8 +391,35 @@ var zigAnalysis;
         return isType(x) && typeKindIsContainer(/** @type {Type} */(x).kind) ;
     }
 
-    /** @param {Type} type */
-    function typeShorthandName(type) {
+    /** @param {WalkResult} wr */
+    function typeShorthandName(wr) {
+        let resolvedWr = resolveValue(wr);
+        if (!("type" in resolvedWr)) {
+            return null;
+        }
+        let type = /** @type {Type} */(zigAnalysis.types[resolvedWr.type]);
+
+        outer: for (let i = 0; i < 10000; i += 1) {
+            switch (type.kind) {
+                case typeKinds.Optional:
+                case typeKinds.Pointer:
+                    let child = /** @type {PointerType | OptionalType} */(type).child;
+                    let resolvedChild = resolveValue(child);
+                    if ("type" in resolvedChild) {
+                        type = zigAnalysis.types[resolvedChild.type];
+                        continue;
+                    } else {
+                        return null;
+                    }
+                default:
+                    break outer;
+            }
+
+            if (i == 9999) throw "Exhausted typeShorthandName quota";
+        }
+
+
+
         let name = undefined;
         if (type.kind === typeKinds.Struct) {
             name = "struct";
@@ -401,8 +428,10 @@ var zigAnalysis;
         } else if (type.kind === typeKinds.Union) {
             name = "union";
         } else {
-            name = /** @type {any} */(type).name;
+            console.log("TODO: unhalndled case in typeShortName");
+            return null;
         }
+
         return escapeHtml(name);
     }
 
@@ -954,8 +983,7 @@ var zigAnalysis;
     */
     function resizeDomListDl(dlDom, desiredLen) {
         // add the missing dom entries
-        let i, ev;
-        for (i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
+        for (let i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
             dlDom.insertAdjacentHTML('beforeend', '<dt></dt><dd></dd>');
         }
         // remove extra dom entries
@@ -972,8 +1000,7 @@ var zigAnalysis;
     */
     function resizeDomList(listDom, desiredLen, templateHtml) {
         // add the missing dom entries
-        let i, ev;
-        for (i = listDom.childElementCount; i < desiredLen; i += 1) {
+        for (let i = listDom.childElementCount; i < desiredLen; i += 1) {
             listDom.insertAdjacentHTML('beforeend', templateHtml);
         }
         // remove extra dom entries
@@ -1050,7 +1077,6 @@ var zigAnalysis;
         console.assert("type" in typeValue)
         let typeIndex = typeValue.type;
         let typeObj = zigAnalysis.types[typeIndex];
-        let declNameOk = declCanRepresentTypeKind(typeObj.kind);
         if (wantLink) {
             let declIndex = getCanonTypeDecl(typeIndex);
             let declPath = getCanonDeclPath(declIndex);
@@ -1359,7 +1385,6 @@ var zigAnalysis;
 
                             let value = fnObj.params[i];
                             let paramValue = resolveValue(value);
-                            let isCte = "comptimeExpr" in paramValue;
 
                             if (fields != null) {
                                 let paramNode = zigAnalysis.astNodes[fields[i]];
@@ -1402,7 +1427,7 @@ var zigAnalysis;
                                 payloadHtml += '</a>';
 
                             } else if ("type" in value) {
-                                let name = typeValueName(value, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
+                                let name = typeValueName(value, false, false, fnDecl, linkFnNameDecl);
                                 payloadHtml += '<span class="tok-kw">' + escapeHtml(name) + '</span>';
                             } else if ("comptimeExpr" in value) {
                                 payloadHtml += '<span class="tok-kw">[ComptimeExpr]</span>';
@@ -1815,10 +1840,15 @@ var zigAnalysis;
                 if (container.kind === typeKinds.Enum) {
                     html += ' = <span class="tok-number">' + fieldName + '</span>';
                 } else {
-                    let field = container.fields[i];
+                    let fieldTypeWr = container.fields[i];
                     html += ": ";
-                    let name = typeValueName(field, false, false);
+                    let name = typeValueName(fieldTypeWr, false, false);
                     html += '<span class="tok-kw">'+ name +'</span>';
+                    let tsn = typeShorthandName(fieldTypeWr);
+                    if (tsn) {
+                        html += '<span> ('+ tsn +')</span>';
+
+                    }
                 }
 
                 html += ',</pre></div>';
@@ -2751,18 +2781,5 @@ function byNameProperty(a, b) {
 }
 
 
-/**
- * @template T
- * @param {T} obj
- * @returns {T}
- */
-function clone(obj) {
-    let res = /** @type T */({});
-    for (let key in obj) {
-        res[key] = obj[key];
-    }
-    return res;
-}
-
 
 })();