refactor(inc-selection): simplify keymap and add error message

This commit is contained in:
Maria José Solano 2024-01-31 20:37:47 -08:00 committed by Christian Clason
parent 1cda98132a
commit 140a486abe

View file

@ -5,6 +5,7 @@ local ts_utils = require "nvim-treesitter.ts_utils"
local locals = require "nvim-treesitter.locals"
local parsers = require "nvim-treesitter.parsers"
local queries = require "nvim-treesitter.query"
local utils = require "nvim-treesitter.utils"
local M = {}
@ -138,22 +139,14 @@ function M.attach(bufnr)
local config = configs.get_module "incremental_selection"
for funcname, mapping in pairs(config.keymaps) do
if mapping then
---@type string, string|function
local mode, rhs
if funcname == "init_selection" then
mode = "n"
---@type function
rhs = M[funcname]
local mode = funcname == "init_selection" and "n" or "x"
local rhs = M[funcname] ---@type function
if not rhs then
utils.notify("Unknown keybinding: " .. funcname .. debug.traceback(), vim.log.levels.ERROR)
else
mode = "x"
rhs = M[funcname] ---@type function
vim.keymap.set(mode, mapping, rhs, { buffer = bufnr, silent = true, desc = FUNCTION_DESCRIPTIONS[funcname] })
end
vim.keymap.set(
mode,
mapping,
rhs,
{ buffer = bufnr, silent = true, noremap = true, desc = FUNCTION_DESCRIPTIONS[funcname] }
)
end
end
end