autodoc: add frontend support for optionals & generic cleanup

This commit is contained in:
Loris Cro 2022-02-22 20:18:45 +01:00 committed by Andrew Kelley
parent fbf0d0bee9
commit 253e7e112e

View file

@ -149,8 +149,9 @@
while(i < 1000) {
i += 1;
if ("declRef" in value) {
value = zigAnalysis.decls[value.declRef].value;
if ("declPath" in value) {
console.assert(value.declPath.length == 1); // only support declRefs for now
value = zigAnalysis.decls[value.declPath[0]].value;
continue;
}
@ -169,8 +170,9 @@
return typeTypeId;
}
if ("declRef" in decl.value) {
decl = zigAnalysis.decls[decl.value.declRef];
if ("declPath" in decl.value) {
console.assert(decl.value.declPath.length == 1); // only support declRefs for now
decl = zigAnalysis.decls[decl.value.declPath[0]];
continue;
}
@ -193,6 +195,7 @@
console.log("TODO: handle in `typeOfDecl` more cases: ", decl);
console.assert(false);
throw {};
}
console.assert(false);
}
@ -637,6 +640,25 @@
}
function typeIndexName(typeIndex, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
return typeValueName({ type: typeIndex }, wantHtml, wantLink, fnDecl, linkFnNameDecl);
}
function typeValueName(typeValue, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
if ("declPath" in typeValue) {
console.assert(typeValue.declPath.length == 1);
var declIndex = typeValue.declPath[0];
var name = zigAnalysis.decls[declIndex].name;
var declPath = getCanonDeclPath(declIndex);
if (wantLink) {
var nl = navLink(declPath.pkgNames, declPath.declNames);
return '<a href="' + nl + '">' + name + '</a>';
} else {
return name;
}
}
console.assert("type" in typeValue)
var typeIndex = typeValue.type;
var typeObj = zigAnalysis.types[typeIndex];
var declNameOk = declCanRepresentTypeKind(typeObj.kind);
if (wantLink) {
@ -714,10 +736,11 @@
name += typeObj.len;
}
name += "]";
name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null);
name += typeValueName(typeObj.elem, wantHtml, wantSubLink, null);
return name;
case typeKinds.Optional:
return "?" + typeIndexName(typeObj.child, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
return "?" + typeValueName(typeObj.child, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
case typeKinds.Pointer:
var name = "";
switch (typeObj.len) {
@ -776,7 +799,7 @@
}
name += ") ";
}
name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null);
name += typeValueName(typeObj.elem, wantHtml, wantSubLink, null);
return name;
case typeKinds.Float:
if (wantHtml) {
@ -949,13 +972,9 @@
}
}
var retValue = resolveValue(typeObj.ret);
console.assert("type" in retValue);
var retTypeIndex = retValue.type;
payloadHtml += ') ';
if (retTypeIndex != null) {
payloadHtml += typeIndexName(retTypeIndex, wantHtml, wantSubLink, fnDecl);
if (typeObj.ret != null) {
payloadHtml += typeValueName(typeObj.ret, wantHtml, wantSubLink, fnDecl);
} else if (wantHtml) {
payloadHtml += '<span class="tok-kw">anytype</span>';
} else {
@ -1295,8 +1314,9 @@
if (typeof(field) === 'object') {
if (field.failure === true) {
html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>';
} else if ("declRef" in field) {
var decl = zigAnalysis.decls[field.declRef];
} else if ("declPath" in field) {
console.assert(field.declPath.lenght == 1);
var decl = zigAnalysis.decls[field.declPath[0]];
var val = resolveValue(decl.value);
console.assert("type" in val);
var valType = zigAnalysis.types[val.type];
@ -2002,37 +2022,37 @@
}
}
function showHelpModal() {
function showHelpModal() {
domHelpModal.classList.remove("hidden");
domHelpModal.style.left = (window.innerWidth / 2 - domHelpModal.clientWidth / 2) + "px";
domHelpModal.style.top = (window.innerHeight / 2 - domHelpModal.clientHeight / 2) + "px";
domHelpModal.focus();
}
}
function clearAsyncSearch() {
function clearAsyncSearch() {
if (searchTimer != null) {
clearTimeout(searchTimer);
searchTimer = null;
}
}
}
function startAsyncSearch() {
function startAsyncSearch() {
clearAsyncSearch();
searchTimer = setTimeout(startSearch, 100);
}
function startSearch() {
}
function startSearch() {
clearAsyncSearch();
var oldHash = location.hash;
var parts = oldHash.split("?");
var newPart2 = (domSearch.value === "") ? "" : ("?" + domSearch.value);
location.hash = (parts.length === 1) ? (oldHash + newPart2) : (parts[0] + newPart2);
}
function getSearchTerms() {
}
function getSearchTerms() {
var list = curNavSearch.trim().split(/[ \r\n\t]+/);
list.sort();
return list;
}
function renderSearch() {
}
function renderSearch() {
var matchedItems = [];
var ignoreCase = (curNavSearch.toLowerCase() === curNavSearch);
var terms = getSearchTerms();
@ -2112,7 +2132,7 @@
} else {
domSectSearchNoResults.classList.remove("hidden");
}
}
}
function renderSearchCursor() {
for (var i = 0; i < domListSearchResults.children.length; i += 1) {