fix(commands): register VimLeavePre to call stop_all
Problem: spawned compiler processes and watching autocmds were never cleaned up when Neovim exited, leaving orphaned processes running. Solution: register a VimLeavePre autocmd in commands setup that calls compiler.stop_all(), which kills active processes, unwatches all buffers, and stops the reload server.
This commit is contained in:
parent
75b855438a
commit
9d4f2e77cc
2 changed files with 19 additions and 0 deletions
|
|
@ -57,6 +57,12 @@ function M.setup()
|
|||
end,
|
||||
desc = 'Toggle, compile, clean, open, or check status of document preview',
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('VimLeavePre', {
|
||||
callback = function()
|
||||
require('preview.compiler').stop_all()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -11,6 +11,19 @@ describe('commands', function()
|
|||
local cmds = vim.api.nvim_get_commands({})
|
||||
assert.is_not_nil(cmds.Preview)
|
||||
end)
|
||||
|
||||
it('registers VimLeavePre autocmd', function()
|
||||
require('preview.commands').setup()
|
||||
local aus = vim.api.nvim_get_autocmds({ event = 'VimLeavePre' })
|
||||
local found = false
|
||||
for _, au in ipairs(aus) do
|
||||
if au.callback then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_true(found)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('dispatch', function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue