Skip to content

Commit

Permalink
feat: add types to arguments of register, and validate it
Browse files Browse the repository at this point in the history
  • Loading branch information
pogyomo committed Jun 18, 2024
1 parent 766c3cd commit 597c2a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lua/submode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ function M.create(name, opts, default)
})
end

---@param lhs string
---@param rhs string | fun():string?
---@param opts_ vim.keymap.set.Opts?
local register = function(lhs, rhs, opts_)
vim.validate {
lhs = { lhs, "string" },
rhs = { rhs, { "string", "function" } },
opts = { opts_, "table", true },
}
M.state.submode_to_default_mappings[name][lhs] = {
rhs = rhs,
opts = opts_,
Expand Down
2 changes: 1 addition & 1 deletion lua/submode/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
---Infomation of mapping except lhs.
---@class SubmodeMappingElement
---@field rhs string | fun():string?
---@field opts? table
---@field opts? vim.keymap.set.Opts

---@alias SubmodeDefaultMappingRegister fun(lhs: string, rhs: string | function, opts: vim.keymap.set.Opts?)

0 comments on commit 597c2a7

Please sign in to comment.