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 protocol = require 'vim.lsp.protocol'
|
||||||
local ts_utils = require 'nvim-lsp-ts-utils'
|
local ts_utils = require 'nvim-lsp-ts-utils'
|
||||||
local util = require 'lspconfig/util'
|
local util = require 'lspconfig/util'
|
||||||
|
local lightbulb = require 'nvim-lightbulb'
|
||||||
|
|
||||||
-- https://github.com/neovim/nvim-lspconfig/wiki/User-contributed-tips
|
-- https://github.com/neovim/nvim-lspconfig/wiki/User-contributed-tips
|
||||||
function FormatRangeOperator()
|
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)
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
||||||
end
|
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
|
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_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_create_autocmd({"CursorHold", "CursorHoldI", "InsertLeave"}, {
|
||||||
vim.api.nvim_command [[autocmd CursorHold,CursorHoldI <buffer> lua require'nvim-lightbulb'.update_lightbulb()]]
|
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
|
end
|
||||||
|
|
||||||
if client.resolved_capabilities.document_highlight then
|
if client.resolved_capabilities.document_highlight then
|
||||||
vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]]
|
vim.api.nvim_create_autocmd("CursorHold", {
|
||||||
vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]]
|
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue