refactor: use command.command_names index and improve logging of commands

We now use the command name index more consistently to allow for
pre-allocating command IDs and better logging when commands are not
found.

This is a major, but hopefully non-breaking, change to command execution.
This commit is contained in:
CJ van den Berg 2025-12-23 13:45:13 +01:00
parent 6c60e5a0df
commit f75cc9b845
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
4 changed files with 57 additions and 53 deletions

View file

@ -5734,7 +5734,7 @@ pub const Editor = struct {
pub fn goto_next_diagnostic(self: *Self, _: Context) Result {
if (self.diagnostics.items.len == 0) {
if (command.get_id("goto_next_file")) |id|
return command.execute(id, .{});
return command.execute(id, "goto_next_file", .{});
return;
}
self.sort_diagnostics();
@ -5750,7 +5750,7 @@ pub const Editor = struct {
pub fn goto_prev_diagnostic(self: *Self, _: Context) Result {
if (self.diagnostics.items.len == 0) {
if (command.get_id("goto_prev_file")) |id|
return command.execute(id, .{});
return command.execute(id, "goto_prev_file", .{});
return;
}
self.sort_diagnostics();
@ -6224,7 +6224,7 @@ pub const Editor = struct {
}
fn add_default_symbol_triggers(self: *Self) void {
const id = command.get_id("completion") orelse return;
const id = command.get_name_id("completion");
self.add_symbol_trigger('.', id, .insert) catch {};
}

View file

@ -416,7 +416,7 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
if (try m.match(.{ "cmd", tp.extract(&cmd) }))
return command.executeName(cmd, ctx) catch |e| self.logger.err(cmd, e);
if (try m.match(.{ "cmd", tp.extract(&cmd_id) }))
return command.execute(cmd_id, ctx) catch |e| self.logger.err("command", e);
return command.execute(cmd_id, command.get_name(cmd_id) orelse "(unknown)", ctx) catch |e| self.logger.err("command", e);
var arg: []const u8 = undefined;
@ -426,7 +426,7 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
}
if (try m.match(.{ "cmd", tp.extract(&cmd_id), tp.extract_cbor(&arg) })) {
ctx.args = .{ .buf = arg };
return command.execute(cmd_id, ctx) catch |e| self.logger.err("command", e);
return command.execute(cmd_id, command.get_name(cmd_id) orelse "(unknown)", ctx) catch |e| self.logger.err("command", e);
}
if (try m.match(.{"quit"})) {
project_manager.shutdown();
@ -736,7 +736,7 @@ fn dispatch_event(ctx: *anyopaque, cbor_msg: []const u8) void {
fn handle_system_clipboard(self: *Self, text: []const u8) !void {
if (command.get_id("mini_mode_paste")) |id|
return command.execute(id, command.fmt(.{text}));
return command.execute(id, "mini_mode_paste", command.fmt(.{text}));
{
const text_ = try clipboard_system_clipboard_text(self.allocator);