Problem: :Preview watch only registered a BufWritePost autocmd without
compiling immediately, required boilerplate to open output files after
first compilation, and was misleadingly named.
Solution: Rename watch → toggle throughout. M.toggle now compiles
immediately on activation. Add an open field to ProviderConfig: true
calls vim.ui.open(), a string[] runs the command with the output path
appended, tracked per-buffer so the file opens only once. All presets
default to { 'xdg-open' }. Health check validates opener binaries.
Guard the async compile callback against invalid buffer ids.
39 lines
1.1 KiB
Lua
39 lines
1.1 KiB
Lua
local M = {}
|
|
|
|
function M.check()
|
|
vim.health.start('preview.nvim')
|
|
|
|
if vim.fn.has('nvim-0.11.0') == 1 then
|
|
vim.health.ok('Neovim 0.11.0+ detected')
|
|
else
|
|
vim.health.error('preview.nvim requires Neovim 0.11.0+')
|
|
end
|
|
|
|
local config = require('preview').get_config()
|
|
|
|
local provider_count = vim.tbl_count(config.providers)
|
|
if provider_count == 0 then
|
|
vim.health.warn('no providers configured')
|
|
else
|
|
vim.health.ok(provider_count .. ' provider(s) configured')
|
|
end
|
|
|
|
for ft, provider in pairs(config.providers) do
|
|
local bin = provider.cmd[1]
|
|
if vim.fn.executable(bin) == 1 then
|
|
vim.health.ok('filetype "' .. ft .. '": ' .. bin .. ' found')
|
|
else
|
|
vim.health.error('filetype "' .. ft .. '": ' .. bin .. ' not found')
|
|
end
|
|
if type(provider.open) == 'table' then
|
|
local opener = provider.open[1]
|
|
if vim.fn.executable(opener) == 1 then
|
|
vim.health.ok('filetype "' .. ft .. '": opener ' .. opener .. ' found')
|
|
else
|
|
vim.health.error('filetype "' .. ft .. '": opener ' .. opener .. ' not found')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|