preview.nvim/lua/preview
Barrett Ruth 239f8a4769
fix(compiler): defer open until successful compile, close viewer on :bd (#38)
* fix(compiler): defer open until successful compile, close viewer on :bd

Problem: For long-running providers (e.g. `typst watch`), the viewer
was opened immediately on toggle start by checking if the output file
existed on disk. A stale PDF from a prior session satisfied that check,
so a failed compile still opened the viewer. Additionally, viewer
processes spawned via a table `open` command were untracked, so `:bd`
killed the compiler but left the viewer running.

Solution: Replace the immediate open with a `vim.uv.new_fs_event`
directory watcher that fires only when the output file's `mtime`
advances past its pre-compile value, proving the current session wrote
it. Add `viewer_procs` and `open_watchers` tables with `close_viewer`
and `stop_open_watcher` helpers; all `BufUnload` paths and `stop_all`
now tear down both. Extract `do_open` to deduplicate the open branching
logic across three call sites.

* docs: document viewer auto-close behaviour and limitations in `open` field

* ci: format
2026-03-04 15:48:30 -05:00
..
commands.lua fix: lifecycle cleanup and defensive runtime checks (#29) 2026-03-04 14:02:16 -05:00
compiler.lua fix(compiler): defer open until successful compile, close viewer on :bd (#38) 2026-03-04 15:48:30 -05:00
diagnostic.lua fix(presets): correct error parsers for real compiler output (#11) 2026-03-03 14:14:59 -05:00
health.lua feat: rename watch → toggle, auto-compile on start, built-in opener 2026-03-02 23:37:44 -05:00
init.lua fix: lifecycle cleanup and defensive runtime checks (#29) 2026-03-04 14:02:16 -05:00
log.lua feat: rename 2026-03-02 21:23:40 -05:00
presets.lua fix(presets): add --failure-level ERROR to asciidoctor, add clean to typst/pdflatex/tectonic, skip auto-open on one-shot compile (#35) 2026-03-04 14:57:36 -05:00
reload.lua fix(reload): bind SSE server to port 0 for OS-assigned port (#21) 2026-03-03 17:46:04 -05:00