fix(lsp): added support for has as array for lsp keymaps

This commit is contained in:
Folke Lemaitre
2024-05-29 16:31:16 +02:00
parent 38b8736b81
commit 01e6718e03

View File

@ -3,8 +3,8 @@ local M = {}
---@type LazyKeysLspSpec[]|nil
M._keys = nil
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string, cond?:fun():boolean}
---@alias LazyKeysLsp LazyKeys|{has?:string, cond?:fun():boolean}
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string|string[], cond?:fun():boolean}
---@alias LazyKeysLsp LazyKeys|{has?:string|string[], cond?:fun():boolean}
---@return LazyKeysLspSpec[]
function M.get()
@ -26,8 +26,7 @@ function M.get()
{ "<leader>cc", vim.lsp.codelens.run, desc = "Run Codelens", mode = { "n", "v" }, has = "codeLens" },
{ "<leader>cC", vim.lsp.codelens.refresh, desc = "Refresh & Display Codelens", mode = { "n" }, has = "codeLens" },
{ "<leader>cC", vim.lsp.codelens.refresh, desc = "Refresh & Display Codelens", mode = { "n" }, has = "codeLens" },
{ "<leader>cR", LazyVim.lsp.rename_file, desc = "Rename File", mode ={"n"}, has = "workspace/didRenameFiles"},
{ "<leader>cR", LazyVim.lsp.rename_file, desc = "Rename File", mode ={"n"}, has = "workspace/willRenameFiles"},
{ "<leader>cR", LazyVim.lsp.rename_file, desc = "Rename File", mode ={"n"}, has = { "workspace/didRenameFiles", "workspace/willRenameFiles" } },
{
"<leader>cA",
function()
@ -69,8 +68,16 @@ function M.get()
return M._keys
end
---@param method string
---@param method string|string[]
function M.has(buffer, method)
if type(method) == "table" then
for _, m in ipairs(method) do
if M.has(buffer, m) then
return true
end
end
return false
end
method = method:find("/") and method or "textDocument/" .. method
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do