nvim: lsp: Refactor setting up of autocmd for code lens & document highlight

This commit is contained in:
Sanchayan Maity 2022-05-02 09:28:36 +05:30
parent fdc17306b7
commit 59b1696ffa

View file

@ -144,41 +144,41 @@ local on_attach = function(client, bufnr)
if client.server_capabilities.codeLensProvider or client.server_capabilities.documentHighlightProvider then if client.server_capabilities.codeLensProvider or client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_augroup("LSP", {clear = true}) vim.api.nvim_create_augroup("LSP", {clear = true})
end
if client.server_capabilities.codeLensProvider then if client.server_capabilities.codeLensProvider then
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>l", "<cmd>lua vim.lsp.codelens.run()<CR>", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>l", "<cmd>lua vim.lsp.codelens.run()<CR>", opts)
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI", "InsertLeave"}, { vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI", "InsertLeave"}, {
group = "LSP", group = "LSP",
buffer = bufnr, buffer = bufnr,
callback = function () callback = function ()
vim.lsp.codelens.refresh() vim.lsp.codelens.refresh()
end, end,
}) })
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, { vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {
group = "LSP", group = "LSP",
buffer = bufnr, buffer = bufnr,
callback = function () callback = function ()
lightbulb.update_lightbulb() lightbulb.update_lightbulb()
end, end,
}) })
end end
if client.server_capabilities.documentHighlightProvider then if client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd("CursorHold", { vim.api.nvim_create_autocmd("CursorHold", {
group = "LSP", group = "LSP",
buffer = bufnr, buffer = bufnr,
callback = function () callback = function ()
vim.lsp.buf.document_highlight() vim.lsp.buf.document_highlight()
end, end,
}) })
vim.api.nvim_create_autocmd("CursorMoved", { vim.api.nvim_create_autocmd("CursorMoved", {
group = "LSP", group = "LSP",
buffer = bufnr, buffer = bufnr,
callback = function () callback = function ()
vim.lsp.buf.clear_references() vim.lsp.buf.clear_references()
end, end,
}) })
end
end end
end end