Delete the highlight autocommands in the LspDetatch event

This commit is contained in:
Francis Belanger 2024-04-22 08:29:42 -04:00
parent 4d73020681
commit f45cec078c
1 changed files with 13 additions and 13 deletions

View File

@ -514,25 +514,17 @@ require('lazy').setup({
-- When you move your cursor, the highlights will be cleared (the second autocommand). -- When you move your cursor, the highlights will be cleared (the second autocommand).
local client = vim.lsp.get_client_by_id(event.data.client_id) local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.server_capabilities.documentHighlightProvider then if client and client.server_capabilities.documentHighlightProvider then
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = true })
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf, buffer = event.buf,
callback = function() group = highlight_augroup,
if not vim.lsp.get_client_by_id(event.data.client_id) then callback = vim.lsp.buf.document_highlight,
vim.lsp.buf.clear_references()
return true
end
vim.lsp.buf.document_highlight()
end,
}) })
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf, buffer = event.buf,
callback = function() group = highlight_augroup,
if not vim.lsp.get_client_by_id(event.data.client_id) then callback = vim.lsp.buf.clear_references,
return true
end
vim.lsp.buf.clear_references()
end,
}) })
end end
@ -548,6 +540,14 @@ require('lazy').setup({
end, end,
}) })
vim.api.nvim_create_autocmd('LspDetach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
callback = function()
vim.lsp.buf.clear_references()
vim.api.nvim_del_augroup_by_name 'kickstart-lsp-highlight'
end,
})
-- LSP servers and clients are able to communicate to each other what features they support. -- LSP servers and clients are able to communicate to each other what features they support.
-- By default, Neovim doesn't support everything that is in the LSP specification. -- By default, Neovim doesn't support everything that is in the LSP specification.
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities. -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.