Files
gffranco 4bee216c05
CI / editor tests (push) Successful in 45s
refactor(client): self-review cleanup — dead code, dedup, parity, stale comments
A code-review pass over the VimL + Lua client layers (no behaviour change
beyond the noted parity fixes; full editor harness 10/10):

Lua (lua/nuwiki/):
- commands.lua: drop the dead <0.10 make_position_params pcall/no-arg fallback
  (min is 0.11; no-arg form is itself deprecated) and its stale comment.
- commands.lua: simplify the exec() client dispatch — the metatable/rawget
  dance is gone; always use the non-deprecated colon form client:request() on
  0.11+. (This is the block an external review misread as "critical".)
- commands.lua: extract parse_list_marker() + has_auto_indent() shared by
  smart_return/smart_shift_return; extract word_boundaries() shared by
  wrap_cword_as_wikilink/colorize (and unify the equivalent char classes).
- commands.lua: :Nuwiki search now surfaces real lvimgrep errors instead of
  reporting every failure as "no match" (E480 stays a WARN) — parity with the
  VimL twin's `catch /E480/`.
- keymaps.lua: collapse open_below/above_with_bullet into open_with_bullet(cmd)
  (checkbox prefix preserved for `o` only, as before).
- lsp.lua: normalize the wiki root before the buffer-path prefix compare
  (Windows separators); buf path was already normalized.
- ftplugin.lua: drop the always-true has('nvim-0.11') guard and hoist the
  identical foldmethod/foldtext out of both branches.
- install.lua: use a local `uv` instead of mutating the global vim.uv.

VimL (autoload/nuwiki/):
- commands.vim: refresh a stale comment pointing at the old in-repo
  nuwiki-lsp/src/commands.rs path → the nuwiki-rs server generally.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 13:59:52 +00:00

109 lines
3.5 KiB
Lua

-- lua/nuwiki/lsp.lua — registration of the nuwiki LSP server in Neovim.
--
-- Prefers Neovim 0.11+'s declarative `vim.lsp.config{}` + `vim.lsp.enable`.
-- Falls back to a FileType autocmd that calls `vim.lsp.start` for older
-- versions (we still officially support only 0.11+; the fallback exists so
-- the plugin degrades gracefully rather than erroring out).
local M = {}
local config = require('nuwiki.config')
local install = require('nuwiki.install')
local function command()
return { install.expected_path() }
end
-- Build the server config payload. The wiki list comes from the shared
-- resolver (config.wikis) — native setup() wikis, g:nuwiki_wikis, or an
-- upstream g:vimwiki_list, with global scalar defaults already folded — so the
-- payload and the buffer-side commands agree on which wikis exist.
local function resolved_opts()
local opts = config.options
local wikis = config.wikis()
if #wikis > 0 then
opts = vim.tbl_extend('force', opts, { wikis = wikis })
else
-- Single-wiki shorthand: fold the global scalars into the top-level payload
-- so the server's single-wiki desugaring honours them.
local globals = config.scalar_globals()
if not vim.tbl_isempty(globals) then
opts = vim.tbl_extend('keep', opts, globals)
end
end
return opts
end
--- `initializationOptions` payload: the server reads it once at
--- `initialize` time via `Config::from_init_params`. This is what
--- delivers `wiki_root`/`wikis`/HTML/diary config to Rust.
--- Public so the config parity harness can inspect the exact payload.
function M.init_options()
return resolved_opts()
end
--- `settings` payload: the same shape, but sent via
--- `workspace/didChangeConfiguration` after startup. Lets the server
--- pick up config changes without a restart.
--- Public so the config parity harness can inspect the exact payload.
function M.server_settings()
return { nuwiki = resolved_opts() }
end
local function root_dir_for(buf_file)
-- Walk up from the buffer until we hit a workspace marker.
local found = vim.fs.find(
{ '.git', '.nuwiki' },
{ upward = true, path = vim.fs.dirname(buf_file) }
)[1]
if found then
return vim.fs.dirname(found)
end
-- For multi-wiki setups, find the wiki whose root contains buf_file.
local opts = resolved_opts()
if opts.wikis then
local buf_norm = vim.fs.normalize(buf_file)
for _, w in ipairs(opts.wikis) do
-- Normalize both sides so the prefix compare survives mixed path
-- separators (e.g. on Windows); buf_norm is already normalized.
local root = vim.fs.normalize(vim.fn.expand(w.root or ''))
if root ~= '' and buf_norm:sub(1, #root) == root then
return root
end
end
end
return vim.fn.expand(opts.wiki_root or '~/vimwiki')
end
function M.register()
if vim.lsp.config and vim.lsp.enable then
-- Neovim 0.11+: declarative server registration.
vim.lsp.config('nuwiki', {
cmd = command(),
filetypes = { 'vimwiki' },
root_markers = { '.git', '.nuwiki' },
init_options = M.init_options(),
settings = M.server_settings(),
})
vim.lsp.enable('nuwiki')
return
end
-- Pre-0.11 fallback path.
vim.api.nvim_create_autocmd('FileType', {
pattern = 'vimwiki',
desc = 'start nuwiki language server',
callback = function(ev)
vim.lsp.start({
name = 'nuwiki',
cmd = command(),
root_dir = root_dir_for(ev.file),
init_options = M.init_options(),
settings = M.server_settings(),
})
end,
})
end
return M