fix(compiler): guard active entry before clearing in process callback

Problem: when M.compile() is called while a previous process is still
running, the old process's vim.schedule_wrap callback unconditionally
sets active[bufnr] = nil, wiping the new process from the tracking
table. status() incorrectly returns idle and stop() becomes a no-op
against the still-running process.

Solution: capture obj as an upvalue in each callback and only clear
active[bufnr] if it still points to the same process object.
This commit is contained in:
Barrett Ruth 2026-03-03 17:49:28 -05:00
parent e661ea78e8
commit 4b1f95064f
Signed by: barrett
GPG key ID: A6C96C9349D2FC81

View file

@ -98,7 +98,9 @@ function M.compile(bufnr, name, provider, ctx)
env = provider.env,
},
vim.schedule_wrap(function(result)
active[bufnr] = nil
if active[bufnr] and active[bufnr].obj == obj then
active[bufnr] = nil
end
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
@ -187,7 +189,9 @@ function M.compile(bufnr, name, provider, ctx)
env = provider.env,
},
vim.schedule_wrap(function(result)
active[bufnr] = nil
if active[bufnr] and active[bufnr].obj == obj then
active[bufnr] = nil
end
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end