fix(compiler): add fs_stat check to one-shot open path

Problem: the long-running process path already guarded opens with
vim.uv.fs_stat(), but the one-shot compile path and M.open() did not.
Compilation can exit 0 and produce no output, and output files can be
externally deleted between compile and open.

Solution: add the same fs_stat guard to the one-shot open branch and
to M.open() before attempting to launch the viewer.
This commit is contained in:
Barrett Ruth 2026-03-04 13:49:50 -05:00
parent bc22350692
commit 1456b3070a
Signed by: barrett
GPG key ID: A6C96C9349D2FC81

View file

@ -230,7 +230,7 @@ function M.compile(bufnr, name, provider, ctx, opts)
r.inject(output_file)
r.broadcast()
end
if provider.open and not opened[bufnr] and output_file ~= '' then
if provider.open and not opened[bufnr] and output_file ~= '' and vim.uv.fs_stat(output_file) then
if provider.open == true then
vim.ui.open(output_file)
elseif type(provider.open) == 'table' then
@ -452,6 +452,10 @@ function M.open(bufnr, open_config)
log.dbg('no last output file for buffer %d', bufnr)
return false
end
if not vim.uv.fs_stat(output) then
log.dbg('output file no longer exists for buffer %d: %s', bufnr, output)
return false
end
if type(open_config) == 'table' then
local open_cmd = vim.list_extend({}, open_config)
table.insert(open_cmd, output)