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
vim.api.nvim_create_augroup("LSP", {clear = true})
end
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_create_autocmd({"CursorHold", "CursorHoldI", "InsertLeave"}, {
group = "LSP",
buffer = bufnr,
callback = function ()
vim.lsp.codelens.refresh()
end,
})
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {
group = "LSP",
buffer = bufnr,
callback = function ()
lightbulb.update_lightbulb()
end,
})
end
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_create_autocmd({"CursorHold", "CursorHoldI", "InsertLeave"}, {
group = "LSP",
buffer = bufnr,
callback = function ()
vim.lsp.codelens.refresh()
end,
})
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {
group = "LSP",
buffer = bufnr,
callback = function ()
lightbulb.update_lightbulb()
end,
})
end
if client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd("CursorHold", {
group = "LSP",
buffer = bufnr,
callback = function ()
vim.lsp.buf.document_highlight()
end,
})
vim.api.nvim_create_autocmd("CursorMoved", {
group = "LSP",
buffer = bufnr,
callback = function ()
vim.lsp.buf.clear_references()
end,
})
if client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd("CursorHold", {
group = "LSP",
buffer = bufnr,
callback = function ()
vim.lsp.buf.document_highlight()
end,
})
vim.api.nvim_create_autocmd("CursorMoved", {
group = "LSP",
buffer = bufnr,
callback = function ()
vim.lsp.buf.clear_references()
end,
})
end
end
end