mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-27 11:19:02 +02:00
feat(keymaps): added support for lazy's per-mode keymap disabling
This commit is contained in:
parent
af9e452854
commit
1bc78272da
4 changed files with 68 additions and 53 deletions
|
@ -55,7 +55,7 @@ return {
|
|||
-- mason = false, -- set to false if you don't want this server to be installed with mason
|
||||
-- Use this to add any additional keymaps
|
||||
-- for specific lsp servers
|
||||
---@type LazyKeys[]
|
||||
---@type LazyKeysSpec[]
|
||||
-- keys = {},
|
||||
settings = {
|
||||
Lua = {
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
local M = {}
|
||||
|
||||
---@type PluginLspKeys
|
||||
---@type LazyKeysLspSpec[]|nil
|
||||
M._keys = nil
|
||||
|
||||
---@return (LazyKeys|{has?:string})[]
|
||||
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string}
|
||||
---@alias LazyKeysLsp LazyKeys|{has?:string}
|
||||
|
||||
---@return LazyKeysLspSpec[]
|
||||
function M.get()
|
||||
if not M._keys then
|
||||
---@class PluginLspKeys
|
||||
if M._keys then
|
||||
return M._keys
|
||||
end
|
||||
-- stylua: ignore
|
||||
M._keys = {
|
||||
{ "<leader>cd", vim.diagnostic.open_float, desc = "Line Diagnostics" },
|
||||
|
@ -42,20 +46,19 @@ function M.get()
|
|||
has = "codeAction",
|
||||
}
|
||||
}
|
||||
if require("lazyvim.util").has("inc-rename.nvim") then
|
||||
M._keys[#M._keys + 1] = {
|
||||
"<leader>cr",
|
||||
function()
|
||||
local inc_rename = require("inc_rename")
|
||||
return ":" .. inc_rename.config.cmd_name .. " " .. vim.fn.expand("<cword>")
|
||||
end,
|
||||
expr = true,
|
||||
desc = "Rename",
|
||||
has = "rename",
|
||||
}
|
||||
else
|
||||
M._keys[#M._keys + 1] = { "<leader>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" }
|
||||
end
|
||||
if require("lazyvim.util").has("inc-rename.nvim") then
|
||||
M._keys[#M._keys + 1] = {
|
||||
"<leader>cr",
|
||||
function()
|
||||
local inc_rename = require("inc_rename")
|
||||
return ":" .. inc_rename.config.cmd_name .. " " .. vim.fn.expand("<cword>")
|
||||
end,
|
||||
expr = true,
|
||||
desc = "Rename",
|
||||
has = "rename",
|
||||
}
|
||||
else
|
||||
M._keys[#M._keys + 1] = { "<leader>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" }
|
||||
end
|
||||
return M._keys
|
||||
end
|
||||
|
@ -72,34 +75,23 @@ function M.has(buffer, method)
|
|||
return false
|
||||
end
|
||||
|
||||
---@return (LazyKeys|{has?:string})[]
|
||||
function M.resolve(buffer)
|
||||
local Keys = require("lazy.core.handler.keys")
|
||||
local keymaps = {} ---@type table<string,LazyKeys|{has?:string}>
|
||||
|
||||
local function add(keymap)
|
||||
local keys = Keys.parse(keymap)
|
||||
if keys[2] == false then
|
||||
keymaps[keys.id] = nil
|
||||
else
|
||||
keymaps[keys.id] = keys
|
||||
end
|
||||
if not Keys.resolve then
|
||||
return {}
|
||||
end
|
||||
for _, keymap in ipairs(M.get()) do
|
||||
add(keymap)
|
||||
end
|
||||
|
||||
local spec = M.get()
|
||||
local opts = require("lazyvim.util").opts("nvim-lspconfig")
|
||||
local clients = vim.lsp.get_active_clients({ bufnr = buffer })
|
||||
for _, client in ipairs(clients) do
|
||||
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
|
||||
for _, keymap in ipairs(maps) do
|
||||
add(keymap)
|
||||
end
|
||||
vim.list_extend(spec, maps)
|
||||
end
|
||||
return keymaps
|
||||
return Keys.resolve(spec)
|
||||
end
|
||||
|
||||
function M.on_attach(client, buffer)
|
||||
function M.on_attach(_, buffer)
|
||||
local Keys = require("lazy.core.handler.keys")
|
||||
local keymaps = M.resolve(buffer)
|
||||
|
||||
|
@ -110,7 +102,7 @@ function M.on_attach(client, buffer)
|
|||
opts.has = nil
|
||||
opts.silent = opts.silent ~= false
|
||||
opts.buffer = buffer
|
||||
vim.keymap.set(keys.mode or "n", keys[1], keys[2], opts)
|
||||
vim.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue