phase 9: editor glue — plugin, LSP wiring, install, health, docs
P5 + P6 resolved (SPEC §11): Neovim 0.11+ and Vim 9.1+.
Universal Vim entry:
- plugin/nuwiki.vim dispatches Vim vs Neovim. Neovim path waits for
the user's `require('nuwiki').setup()` call; Vim path starts the
LSP client on `FileType vimwiki` and exposes `:NuwikiInstall`.
- ftdetect/nuwiki.vim associates `*.wiki` with the `vimwiki` filetype.
- ftplugin/nuwiki.vim sets commentstring + comments + formatoptions +
suffixesadd + iskeyword, with a clean `b:undo_ftplugin`.
- syntax/nuwiki.vim ships default `@vimwiki*` highlight links for the
semantic-token legend (with `level1..6` + `centered` modifiers),
plus a minimal regex fallback so static highlighting works before
the LSP attaches.
Lua glue (Neovim 0.11+):
- init.lua exposes setup() / install() / health() — wiring only per
SPEC §6.2.
- config.lua holds the §7.5 schema (wiki_root / file_extension /
syntax / log_level) and a tbl_deep_extend apply().
- lsp.lua registers via `vim.lsp.config{} + vim.lsp.enable` on 0.11+;
falls back to a FileType autocmd calling `vim.lsp.start` on older
builds. Root dir walks up for `.git` / `.nuwiki`, then uses
wiki_root.
- install.lua does target-triple detection (Linux gnu/musl x x86_64/
aarch64, macOS arm/x86, Windows), curl+tar download from the
release URL, cp/chmod into bin/, with a cargo fallback. Honours
`g:nuwiki_build_from_source`.
- health.lua implements `:checkhealth nuwiki` per §7.6.
VimL glue (Vim 9.1+):
- autoload/nuwiki/lsp.vim follows §7.4 preference order:
vim-lsp (calls `lsp#register_server`) → coc.nvim (prints the
coc-settings.json snippet) → error.
- scripts/download_bin.vim mirrors the Lua installer for Dein /
vim-plug build hooks — same target triples, same download →
fallback → cargo build chain.
Help: doc/nuwiki.txt with tags for install (lazy.nvim / vim-plug /
Dein), config options, health, LSP feature list, `:NuwikiInstall`.
Rust workspace unchanged this phase; 172 tests still green locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
-- lua/nuwiki/health.lua — `:checkhealth nuwiki` target.
|
||||
--
|
||||
-- Checks per SPEC §7.6: binary exists, is executable, LSP client running,
|
||||
-- filetype detection works for `.wiki`.
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.check()
|
||||
local install = require('nuwiki.install')
|
||||
local config = require('nuwiki.config')
|
||||
|
||||
vim.health.start('nuwiki')
|
||||
|
||||
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
|
||||
|
||||
local root = vim.fn.expand(config.options.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
|
||||
|
||||
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
|
||||
|
||||
local clients = vim.lsp.get_clients and vim.lsp.get_clients({ name = 'nuwiki' })
|
||||
or vim.lsp.get_active_clients({ name = 'nuwiki' })
|
||||
if clients and #clients > 0 then
|
||||
vim.health.ok('LSP client attached (' .. #clients .. ' instance(s))')
|
||||
else
|
||||
vim.health.info('LSP client not yet attached — open a .wiki buffer')
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user