nvim: lsp: Use the new auto command API

This commit is contained in:
Sanchayan Maity 2022-03-06 13:11:12 +05:30
parent 39acdb222f
commit 28049ed540

View file

@ -2,6 +2,7 @@ local nvim_lsp = require 'lspconfig'
local protocol = require 'vim.lsp.protocol'
local ts_utils = require 'nvim-lsp-ts-utils'
local util = require 'lspconfig/util'
local lightbulb = require 'nvim-lightbulb'
-- https://github.com/neovim/nvim-lspconfig/wiki/User-contributed-tips
function FormatRangeOperator()
@ -138,15 +139,43 @@ local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
if client.resolved_capabilities.code_lens or client.resolved_capabilities.document_highlight then
vim.api.nvim_create_augroup("LSP", {clear = true})
end
if client.resolved_capabilities.code_lens then
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>l", "<cmd>lua vim.lsp.codelens.run()<CR>", opts)
vim.api.nvim_command [[autocmd CursorHold,CursorHoldI,InsertLeave <buffer> lua vim.lsp.codelens.refresh()]]
vim.api.nvim_command [[autocmd CursorHold,CursorHoldI <buffer> lua require'nvim-lightbulb'.update_lightbulb()]]
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.resolved_capabilities.document_highlight then
vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]]
vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]]
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