fix: make keybind module respect command.suppressed_errors list

Also, make suppressed_errors a static string map for a little extra
performance.
This commit is contained in:
CJ van den Berg 2025-07-15 13:14:47 +02:00
parent 0003a52aaf
commit c5655468e3
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 12 additions and 8 deletions

View file

@ -188,16 +188,20 @@ pub fn get_arguments(id: ID) ?[]const ArgumentType {
return (commands.items[id] orelse return null).meta.arguments; return (commands.items[id] orelse return null).meta.arguments;
} }
const suppressed_errors = .{ const suppressed_errors = std.StaticStringMap(void).initComptime(.{
"enable_fast_scroll", .{ "enable_fast_scroll", void },
"disable_fast_scroll", .{ "disable_fast_scroll", void },
"clear_diagnostics", .{ "clear_diagnostics", void },
}; });
pub fn executeName(name: []const u8, ctx: Context) tp.result { pub fn executeName(name: []const u8, ctx: Context) tp.result {
const id = get_id(name); const id = get_id(name);
if (id) |id_| return execute(id_, ctx); if (id) |id_| return execute(id_, ctx);
inline for (suppressed_errors) |err| if (std.mem.eql(u8, err, name)) return; return notFoundError(name);
}
pub fn notFoundError(name: []const u8) !void {
if (!suppressed_errors.has(name))
return tp.exit_fmt("CommandNotFound: {s}", .{name}); return tp.exit_fmt("CommandNotFound: {s}", .{name});
} }

View file

@ -291,7 +291,7 @@ const Command = struct {
fn execute(self: *@This()) !void { fn execute(self: *@This()) !void {
const id = self.command_id orelse const id = self.command_id orelse
command.get_id_cache(self.command, &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; var buf: [2048]u8 = undefined;
@memcpy(buf[0..self.args.len], self.args); @memcpy(buf[0..self.args.len], self.args);