mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
autodocs: added support for some non-type values
This commit is contained in:
+32
-17
@@ -177,8 +177,8 @@
|
||||
return renderUnknownDecl(lastDeclOrType);
|
||||
} else if (lastDeclOrType.kind === 'var') {
|
||||
return renderVar(lastDeclOrType);
|
||||
} else if (lastDeclOrType.kind === 'const' && lastDeclOrType.type != null) {
|
||||
var typeObj = zigAnalysis.types[lastDeclOrType.type];
|
||||
} else if (lastDeclOrType.kind === 'const' && "value" in lastDeclOrType && !("type" in lastDeclOrType.value)) {
|
||||
var typeObj = zigAnalysis.types[getDeclValTypeId(lastDeclOrType)];
|
||||
if (typeObj.kind === typeKinds.Fn) {
|
||||
return renderFn(lastDeclOrType);
|
||||
} else {
|
||||
@@ -960,6 +960,7 @@
|
||||
|
||||
function renderValue(decl) {
|
||||
|
||||
var declTypeId = getDeclValTypeId(decl);
|
||||
var declValueText = "";
|
||||
switch(Object.keys(decl.value)[0]) {
|
||||
case "int":
|
||||
@@ -971,7 +972,7 @@
|
||||
}
|
||||
|
||||
domFnProtoCode.innerHTML = '<span class="tok-kw">const</span> ' +
|
||||
escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true) +
|
||||
escapeHtml(decl.name) + ': ' + typeIndexName(declTypeId, true, true) +
|
||||
" = " + declValueText;
|
||||
|
||||
var docs = zigAnalysis.astNodes[decl.src].docs;
|
||||
@@ -984,8 +985,9 @@
|
||||
}
|
||||
|
||||
function renderVar(decl) {
|
||||
var declTypeId = getDeclValTypeId(decl);
|
||||
domFnProtoCode.innerHTML = '<span class="tok-kw">var</span> ' +
|
||||
escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true);
|
||||
escapeHtml(decl.name) + ': ' + typeIndexName(declTypeId, true, true);
|
||||
|
||||
var docs = zigAnalysis.astNodes[decl.src].docs;
|
||||
if (docs != null) {
|
||||
@@ -1011,10 +1013,8 @@
|
||||
if (decl.kind === 'var') {
|
||||
varsList.push(decl);
|
||||
continue;
|
||||
} else if (decl.kind === 'const' && decl.type != null) {
|
||||
if (decl.type === typeTypeId) {
|
||||
// todo: this actually makes sense for decl_vals too
|
||||
// the problem is, how should we get to the final type though?
|
||||
} else if (decl.kind === 'const' && "value" in decl) {
|
||||
if (declValTypeId === typeTypeId) {
|
||||
if (typeIsErrSet(declValTypeId)) {
|
||||
errSetsList.push(decl);
|
||||
} else if (typeIsStructWithNoFields(declValTypeId)) {
|
||||
@@ -1023,8 +1023,9 @@
|
||||
typesList.push(decl);
|
||||
}
|
||||
} else {
|
||||
var typeKind = zigAnalysis.types[decl.type].kind;
|
||||
var typeKind = zigAnalysis.types[declValTypeId].kind;
|
||||
if (typeKind === typeKinds.Fn) {
|
||||
// TODO: this is broken but I don't understand functions yet
|
||||
if (allCompTimeFnCallsHaveTypeResult(decl.type, declValTypeId)) {
|
||||
typesList.push(decl);
|
||||
} else {
|
||||
@@ -1125,8 +1126,8 @@
|
||||
if (typeof(field) === 'object') {
|
||||
if (field.failure === true) {
|
||||
html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>';
|
||||
} else if ("decl_ref" in field) {
|
||||
var decl = zigAnalysis.decls[field.decl_ref];
|
||||
} else if ("declRef" in field) {
|
||||
var decl = zigAnalysis.decls[field.declRef];
|
||||
var valType = zigAnalysis.types[getDeclValTypeId(decl)];
|
||||
var valTypeName = valType.name;
|
||||
if (valType.kind === typeKinds.Struct) {
|
||||
@@ -1174,7 +1175,7 @@
|
||||
tdNameA.setAttribute('href', navLinkDecl(decl.name));
|
||||
tdNameA.textContent = decl.name;
|
||||
|
||||
tdType.innerHTML = typeIndexName(decl.type, true, true);
|
||||
tdType.innerHTML = typeIndexName(getDeclValTypeId(decl), true, true);
|
||||
|
||||
var docs = zigAnalysis.astNodes[decl.src].docs;
|
||||
if (docs != null) {
|
||||
@@ -1201,7 +1202,7 @@
|
||||
tdNameA.setAttribute('href', navLinkDecl(decl.name));
|
||||
tdNameA.textContent = decl.name;
|
||||
|
||||
tdType.innerHTML = typeIndexName(decl.type, true, true);
|
||||
tdType.innerHTML = typeIndexName(getDeclValTypeId(decl), true, true);
|
||||
|
||||
var docs = zigAnalysis.astNodes[decl.src].docs;
|
||||
if (docs != null) {
|
||||
@@ -1359,12 +1360,26 @@
|
||||
return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind);
|
||||
}
|
||||
|
||||
// Handles both WalkResult and TypeRef
|
||||
function getDeclValTypeId(decl) {
|
||||
while ( "decl_ref" in decl.value) {
|
||||
decl = zigAnalysis.decls[decl.value.decl_ref];
|
||||
var val = decl.value;
|
||||
while (true) {
|
||||
if ( "declRef" in val) {
|
||||
val = zigAnalysis.decls[val.declRef].value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("int" in val) {
|
||||
val = val.int.typeRef;
|
||||
}
|
||||
|
||||
if ("type" in val) {
|
||||
return val.type;
|
||||
}
|
||||
|
||||
console.assert("type" in val);
|
||||
}
|
||||
console.assert("type" in decl.value);
|
||||
return decl.value.type;
|
||||
return val.type;
|
||||
}
|
||||
|
||||
function computeCanonDeclPaths() {
|
||||
|
||||
Reference in New Issue
Block a user