Skip to content

Commit f192bd4

Browse files
committed
feat(nvim): clean up highlight autocmds at lsp detach
1 parent 72105d7 commit f192bd4

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • home/dot_config/exact_nvim/exact_plugin

home/dot_config/exact_nvim/exact_plugin/lsp.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ vim.api.nvim_create_autocmd('LspAttach', {
2020
---@type integer
2121
local highlight_group =
2222
vim.api.nvim_create_augroup('LspDocumentHighlight', { clear = false })
23+
local highlight_detach_group = vim.api.nvim_create_augroup(
24+
'LspDocumentHighlightDetach',
25+
{ clear = true }
26+
)
2327

2428
-- Clear existing highlights for this buffer.
2529
vim.api.nvim_clear_autocmds({ buffer = args.buf, group = highlight_group })
@@ -35,6 +39,17 @@ vim.api.nvim_create_autocmd('LspAttach', {
3539
buffer = args.buf,
3640
callback = vim.lsp.buf.clear_references,
3741
})
42+
43+
vim.api.nvim_create_autocmd('LspDetach', {
44+
group = highlight_detach_group,
45+
callback = function(event)
46+
vim.lsp.buf.clear_references()
47+
vim.api.nvim_clear_autocmds({
48+
group = highlight_group,
49+
buffer = event.buf,
50+
})
51+
end,
52+
})
3853
end
3954
end,
4055
})

0 commit comments

Comments
 (0)