ee61d40872
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>
76 lines
2.2 KiB
VimL
76 lines
2.2 KiB
VimL
" autoload/nuwiki/lsp.vim — Vim (non-Neovim) LSP client wiring.
|
|
"
|
|
" Spec §7.4 preference order:
|
|
" 1. vim-lsp (matoto/vim-lsp)
|
|
" 2. coc.nvim
|
|
" 3. Print an error if neither is available.
|
|
|
|
let s:started = 0
|
|
|
|
function! nuwiki#lsp#start() abort
|
|
if s:started
|
|
return
|
|
endif
|
|
let s:started = 1
|
|
|
|
let l:bin = s:bin_path()
|
|
if !executable(l:bin)
|
|
echohl ErrorMsg
|
|
echom 'nuwiki: language server not found at ' . l:bin
|
|
echom 'Run :NuwikiInstall to install the binary'
|
|
echohl None
|
|
return
|
|
endif
|
|
|
|
if exists('*lsp#register_server')
|
|
" vim-lsp
|
|
call lsp#register_server({
|
|
\ 'name': 'nuwiki',
|
|
\ 'cmd': {server_info -> [l:bin]},
|
|
\ 'allowlist': ['vimwiki'],
|
|
\ 'config': { 'settings': { 'nuwiki': s:settings() } },
|
|
\ })
|
|
return
|
|
endif
|
|
|
|
if exists(':CocConfig') == 2 || exists('*coc#config')
|
|
" coc.nvim — coc reads its server list from coc-settings.json.
|
|
" We can't inject it dynamically without owning the file, so just point
|
|
" the user at the snippet.
|
|
echohl WarningMsg
|
|
echom 'nuwiki: coc.nvim detected. Add this to your coc-settings.json:'
|
|
echom ' "languageserver": {'
|
|
echom ' "nuwiki": {'
|
|
echom ' "command": "' . l:bin . '",'
|
|
echom ' "filetypes": ["vimwiki"]'
|
|
echom ' }'
|
|
echom ' }'
|
|
echohl None
|
|
return
|
|
endif
|
|
|
|
echohl ErrorMsg
|
|
echom 'nuwiki: no supported LSP client found.'
|
|
echom 'Install vim-lsp (https://github.com/prabirshrestha/vim-lsp)'
|
|
echom 'or coc.nvim (https://github.com/neoclide/coc.nvim).'
|
|
echohl None
|
|
endfunction
|
|
|
|
function! s:bin_path() abort
|
|
if exists('g:nuwiki_binary_path') && filereadable(g:nuwiki_binary_path)
|
|
return g:nuwiki_binary_path
|
|
endif
|
|
let l:plugin_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h:h:h')
|
|
let l:suffix = has('win32') ? '.exe' : ''
|
|
return l:plugin_dir . '/bin/nuwiki-ls' . l:suffix
|
|
endfunction
|
|
|
|
function! s:settings() abort
|
|
return {
|
|
\ 'wiki_root': get(g:, 'nuwiki_wiki_root', '~/vimwiki'),
|
|
\ 'file_extension': get(g:, 'nuwiki_file_extension', '.wiki'),
|
|
\ 'syntax': get(g:, 'nuwiki_syntax', 'vimwiki'),
|
|
\ 'log_level': get(g:, 'nuwiki_log_level', 'warn'),
|
|
\ }
|
|
endfunction
|