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.
This commit is contained in:
parent
047e169c21
commit
e513fc57d1
2 changed files with 19 additions and 2 deletions
|
|
@ -329,6 +329,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
|
||||||
s.provider = name
|
s.provider = name
|
||||||
s.is_reload = true
|
s.is_reload = true
|
||||||
|
|
||||||
|
if not opts.silent then
|
||||||
|
vim.notify('[preview.nvim]: compiling...', vim.log.levels.INFO)
|
||||||
|
end
|
||||||
vim.api.nvim_exec_autocmds('User', {
|
vim.api.nvim_exec_autocmds('User', {
|
||||||
pattern = 'PreviewCompileStarted',
|
pattern = 'PreviewCompileStarted',
|
||||||
data = { bufnr = bufnr, provider = name },
|
data = { bufnr = bufnr, provider = name },
|
||||||
|
|
@ -360,6 +363,7 @@ function M.compile(bufnr, name, provider, ctx, opts)
|
||||||
end
|
end
|
||||||
if result.code == 0 then
|
if result.code == 0 then
|
||||||
log.dbg('compilation succeeded for buffer %d', bufnr)
|
log.dbg('compilation succeeded for buffer %d', bufnr)
|
||||||
|
vim.notify('[preview.nvim]: compilation complete', vim.log.levels.INFO)
|
||||||
clear_errors(bufnr, provider)
|
clear_errors(bufnr, provider)
|
||||||
vim.api.nvim_exec_autocmds('User', {
|
vim.api.nvim_exec_autocmds('User', {
|
||||||
pattern = 'PreviewCompileSuccess',
|
pattern = 'PreviewCompileSuccess',
|
||||||
|
|
@ -403,6 +407,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
|
||||||
s.provider = name
|
s.provider = name
|
||||||
s.is_reload = false
|
s.is_reload = false
|
||||||
|
|
||||||
|
if not opts.silent then
|
||||||
|
vim.notify('[preview.nvim]: compiling...', vim.log.levels.INFO)
|
||||||
|
end
|
||||||
vim.api.nvim_exec_autocmds('User', {
|
vim.api.nvim_exec_autocmds('User', {
|
||||||
pattern = 'PreviewCompileStarted',
|
pattern = 'PreviewCompileStarted',
|
||||||
data = { bufnr = bufnr, provider = name },
|
data = { bufnr = bufnr, provider = name },
|
||||||
|
|
@ -512,8 +519,8 @@ function M.toggle(bufnr, name, provider, ctx_builder)
|
||||||
log.dbg('watching buffer %d with provider "%s"', bufnr, name)
|
log.dbg('watching buffer %d with provider "%s"', bufnr, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.notify('[preview.nvim]: watching with "' .. name .. '"', vim.log.levels.INFO)
|
vim.notify('[preview.nvim]: compiling with "' .. name .. '"...', vim.log.levels.INFO)
|
||||||
M.compile(bufnr, name, provider, ctx_builder(bufnr))
|
M.compile(bufnr, name, provider, ctx_builder(bufnr), { silent = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,14 @@ describe('compiler', function()
|
||||||
end,
|
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 provider = { cmd = { 'echo', 'ok' } }
|
||||||
local ctx = {
|
local ctx = {
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
|
|
@ -64,7 +72,9 @@ describe('compiler', function()
|
||||||
}
|
}
|
||||||
|
|
||||||
compiler.compile(bufnr, 'echo', provider, ctx)
|
compiler.compile(bufnr, 'echo', provider, ctx)
|
||||||
|
vim.notify = orig
|
||||||
assert.is_true(fired)
|
assert.is_true(fired)
|
||||||
|
assert.is_true(notified)
|
||||||
|
|
||||||
vim.wait(2000, function()
|
vim.wait(2000, function()
|
||||||
return process_done(bufnr)
|
return process_done(bufnr)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue