From 597c2a78977ee577a39dfc51d23a7967ea2532b0 Mon Sep 17 00:00:00 2001 From: pogyomo Date: Tue, 18 Jun 2024 15:12:50 +0900 Subject: [PATCH] feat: add types to arguments of register, and validate it --- lua/submode/init.lua | 8 ++++++++ lua/submode/types.lua | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/submode/init.lua b/lua/submode/init.lua index 73a4d2d..5b37370 100644 --- a/lua/submode/init.lua +++ b/lua/submode/init.lua @@ -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_, diff --git a/lua/submode/types.lua b/lua/submode/types.lua index 9c6ddc3..5214c7c 100644 --- a/lua/submode/types.lua +++ b/lua/submode/types.lua @@ -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?)