@@ -6,6 +6,8 @@ local AUGROUP_NAME = "TinyInlineDiagnosticAutocmds"
66
77local attached_buffers = {}
88local last_cursor_positions = {}
9+ --- @type number | nil
10+ local augroup_id = nil
911
1012--- @param bufnr number
1113--- @return boolean
@@ -21,6 +23,9 @@ function M.detach(bufnr, cleanup_callback)
2123 attached_buffers [bufnr ] = nil
2224 last_cursor_positions [bufnr ] = nil
2325 cache .clear (bufnr )
26+ if augroup_id and vim .api .nvim_buf_is_valid (bufnr ) then
27+ pcall (vim .api .nvim_clear_autocmds , { group = augroup_id , buffer = bufnr })
28+ end
2429 if cleanup_callback then
2530 cleanup_callback (bufnr )
2631 end
@@ -146,14 +151,22 @@ function M.setup_buffer_autocmds(
146151 M .detach (event .buf )
147152 end ,
148153 })
154+ end
149155
156+ --- @param autocmd_ns number
157+ --- @param opts table
158+ --- @param direct_apply function
159+ --- @param on_window_change function
160+ function M .setup_global_autocmds (autocmd_ns , opts , direct_apply , on_window_change )
150161 vim .api .nvim_create_autocmd ({ " VimResized" , " WinResized" }, {
151162 group = autocmd_ns ,
152163 callback = function ()
153- if vim .api .nvim_buf_is_valid (bufnr ) then
154- direct_apply (bufnr )
155- else
156- M .detach (bufnr )
164+ for bufnr , _ in pairs (attached_buffers ) do
165+ if vim .api .nvim_buf_is_valid (bufnr ) then
166+ direct_apply (bufnr )
167+ else
168+ M .detach (bufnr )
169+ end
157170 end
158171 end ,
159172 desc = " Update diagnostics on window resize" ,
170183
171184--- @return number
172185function M .create_augroup ()
173- return vim .api .nvim_create_augroup (AUGROUP_NAME , { clear = true })
186+ local id = vim .api .nvim_create_augroup (AUGROUP_NAME , { clear = true })
187+ augroup_id = id
188+ attached_buffers = {}
189+ last_cursor_positions = {}
190+ return id
174191end
175192
176193return M
0 commit comments