cdp.lp: use enum for getSemanticTree format param

Leverages std.json.parse to automatically validate the format param into a type-safe enum.
This commit is contained in:
Adrià Arrufat
2026-03-11 16:21:43 +09:00
parent 5329d05005
commit af803da5c8

View File

@@ -44,7 +44,7 @@ pub fn processMessage(cmd: anytype) !void {
fn getSemanticTree(cmd: anytype) !void {
const Params = struct {
format: ?[]const u8 = null,
format: ?enum { text } = null,
prune: ?bool = null,
};
const params = (try cmd.params(Params)) orelse Params{};
@@ -62,8 +62,8 @@ fn getSemanticTree(cmd: anytype) !void {
};
if (params.format) |format| {
if (std.mem.eql(u8, format, "text")) {
st.prune = params.prune orelse true; // text format defaults to pruned
if (format == .text) {
st.prune = params.prune orelse true;
var aw: std.Io.Writer.Allocating = .init(cmd.arena);
defer aw.deinit();
try st.textStringify(&aw.writer);