feat(lsp): properly update certain Neovim functionlity based on dynamic capabilities. See #3244. Fixes #3246

This commit is contained in:
Folke Lemaitre
2024-05-20 00:08:05 +02:00
parent 97862f4259
commit 20e002f9f0
2 changed files with 85 additions and 45 deletions

View File

@ -121,16 +121,8 @@ return {
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
end)
local register_capability = vim.lsp.handlers["client/registerCapability"]
vim.lsp.handlers["client/registerCapability"] = function(err, res, ctx)
---@diagnostic disable-next-line: no-unknown
local ret = register_capability(err, res, ctx)
local client = vim.lsp.get_client_by_id(ctx.client_id)
local buffer = vim.api.nvim_get_current_buf()
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
return ret
end
LazyVim.lsp.setup_dynamic_capability()
LazyVim.lsp.on_dynamic_capability(require("lazyvim.plugins.lsp.keymaps").on_attach)
LazyVim.lsp.words.setup(opts.document_highlight)
@ -148,24 +140,19 @@ return {
if vim.fn.has("nvim-0.10") == 1 then
-- inlay hints
if opts.inlay_hints.enabled then
LazyVim.lsp.on_attach(function(client, buffer)
if client.supports_method("textDocument/inlayHint") then
LazyVim.toggle.inlay_hints(buffer, true)
end
LazyVim.lsp.on_supports_method("textDocument/inlayHint", function(client, buffer)
LazyVim.toggle.inlay_hints(buffer, true)
end)
end
-- code lens
if opts.codelens.enabled and vim.lsp.codelens then
LazyVim.lsp.on_attach(function(client, buffer)
if client.supports_method("textDocument/codeLens") then
vim.lsp.codelens.refresh()
--- autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()
vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, {
buffer = buffer,
callback = vim.lsp.codelens.refresh,
})
end
LazyVim.lsp.on_supports_method("textDocument/codeLens", function(client, buffer)
vim.lsp.codelens.refresh()
vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, {
buffer = buffer,
callback = vim.lsp.codelens.refresh,
})
end)
end
end