feat: compile notifications and long-running provider feedback (#55)
* feat(compiler): add compile start/complete notifications Problem: No user-facing feedback when compilation starts or finishes. Long-running compilers like pandoc with `--embed-resources` leave the user staring at nothing for 15+ seconds. Solution: Notify "compiling..." at compile start and "compilation complete" on success. The initial `toggle` call uses a combined "compiling with <name>..." message to avoid stacking two notifications. * refactor(presets): use `--katex` instead of `--embed-resources --mathml` Problem: `--embed-resources` with `--mathml` caused pandoc to inline all assets at compile time, adding ~15s per save for KaTeX-heavy documents. Solution: Default to `--katex`, which inserts a CDN `<script>` tag and defers rendering to the browser. Users can opt into `--embed-resources` or `--mathml` via `extra_args`. * docs(presets): rewrite math rendering section for `--katex` default * refactor(compiler): simplify notification flow, add failure notify Problem: `compile()` used an `opts.silent` escape hatch so `toggle()` could suppress duplicate notifications. Compilation failures had no user-facing notification. Solution: Remove `opts.silent` — `compile()` unconditionally notifies on start, success, and failure. `toggle()` no longer emits its own message. * feat(compiler): add per-recompile notifications for long-running providers Problem: long-running providers like `typst watch` had no per-recompile feedback — the process stays alive and individual success/failure was never reported. Solution: add a persistent `output_watcher` fs_event that fires "compilation complete" on every output mtime bump, and track `has_errors` on `BufState` so stderr diagnostics trigger a one-shot "compilation failed" notification. `diagnostic.set()` now returns the diagnostic count to support this flow. * ci: format * chore: remove testing files
This commit is contained in:
parent
aeea1bd8fa
commit
39406c559c
7 changed files with 217 additions and 44 deletions
|
|
@ -55,6 +55,14 @@ describe('compiler', function()
|
|||
end,
|
||||
})
|
||||
|
||||
local notified = false
|
||||
local orig = vim.notify
|
||||
vim.notify = function(msg)
|
||||
if msg:find('compiling') then
|
||||
notified = true
|
||||
end
|
||||
end
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx = {
|
||||
bufnr = bufnr,
|
||||
|
|
@ -64,7 +72,9 @@ describe('compiler', function()
|
|||
}
|
||||
|
||||
compiler.compile(bufnr, 'echo', provider, ctx)
|
||||
vim.notify = orig
|
||||
assert.is_true(fired)
|
||||
assert.is_true(notified)
|
||||
|
||||
vim.wait(2000, function()
|
||||
return process_done(bufnr)
|
||||
|
|
@ -269,6 +279,58 @@ describe('compiler', function()
|
|||
end)
|
||||
end)
|
||||
|
||||
describe('long-running notifications', function()
|
||||
it('notifies failure on stderr diagnostics', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_longrun.txt')
|
||||
vim.bo[bufnr].modified = false
|
||||
|
||||
local notified_fail = false
|
||||
local orig = vim.notify
|
||||
vim.notify = function(msg, level)
|
||||
if msg:find('compilation failed') and level == vim.log.levels.ERROR then
|
||||
notified_fail = true
|
||||
end
|
||||
end
|
||||
|
||||
local provider = {
|
||||
cmd = { 'sh' },
|
||||
reload = function()
|
||||
return { 'sh', '-c', 'echo "error: bad input" >&2; sleep 60' }
|
||||
end,
|
||||
error_parser = function()
|
||||
return {
|
||||
{ lnum = 0, col = 0, message = 'bad input', severity = vim.diagnostic.severity.ERROR },
|
||||
}
|
||||
end,
|
||||
}
|
||||
local ctx = {
|
||||
bufnr = bufnr,
|
||||
file = '/tmp/preview_test_longrun.txt',
|
||||
root = '/tmp',
|
||||
ft = 'text',
|
||||
}
|
||||
|
||||
compiler.compile(bufnr, 'testprov', provider, ctx)
|
||||
|
||||
vim.wait(3000, function()
|
||||
return notified_fail
|
||||
end, 50)
|
||||
|
||||
vim.notify = orig
|
||||
assert.is_true(notified_fail)
|
||||
|
||||
local s = compiler._test.state[bufnr]
|
||||
assert.is_true(s.has_errors)
|
||||
|
||||
compiler.stop(bufnr)
|
||||
vim.wait(2000, function()
|
||||
return process_done(bufnr)
|
||||
end, 50)
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('stop', function()
|
||||
it('does nothing when no process is active', function()
|
||||
assert.has_no.errors(function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue