125 lines
3.7 KiB
Lua
125 lines
3.7 KiB
Lua
-- lua/nuwiki/health.lua — `:checkhealth nuwiki` target.
|
|
--
|
|
-- Core checks: binary, version, filetype, LSP attach.
|
|
-- Additional checks: registered LSP commands, indexed wikis, HTML
|
|
-- output path writability, default keymaps installed.
|
|
|
|
local M = {}
|
|
|
|
local function bin_section()
|
|
local install = require('nuwiki.install')
|
|
local bin = install.expected_path()
|
|
if install.is_installed() then
|
|
vim.health.ok('binary present at ' .. bin)
|
|
local out = vim.fn.system({ bin, '--version' })
|
|
if vim.v.shell_error == 0 then
|
|
vim.health.ok('binary --version: ' .. (out:gsub('\n', ' ')):gsub('^%s+', ''))
|
|
else
|
|
vim.health.warn(
|
|
'binary did not respond to --version',
|
|
{ 'Re-install with :lua require("nuwiki").install()' }
|
|
)
|
|
end
|
|
else
|
|
vim.health.error(
|
|
'binary not found at ' .. bin,
|
|
{ 'Run :lua require("nuwiki").install() to install' }
|
|
)
|
|
end
|
|
end
|
|
|
|
local function wiki_root_section(opts)
|
|
local root = vim.fn.expand(opts.wiki_root or '')
|
|
if root ~= '' then
|
|
if vim.fn.isdirectory(root) == 1 then
|
|
vim.health.ok('wiki_root exists: ' .. root)
|
|
else
|
|
vim.health.warn('wiki_root does not exist: ' .. root)
|
|
end
|
|
end
|
|
end
|
|
|
|
local function filetype_section()
|
|
if vim.fn.exists('#filetypedetect#BufRead#*.wiki') ~= 0
|
|
or vim.filetype.match({ filename = 'test.wiki' }) == 'vimwiki' then
|
|
vim.health.ok('filetype detection for *.wiki is wired up')
|
|
else
|
|
vim.health.warn('filetype detection for *.wiki not active')
|
|
end
|
|
end
|
|
|
|
local function clients()
|
|
return (vim.lsp.get_clients or vim.lsp.get_active_clients)({ name = 'nuwiki' })
|
|
end
|
|
|
|
local function lsp_section()
|
|
local cs = clients()
|
|
if cs and #cs > 0 then
|
|
vim.health.ok('LSP client attached (' .. #cs .. ' instance(s))')
|
|
local cl = cs[1]
|
|
local cmds = vim.tbl_get(
|
|
cl,
|
|
'server_capabilities',
|
|
'executeCommandProvider',
|
|
'commands'
|
|
) or {}
|
|
if #cmds > 0 then
|
|
vim.health.ok('server advertises ' .. #cmds .. ' executeCommand entries')
|
|
else
|
|
vim.health.info('server has not yet reported executeCommand entries')
|
|
end
|
|
local folding = vim.tbl_get(cl, 'server_capabilities', 'foldingRangeProvider')
|
|
if folding then
|
|
vim.health.ok('server supports textDocument/foldingRange')
|
|
else
|
|
vim.health.info('server has not advertised foldingRange capability')
|
|
end
|
|
else
|
|
vim.health.info('LSP client not yet attached — open a .wiki buffer')
|
|
end
|
|
end
|
|
|
|
local function html_section(opts)
|
|
local html_path = (opts.wikis and opts.wikis[1] and opts.wikis[1].html_path)
|
|
or (opts.wiki_root and (vim.fn.expand(opts.wiki_root) .. '/_html'))
|
|
if not html_path or html_path == '' then
|
|
return
|
|
end
|
|
if vim.fn.isdirectory(html_path) == 1 then
|
|
-- Probe writability with `filewritable` on the directory.
|
|
if vim.fn.filewritable(html_path) == 2 then
|
|
vim.health.ok('html output dir writable: ' .. html_path)
|
|
else
|
|
vim.health.warn('html output dir exists but not writable: ' .. html_path)
|
|
end
|
|
else
|
|
vim.health.info(
|
|
'html output dir does not exist yet (created on first export): ' .. html_path
|
|
)
|
|
end
|
|
end
|
|
|
|
local function mappings_section(opts)
|
|
if opts.mappings and opts.mappings.enabled == false then
|
|
vim.health.info('default keymaps disabled by user config')
|
|
return
|
|
end
|
|
vim.health.ok('default keymaps enabled (subgroups: '
|
|
.. table.concat(vim.tbl_keys(opts.mappings or {}), ',') .. ')')
|
|
end
|
|
|
|
function M.check()
|
|
local config = require('nuwiki.config')
|
|
local opts = config.options or config.defaults
|
|
|
|
vim.health.start('nuwiki')
|
|
bin_section()
|
|
wiki_root_section(opts)
|
|
filetype_section()
|
|
lsp_section()
|
|
html_section(opts)
|
|
mappings_section(opts)
|
|
end
|
|
|
|
return M
|