From c5655468e34767752b920b4c695ae3ad45d1d105 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 15 Jul 2025 13:14:47 +0200 Subject: [PATCH] fix: make keybind module respect command.suppressed_errors list Also, make suppressed_errors a static string map for a little extra performance. --- src/command.zig | 18 +++++++++++------- src/keybind/keybind.zig | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/command.zig b/src/command.zig index e7e0829..8577a9a 100644 --- a/src/command.zig +++ b/src/command.zig @@ -188,17 +188,21 @@ pub fn get_arguments(id: ID) ?[]const ArgumentType { return (commands.items[id] orelse return null).meta.arguments; } -const suppressed_errors = .{ - "enable_fast_scroll", - "disable_fast_scroll", - "clear_diagnostics", -}; +const suppressed_errors = std.StaticStringMap(void).initComptime(.{ + .{ "enable_fast_scroll", void }, + .{ "disable_fast_scroll", void }, + .{ "clear_diagnostics", void }, +}); pub fn executeName(name: []const u8, ctx: Context) tp.result { const id = get_id(name); if (id) |id_| return execute(id_, ctx); - inline for (suppressed_errors) |err| if (std.mem.eql(u8, err, name)) return; - return tp.exit_fmt("CommandNotFound: {s}", .{name}); + return notFoundError(name); +} + +pub fn notFoundError(name: []const u8) !void { + if (!suppressed_errors.has(name)) + return tp.exit_fmt("CommandNotFound: {s}", .{name}); } fn CmdDef(comptime T: type) type { diff --git a/src/keybind/keybind.zig b/src/keybind/keybind.zig index 0a69f6c..e3c71e1 100644 --- a/src/keybind/keybind.zig +++ b/src/keybind/keybind.zig @@ -291,7 +291,7 @@ const Command = struct { fn execute(self: *@This()) !void { const id = self.command_id orelse command.get_id_cache(self.command, &self.command_id) orelse { - return tp.exit_fmt("CommandNotFound: {s}", .{self.command}); + return command.notFoundError(self.command); }; var buf: [2048]u8 = undefined; @memcpy(buf[0..self.args.len], self.args);