nvim: lsp: Use the new auto command API
This commit is contained in:
parent
39acdb222f
commit
28049ed540
1 changed files with 33 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue