diff options
| author | Loris Cro <kappaloris@gmail.com> | 2022-01-30 19:12:56 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-07-19 19:10:10 -0700 |
| commit | 0135d2271600db92d1ae727b2a5935d0fc711c13 (patch) | |
| tree | 762b41dafac87eb5f581ab48cbc3d56347149c0b /lib | |
| parent | 38281c8ed421b8febadb2d4e05291fcf4a871ccc (diff) | |
| download | zig-0135d2271600db92d1ae727b2a5935d0fc711c13.tar.gz zig-0135d2271600db92d1ae727b2a5935d0fc711c13.zip | |
autodocs: add support for indirect decl references
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docs/main.js | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/lib/docs/main.js b/lib/docs/main.js index 15e0d7567e..44f003a569 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -147,10 +147,10 @@ curNav.pkgObjs.push(pkg); } - var decl = zigAnalysis.types[pkg.main]; - curNav.declObjs = [decl]; + var currentType = zigAnalysis.types[pkg.main]; + curNav.declObjs = [currentType]; for (var i = 0; i < curNav.declNames.length; i += 1) { - var childDecl = findSubDecl(decl, curNav.declNames[i]); + var childDecl = findSubDecl(currentType, curNav.declNames[i]); if (childDecl == null) { return render404(); } @@ -163,29 +163,29 @@ return render404(); } } - decl = container; - curNav.declObjs.push(decl); + currentType = container; + curNav.declObjs.push(currentType); } renderNav(); - var lastDecl = curNav.declObjs[curNav.declObjs.length - 1]; - if (lastDecl.pubDecls != null) { - renderContainer(lastDecl); + var lastDeclType = curNav.declObjs[curNav.declObjs.length - 1]; + if (lastDeclType.pubDecls != null) { + renderContainer(lastDeclType); } - if (lastDecl.kind == null) { - return renderUnknownDecl(lastDecl); - } else if (lastDecl.kind === 'var') { - return renderVar(lastDecl); - } else if (lastDecl.kind === 'const' && lastDecl.type != null) { - var typeObj = zigAnalysis.types[lastDecl.type]; + if (lastDeclType.kind == null) { + return renderUnknownDecl(lastDeclType); + } else if (lastDeclType.kind === 'var') { + return renderVar(lastDeclType); + } else if (lastDeclType.kind === 'const' && lastDeclType.type != null) { + var typeObj = zigAnalysis.types[lastDeclType.type]; if (typeObj.kind === typeKinds.Fn) { - return renderFn(lastDecl); + return renderFn(lastDeclType); } else { - return renderValue(lastDecl); + return renderValue(lastDeclType); } } else { - renderType(lastDecl); + renderType(lastDeclType); } } @@ -994,15 +994,18 @@ for (var i = 0; i < container.pubDecls.length; i += 1) { var decl = zigAnalysis.decls[container.pubDecls[i]]; + var declValTypeId = getDeclValTypeId(decl); if (decl.kind === 'var') { varsList.push(decl); continue; } else if (decl.kind === 'const' && decl.type != null) { if (decl.type === typeTypeId) { - if (typeIsErrSet(decl.value)) { + // todo: this actually makes sense for decl_vals too + // the problem is, how should we get to the final type though? + if (typeIsErrSet(declValTypeId)) { errSetsList.push(decl); - } else if (typeIsStructWithNoFields(decl.value)) { + } else if (typeIsStructWithNoFields(declValTypeId)) { namespacesList.push(decl); } else { typesList.push(decl); @@ -1010,7 +1013,7 @@ } else { var typeKind = zigAnalysis.types[decl.type].kind; if (typeKind === typeKinds.Fn) { - if (allCompTimeFnCallsHaveTypeResult(decl.type, decl.value)) { + if (allCompTimeFnCallsHaveTypeResult(decl.type, declValTypeId)) { typesList.push(decl); } else { fnsList.push(decl); @@ -1111,10 +1114,20 @@ if (field.failure === true) { html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>'; } else if ("decl_ref" in field) { - var name = zigAnalysis.decls[field.decl_ref].name; - html += '<a href="'+navLinkDecl(name)+'">'; - html += '<span class="tok-kw" style="color:lightblue;">'+ name +'</span>'; + var decl = zigAnalysis.decls[field.decl_ref]; + var valType = zigAnalysis.types[getDeclValTypeId(decl)]; + var valTypeName = valType.name; + if (valType.kind === typeKinds.Struct) { + valTypeName = "struct"; + } + + html += '<a href="'+navLinkDecl(decl.name)+'">'; + html += '<span class="tok-kw" style="color:lightblue;">' + decl.name + '</span>'; html += '</a>'; + html += ' ('+ valTypeName +')'; + } else if ("type" in field) { + var name = zigAnalysis.types[field.type].name; + html += '<span class="tok-kw">' + name + '</span>'; } else { html += '<span class="tok-kw">var</span>'; } @@ -1291,7 +1304,7 @@ function getDeclContainerType(decl) { if (decl.type === typeTypeId) { - return zigAnalysis.types[decl.value]; + return zigAnalysis.types[getDeclValTypeId(decl)]; } return null; } @@ -1334,6 +1347,14 @@ return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind); } + function getDeclValTypeId(decl) { + while ( "decl_ref" in decl.value) { + decl = zigAnalysis.decls[decl.value.decl_ref]; + } + console.assert("type" in decl.value); + return decl.value.type; + } + function computeCanonDeclPaths() { var list = new Array(zigAnalysis.decls.length); canonTypeDecls = new Array(zigAnalysis.types.length); @@ -1355,10 +1376,11 @@ if (list[mainDeclIndex] != null) continue; var decl = zigAnalysis.decls[mainDeclIndex]; + var declValTypeId = getDeclValTypeId(decl); if (decl.type === typeTypeId && - declCanRepresentTypeKind(zigAnalysis.types[decl.value].kind)) + declCanRepresentTypeKind(zigAnalysis.types[declValTypeId].kind)) { - canonTypeDecls[decl.value] = mainDeclIndex; + canonTypeDecls[declValTypeId] = mainDeclIndex; } var declNames = item.declNames.concat([decl.name]); list[mainDeclIndex] = { |
