mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-08 06:44:27 +00:00
autodoc: add frontend support for optionals & generic cleanup
This commit is contained in:
parent
fbf0d0bee9
commit
253e7e112e
1 changed files with 142 additions and 122 deletions
|
|
@ -149,8 +149,9 @@
|
||||||
while(i < 1000) {
|
while(i < 1000) {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
||||||
if ("declRef" in value) {
|
if ("declPath" in value) {
|
||||||
value = zigAnalysis.decls[value.declRef].value;
|
console.assert(value.declPath.length == 1); // only support declRefs for now
|
||||||
|
value = zigAnalysis.decls[value.declPath[0]].value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,8 +170,9 @@
|
||||||
return typeTypeId;
|
return typeTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("declRef" in decl.value) {
|
if ("declPath" in decl.value) {
|
||||||
decl = zigAnalysis.decls[decl.value.declRef];
|
console.assert(decl.value.declPath.length == 1); // only support declRefs for now
|
||||||
|
decl = zigAnalysis.decls[decl.value.declPath[0]];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,6 +195,7 @@
|
||||||
|
|
||||||
console.log("TODO: handle in `typeOfDecl` more cases: ", decl);
|
console.log("TODO: handle in `typeOfDecl` more cases: ", decl);
|
||||||
console.assert(false);
|
console.assert(false);
|
||||||
|
throw {};
|
||||||
}
|
}
|
||||||
console.assert(false);
|
console.assert(false);
|
||||||
}
|
}
|
||||||
|
|
@ -637,6 +640,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function typeIndexName(typeIndex, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
|
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 typeObj = zigAnalysis.types[typeIndex];
|
||||||
var declNameOk = declCanRepresentTypeKind(typeObj.kind);
|
var declNameOk = declCanRepresentTypeKind(typeObj.kind);
|
||||||
if (wantLink) {
|
if (wantLink) {
|
||||||
|
|
@ -714,10 +736,11 @@
|
||||||
name += typeObj.len;
|
name += typeObj.len;
|
||||||
}
|
}
|
||||||
name += "]";
|
name += "]";
|
||||||
name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null);
|
name += typeValueName(typeObj.elem, wantHtml, wantSubLink, null);
|
||||||
return name;
|
return name;
|
||||||
case typeKinds.Optional:
|
case typeKinds.Optional:
|
||||||
return "?" + typeIndexName(typeObj.child, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
|
|
||||||
|
return "?" + typeValueName(typeObj.child, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
|
||||||
case typeKinds.Pointer:
|
case typeKinds.Pointer:
|
||||||
var name = "";
|
var name = "";
|
||||||
switch (typeObj.len) {
|
switch (typeObj.len) {
|
||||||
|
|
@ -776,7 +799,7 @@
|
||||||
}
|
}
|
||||||
name += ") ";
|
name += ") ";
|
||||||
}
|
}
|
||||||
name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null);
|
name += typeValueName(typeObj.elem, wantHtml, wantSubLink, null);
|
||||||
return name;
|
return name;
|
||||||
case typeKinds.Float:
|
case typeKinds.Float:
|
||||||
if (wantHtml) {
|
if (wantHtml) {
|
||||||
|
|
@ -949,13 +972,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var retValue = resolveValue(typeObj.ret);
|
|
||||||
console.assert("type" in retValue);
|
|
||||||
var retTypeIndex = retValue.type;
|
|
||||||
|
|
||||||
payloadHtml += ') ';
|
payloadHtml += ') ';
|
||||||
if (retTypeIndex != null) {
|
if (typeObj.ret != null) {
|
||||||
payloadHtml += typeIndexName(retTypeIndex, wantHtml, wantSubLink, fnDecl);
|
payloadHtml += typeValueName(typeObj.ret, wantHtml, wantSubLink, fnDecl);
|
||||||
} else if (wantHtml) {
|
} else if (wantHtml) {
|
||||||
payloadHtml += '<span class="tok-kw">anytype</span>';
|
payloadHtml += '<span class="tok-kw">anytype</span>';
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1295,8 +1314,9 @@
|
||||||
if (typeof(field) === 'object') {
|
if (typeof(field) === 'object') {
|
||||||
if (field.failure === true) {
|
if (field.failure === true) {
|
||||||
html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>';
|
html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>';
|
||||||
} else if ("declRef" in field) {
|
} else if ("declPath" in field) {
|
||||||
var decl = zigAnalysis.decls[field.declRef];
|
console.assert(field.declPath.lenght == 1);
|
||||||
|
var decl = zigAnalysis.decls[field.declPath[0]];
|
||||||
var val = resolveValue(decl.value);
|
var val = resolveValue(decl.value);
|
||||||
console.assert("type" in val);
|
console.assert("type" in val);
|
||||||
var valType = zigAnalysis.types[val.type];
|
var valType = zigAnalysis.types[val.type];
|
||||||
|
|
@ -2002,37 +2022,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showHelpModal() {
|
function showHelpModal() {
|
||||||
domHelpModal.classList.remove("hidden");
|
domHelpModal.classList.remove("hidden");
|
||||||
domHelpModal.style.left = (window.innerWidth / 2 - domHelpModal.clientWidth / 2) + "px";
|
domHelpModal.style.left = (window.innerWidth / 2 - domHelpModal.clientWidth / 2) + "px";
|
||||||
domHelpModal.style.top = (window.innerHeight / 2 - domHelpModal.clientHeight / 2) + "px";
|
domHelpModal.style.top = (window.innerHeight / 2 - domHelpModal.clientHeight / 2) + "px";
|
||||||
domHelpModal.focus();
|
domHelpModal.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearAsyncSearch() {
|
function clearAsyncSearch() {
|
||||||
if (searchTimer != null) {
|
if (searchTimer != null) {
|
||||||
clearTimeout(searchTimer);
|
clearTimeout(searchTimer);
|
||||||
searchTimer = null;
|
searchTimer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startAsyncSearch() {
|
function startAsyncSearch() {
|
||||||
clearAsyncSearch();
|
clearAsyncSearch();
|
||||||
searchTimer = setTimeout(startSearch, 100);
|
searchTimer = setTimeout(startSearch, 100);
|
||||||
}
|
}
|
||||||
function startSearch() {
|
function startSearch() {
|
||||||
clearAsyncSearch();
|
clearAsyncSearch();
|
||||||
var oldHash = location.hash;
|
var oldHash = location.hash;
|
||||||
var parts = oldHash.split("?");
|
var parts = oldHash.split("?");
|
||||||
var newPart2 = (domSearch.value === "") ? "" : ("?" + domSearch.value);
|
var newPart2 = (domSearch.value === "") ? "" : ("?" + domSearch.value);
|
||||||
location.hash = (parts.length === 1) ? (oldHash + newPart2) : (parts[0] + newPart2);
|
location.hash = (parts.length === 1) ? (oldHash + newPart2) : (parts[0] + newPart2);
|
||||||
}
|
}
|
||||||
function getSearchTerms() {
|
function getSearchTerms() {
|
||||||
var list = curNavSearch.trim().split(/[ \r\n\t]+/);
|
var list = curNavSearch.trim().split(/[ \r\n\t]+/);
|
||||||
list.sort();
|
list.sort();
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
function renderSearch() {
|
function renderSearch() {
|
||||||
var matchedItems = [];
|
var matchedItems = [];
|
||||||
var ignoreCase = (curNavSearch.toLowerCase() === curNavSearch);
|
var ignoreCase = (curNavSearch.toLowerCase() === curNavSearch);
|
||||||
var terms = getSearchTerms();
|
var terms = getSearchTerms();
|
||||||
|
|
@ -2112,7 +2132,7 @@
|
||||||
} else {
|
} else {
|
||||||
domSectSearchNoResults.classList.remove("hidden");
|
domSectSearchNoResults.classList.remove("hidden");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSearchCursor() {
|
function renderSearchCursor() {
|
||||||
for (var i = 0; i < domListSearchResults.children.length; i += 1) {
|
for (var i = 0; i < domListSearchResults.children.length; i += 1) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue