Skip to content

Commit 463a3e6

Browse files
author
Raphaël CHARTIER
committed
fix(autocmds): run detach only when no LSP clients. Fixes #151
1 parent 994c13d commit 463a3e6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lua/tiny-inline-diagnostic/autocmds.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ function M.setup_buffer_autocmds(
9797
end,
9898
})
9999

100-
vim.api.nvim_create_autocmd({ "LspDetach", "BufDelete", "BufUnload", "BufWipeout" }, {
100+
vim.api.nvim_create_autocmd("LspDetach", {
101+
group = autocmd_ns,
102+
buffer = bufnr,
103+
callback = function(event)
104+
if #vim.lsp.get_clients({ bufnr = event.buf }) == 0 then
105+
M.detach(event.buf)
106+
end
107+
end,
108+
})
109+
110+
vim.api.nvim_create_autocmd({ "BufDelete", "BufUnload", "BufWipeout" }, {
101111
group = autocmd_ns,
102112
buffer = bufnr,
103113
callback = function(event)

lua/tiny-inline-diagnostic/diagnostic.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ function M.set_diagnostic_autocmds(opts)
4040
return
4141
end
4242

43+
if autocmds.is_attached(event.buf) then
44+
return
45+
end
46+
4347
local throttler = handlers.build_throttled_renderer(opts, renderer)
4448
local direct_renderer = handlers.build_direct_renderer(opts, renderer)
4549
timers.add(event.buf, throttler.timer)

0 commit comments

Comments
 (0)