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:
parent
0003a52aaf
commit
c5655468e3
2 changed files with 12 additions and 8 deletions
|
@ -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});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue