Compare commits

...

2 commits

Author SHA1 Message Date
bc2fbec083
refactor: clean-up std.StaticStringMap naming 2025-07-15 13:17:04 +02:00
c5655468e3
fix: make keybind module respect command.suppressed_errors list
Also, make suppressed_errors a static string map for a little extra
performance.
2025-07-15 13:16:56 +02:00
4 changed files with 16 additions and 12 deletions

View file

@ -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 {

View file

@ -18,7 +18,7 @@ const SelectionStyle = @import("Buffer").Selection.Style;
const parse_flow = @import("parse_flow.zig");
const parse_vim = @import("parse_vim.zig");
const builtin_keybinds = std.static_string_map.StaticStringMap([]const u8).initComptime(.{
const builtin_keybinds = std.StaticStringMap([]const u8).initComptime(.{
.{ "flow", @embedFile("builtin/flow.json") },
.{ "vim", @embedFile("builtin/vim.json") },
.{ "helix", @embedFile("builtin/helix.json") },
@ -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);

View file

@ -95,7 +95,7 @@ pub const FirstLineMatch = struct {
};
const static_file_type_list = load_file_types(@import("file_types.zig"));
const static_file_types = std.static_string_map.StaticStringMap(FileType).initComptime(static_file_type_list);
const static_file_types = std.StaticStringMap(FileType).initComptime(static_file_type_list);
fn vec(comptime args: anytype) []const []const u8 {
var cmd: []const []const u8 = &[_][]const u8{};
@ -147,7 +147,7 @@ pub const FileTypeQueries = struct {
injections_bin: ?[]const u8,
};
pub const queries = std.static_string_map.StaticStringMap(FileTypeQueries).initComptime(load_queries());
pub const queries = std.StaticStringMap(FileTypeQueries).initComptime(load_queries());
fn load_queries() []const struct { []const u8, FileTypeQueries } {
if (!build_options.use_tree_sitter) return &.{};

View file

@ -5,7 +5,7 @@ const log = @import("log");
const Widget = @import("../Widget.zig");
const widgets = std.static_string_map.StaticStringMap(CreateFunction).initComptime(.{
const widgets = std.StaticStringMap(CreateFunction).initComptime(.{
.{ "mode", @import("modestate.zig").create },
.{ "file", @import("filestate.zig").create },
.{ "log", @import("minilog.zig").create },