diff options
| author | Loris Cro <kappaloris@gmail.com> | 2023-04-13 17:53:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-13 17:53:13 +0200 |
| commit | fbcf1c0006dc6656deb3f04e2f52d1da4a599952 (patch) | |
| tree | 92543a4474cf2ef150c2941f52e932fad16e618e /lib | |
| parent | 83d1f6b15a84864232eceafb24b95b8d16282a3f (diff) | |
| parent | aea886e2f3df6dd7bd89e16d42a953d379b0550a (diff) | |
| download | zig-fbcf1c0006dc6656deb3f04e2f52d1da4a599952.tar.gz zig-fbcf1c0006dc6656deb3f04e2f52d1da4a599952.zip | |
Merge pull request #15261 from der-teufel-programming/autodoc-defaults
Autodoc: default values for fields in structs, explicit values for tags in enums
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docs/main.js | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/docs/main.js b/lib/docs/main.js index 534ddb5ef7..8d9a3b08a6 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -623,7 +623,7 @@ const NAV_MODES = { function typeIsStructWithNoFields(typeIndex) { let typeObj = getType(typeIndex); if (typeObj.kind !== typeKinds.Struct) return false; - return typeObj.fields.length == 0; + return typeObj.field_types.length == 0; } function typeIsGenericFn(typeIndex) { @@ -2705,6 +2705,7 @@ const NAV_MODES = { let declValue = resolveValue(uns.value); if (!("type" in declValue.expr)) continue; let uns_container = getType(declValue.expr.type); + if (!isContainerType(uns_container)) continue; categorizeDecls( uns_container.pubDecls, typesList, @@ -2858,9 +2859,12 @@ const NAV_MODES = { escapeHtml(fieldName); if (container.kind === typeKinds.Enum) { - html += ' = <span class="tok-number">' + fieldName + "</span>"; + let value = container.values[i]; + if (value !== null) { + html += " = " + exprName(value, { wantHtml: true, wantLink: true }); + } } else { - let fieldTypeExpr = container.fields[i]; + let fieldTypeExpr = container.field_types[i]; if (container.kind !== typeKinds.Struct || !container.is_tuple) { html += ": "; } @@ -2869,6 +2873,12 @@ const NAV_MODES = { if (tsn) { html += "<span> (" + tsn + ")</span>"; } + if (container.kind === typeKinds.Struct && !container.is_tuple) { + let defaultInitExpr = container.field_defaults[i]; + if (defaultInitExpr !== null) { + html += " = " + exprName(defaultInitExpr, { wantHtml: true, wantLink: true }); + } + } } html += ",</pre></div>"; @@ -4057,10 +4067,11 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { src: ty[2], privDecls: ty[3], pubDecls: ty[4], - fields: ty[5], - is_tuple: ty[6], - line_number: ty[7], - outer_decl: ty[8], + field_types: ty[5], + field_defaults: ty[6], + is_tuple: ty[7], + line_number: ty[8], + outer_decl: ty[9], }; case 10: // ComptimeExpr case 11: // ComptimeFloat @@ -4099,7 +4110,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { privDecls: ty[3], pubDecls: ty[4], tag: ty[5], - nonexhaustive: ty[6], + values: ty[6], + nonexhaustive: ty[7], }; case 20: // Union return { @@ -4108,7 +4120,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { src: ty[2], privDecls: ty[3], pubDecls: ty[4], - fields: ty[5], + field_types: ty[5], tag: ty[6], auto_tag: ty[7], }; |
