summaryrefslogtreecommitdiff
path: root/core/builtins_json.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 15:14:44 -0300
committerGabriel Schneider <[email protected]>2026-11-23 15:47:11 -0300
commit33b1f209162f94a9200f8c00d131aae772eb02f2 (patch)
tree9bb64b28ec984326939aa42952ffd3dd34d0a4dc /core/builtins_json.zig
parentf34d3a74cc4a6b735c98ce98cef0df42bd065e67 (diff)
downloadpardes-33b1f209162f94a9200f8c00d131aae772eb02f2.tar.gz
pardes-33b1f209162f94a9200f8c00d131aae772eb02f2.zip
help: a builtin's documentation is the `///` block right above its `pub const <Word> = struct`, read at compile time into one table, `registry.doc` (its summary, the first sentence, and all of it, a line a paragraph), and every reader takes the table (the user's words of 2026-11-23: "the builtins should have their documentation in code somewhere (you may use comptime to extract that) near their definitions"): the summary was found at run time, each word's by a scan of the embedded source for `\npub const <Word> = struct` (core/ninep/ctl.zig `summaryOf`), `stripCitations` cutting `(exec.c:892)` and the like out of it: both are deleted; THE CONVENTION is written at the top of core/builtins.zig (the `///` above a builtin is what a user reads in Help, `pardes help`, /commands, `pardes words` and the glossary; no file names, no "registration", no history; notes for the code's reader are `//` lines inside the struct) and the compiler holds what it can read of it: a builtin with no `///` block, a first sentence over `summary_max` (100 bytes) or a `///` naming a .zig file fails the build, naming the builtin (one pass over the source, `registry.docs`; a setting's documentation is its `Setting.doc`, held the same); 35 builtins' docs cut to it (a first sentence over 100 bytes split at a sentence, acme and source citations into `//` notes in the struct), and DumpDir's setting doc (core/config.zig) the same; /commands prints each word's summary whole (no clip: the bound holds it); the docs' JSON (core/builtins_json.zig) takes `doc` from the table and gains `text`, the whole documentation, beside it (an addon's word: its one `.doc` in both); docs/typ/builtins-tui.json regenerated (`zig build builtins-json -Dplatform=tui`; builtins-gui.json in the change that runs the window's gates); tests: builtins.zig "a builtin's documentation is the whole `///` block above it, a line a paragraph, its summary first", ctl.zig "every word's /commands description is its documentation's summary, a line" (replacing the source-scanning one); core-test 942/1108 (166 skipped; the base measures 941/1107 here, see the report), Debug, tui, load 2-7
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/builtins_json.zig')
-rw-r--r--core/builtins_json.zig28
1 files changed, 16 insertions, 12 deletions
diff --git a/core/builtins_json.zig b/core/builtins_json.zig
index 23e15098..c66775db 100644
--- a/core/builtins_json.zig
+++ b/core/builtins_json.zig
@@ -1,17 +1,17 @@
//! Every builtin as JSON, for the docs' glossary (docs/typ/builtins-tui.json
//! and builtins-gui.json, a build's list each; style.typ merges them):
//! the rows the `Help` builtin draws (pardes.builtin_rows: the leader path
-//! and the other shortcuts) with what /commands says of each word (its doc
-//! comment's first sentence, or a setting's doc), then the shipped addons'
-//! words, read off their kinds' `Word` lines (`"addon"` first, so a search
-//! for a builtin's `{"name": ` never meets one). One source, so the
-//! glossary and Help cannot drift; the test below fails when the committed
-//! copy is stale, and `zig build builtins-json` rewrites it.
+//! and the other shortcuts) with each word's documentation (registry.doc:
+//! `doc` its summary, what /commands says, and `text` all of it), then the
+//! shipped addons' words, read off their kinds' `Word` lines (`"addon"`
+//! first, so a search for a builtin's `{"name": ` never meets one; `text`
+//! their one sentence). One source, so the glossary and Help cannot drift;
+//! the test below fails when the committed copy is stale, and `zig build
+//! builtins-json` rewrites it.
const std = @import("std");
const pardes = @import("root.zig");
const builtins = @import("builtins.zig");
const config = @import("config.zig");
-const ctl = @import("ninep/ctl.zig");
const str = std.json.Stringify.encodeJsonString;
@@ -70,10 +70,11 @@ pub fn write(w: *std.Io.Writer, addon_sources: []const []const u8) std.Io.Writer
try w.writeAll(if (setting != null) "true" else "false");
try w.writeAll(", \"choices\": ");
if (setting) |s| if (config.Settings.choices(s.action)) |v| try str(v, .{}, w) else try w.writeAll("null") else try w.writeAll("null");
- var buf: [2048]u8 = undefined;
- const doc = if (setting) |s| s.doc else ctl.summaryOf(name, &buf);
+ const doc = builtins.registry.doc(b);
try w.writeAll(", \"doc\": ");
- try str(doc, .{}, w);
+ try str(doc.summary, .{}, w);
+ try w.writeAll(", \"text\": ");
+ try str(doc.text, .{}, w);
try w.writeByte('}');
}
// A kind's word is a line of its own: `.{ .name = "PdfFit", .leader =
@@ -91,8 +92,11 @@ pub fn write(w: *std.Io.Writer, addon_sources: []const []const u8) std.Io.Writer
for (l) |c| try w.print(" {c}", .{c});
try w.writeByte('"');
} else try w.writeAll("null");
- try w.print(", \"also\": [], \"arg\": {}, \"scope\": \"pane\", \"setting\": false, \"choices\": null, \"doc\": ", .{std.mem.indexOf(u8, line, ".arg = .") != null});
- try str(quoted(line, ".doc = ") orelse "", .{}, w);
+ try w.print(", \"also\": [], \"arg\": {}, \"scope\": \"pane\", \"setting\": false, \"choices\": null", .{std.mem.indexOf(u8, line, ".arg = .") != null});
+ for ([_][]const u8{ "doc", "text" }) |field| {
+ try w.print(", \"{s}\": ", .{field});
+ try str(quoted(line, ".doc = ") orelse "", .{}, w);
+ }
try w.writeByte('}');
}
}