Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(whichkey): use vim.keymap.set directly #2786

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions lua/lvim/core/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ M.config = function()
-- lvim.builtin.terminal.execs[#lvim.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"}
execs = {
{ "lazygit", "<leader>gg", "LazyGit", "float" },
{ "lazygit", "<c-\\><c-g>", "LazyGit", "float" },
},
}
end
Expand Down Expand Up @@ -76,23 +75,9 @@ M.add_exec = function(opts)
return
end

local exec_func = string.format(
"<cmd>lua require('lvim.core.terminal')._exec_toggle({ cmd = '%s', count = %d, direction = '%s'})<CR>",
opts.cmd,
opts.count,
opts.direction
)

require("lvim.keymappings").load {
normal_mode = { [opts.keymap] = exec_func },
term_mode = { [opts.keymap] = exec_func },
}

local wk_status_ok, wk = pcall(require, "which-key")
if not wk_status_ok then
return
end
wk.register({ [opts.keymap] = { opts.label } }, { mode = "n" })
vim.keymap.set({ "n", "t" }, opts.keymap, function()
M._exec_toggle { cmd = opts.cmd, count = opts.count, direction = opts.direction }
end, { desc = opts.label, noremap = true, silent = true })
end

M._exec_toggle = function(opts)
Expand Down
19 changes: 4 additions & 15 deletions lua/lvim/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,10 @@ local function add_lsp_buffer_keybindings(bufnr)
visual_mode = "v",
}

if lvim.builtin.which_key.active then
-- Remap using which_key
local status_ok, wk = pcall(require, "which-key")
if not status_ok then
return
end
for mode_name, mode_char in pairs(mappings) do
wk.register(lvim.lsp.buffer_mappings[mode_name], { mode = mode_char, buffer = bufnr })
end
else
-- Remap using nvim api
for mode_name, mode_char in pairs(mappings) do
for key, remap in pairs(lvim.lsp.buffer_mappings[mode_name]) do
vim.api.nvim_buf_set_keymap(bufnr, mode_char, key, remap[1], { noremap = true, silent = true })
end
for mode_name, mode_char in pairs(mappings) do
for key, remap in pairs(lvim.lsp.buffer_mappings[mode_name]) do
local opts = { buffer = bufnr, desc = remap[2], noremap = true, silent = true }
vim.keymap.set(mode_char, key, remap[1], opts)
end
end
end
Expand Down