fix(compiler): skip reload command for one-shot builds

Problem: compile() unconditionally resolved the reload command, so
:Preview build on a provider with reload = function/table (e.g. typst)
would start a long-running process (typst watch) instead of a one-shot
compile (typst compile). Error diagnostics were also lost because
typst watch does not exit non-zero on input errors.

Solution: add an opts parameter to compile() with a oneshot flag.
M.build() passes { oneshot = true } so resolve_reload_cmd() is
skipped and the one-shot path is always taken. toggle() continues
to call compile() without the flag, preserving long-running behavior
for watch mode.
This commit is contained in:
Barrett Ruth 2026-03-04 01:36:53 -05:00
parent da3e3e4249
commit c556ea9ea1
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
2 changed files with 8 additions and 3 deletions

View file

@ -55,7 +55,9 @@ end
---@param name string
---@param provider preview.ProviderConfig
---@param ctx preview.Context
function M.compile(bufnr, name, provider, ctx)
function M.compile(bufnr, name, provider, ctx, opts)
opts = opts or {}
if vim.bo[bufnr].modified then
vim.cmd('silent! update')
end
@ -81,7 +83,10 @@ function M.compile(bufnr, name, provider, ctx)
last_output[bufnr] = output_file
end
local reload_cmd = resolve_reload_cmd(provider, resolved_ctx)
local reload_cmd
if not opts.oneshot then
reload_cmd = resolve_reload_cmd(provider, resolved_ctx)
end
if reload_cmd then
log.dbg(