diff options
Diffstat (limited to 'core/builtins_json.zig')
| -rw-r--r-- | core/builtins_json.zig | 28 |
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('}'); } } |
