Files
lucisv/editors/nvim/README.md
T
lucioandClaude Fable 5 80b9afdfe3 LSP §9b: willSaveWaitUntil — protocol-native format-on-save
textDocument/willSaveWaitUntil is advertised and served, gated on a new
lucisv.formatOnSave setting that defaults to off (a server that formats
uninvited fights the editor's own format-on-save and doubles up); the
decline is one comparison, before any buffer lookup. When on, the hook
is textDocument/formatting with a different trigger: the same engine,
the same all-or-nothing verified-output contract, settings resolved by
the new format::settings_without_editor_options — the ladder minus the
tabSize rung the protocol simply does not carry here, with the honest
consequence (save-format can differ from manual format without a
lucisv.toml) documented in the README, the VS Code setting description
and the nvim README. Every save reason formats; refusals are shown per
save, on purpose.

18 tests added across settings/format/server/e2e, including QA's
executable proofs of the tab-size gap and its lucisv.toml resolution, a
no-reindex/no-generation-bump guard for the new setting, and an
idempotency round-trip through a real didChange. QA also fixed the
stale 'not advertised' feature list in editors/nvim/README.md and
sharpened the config-warning dedup claim to what the code does (once
per buffer state) — reworded in the README, pinned by test.

docs/features/will-save-wait-until/README.md

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-26 12:21:00 -07:00

179 lines
6.4 KiB
Markdown

# lucisv for Vim / Neovim
There is no plugin here, on purpose: `lucisv-server` speaks plain LSP over stdio,
and every editor in this family already ships a client. What follows is
configuration, not code.
Build the server first and put it on your `PATH`:
```bash
cargo build --release # from the repo root
cp target/release/lucisv-server ~/.local/bin/
```
## Neovim 0.11+ (built-in `vim.lsp.config`, no plugins)
Neovim 0.11 has a native LSP configuration API — `nvim-lspconfig` is no longer
needed for a server this simple.
```lua
-- ~/.config/nvim/init.lua
vim.filetype.add({ extension = { v = 'verilog', vh = 'verilog', sv = 'systemverilog', svh = 'systemverilog' } })
vim.lsp.config('lucisv', {
cmd = { 'lucisv-server' },
filetypes = { 'verilog', 'systemverilog' },
root_markers = { 'lucisv.toml', '.lucisv.toml', '.git' },
})
vim.lsp.enable('lucisv')
```
Use an absolute path in `cmd` (`{ '/path/to/target/release/lucisv-server' }`) if
you would rather not install the binary.
**The `vim.filetype.add` line is not boilerplate.** In the stock runtime
(checked against vim 9.1's `filetype.vim`, which Neovim's tables descend from)
`*.sv` and `*.svh` map to `systemverilog` outright, but `*.v` goes through a
*content heuristic* — `dist#ft#FTv()` chooses between Verilog, Coq and V by
sniffing the first lines — and `*.vh` is not mapped at all. Without the line, a
short or unusual `.v` file can land on the wrong filetype and a `.vh` header
never attaches the server. Drop the `v =` entry if you also write Coq or V.
## Neovim 0.9 / 0.10 (`nvim-lspconfig`)
`lucisv` is not in `nvim-lspconfig`'s registry, so register the config yourself:
```lua
local configs = require('lspconfig.configs')
local util = require('lspconfig.util')
if not configs.lucisv then
configs.lucisv = {
default_config = {
cmd = { 'lucisv-server' },
filetypes = { 'verilog', 'systemverilog' },
root_dir = util.root_pattern('lucisv.toml', '.lucisv.toml', '.git'),
single_file_support = true,
},
}
end
require('lspconfig').lucisv.setup({})
```
`single_file_support = true` matters: the server works with no workspace root
at all (`initialize` with neither `workspaceFolders` nor `rootUri` succeeds),
serving everything single-file. Only cross-file navigation needs a root.
## Vim 9 (`vim-lsp`)
One `autocmd`, in `~/.vimrc`:
```vim
au User lsp_setup call lsp#register_server({'name': 'lucisv', 'cmd': {server_info->['lucisv-server']}, 'allowlist': ['verilog', 'systemverilog']})
```
## coc.nvim
coc has no `vim.lsp`; it takes servers from `coc-settings.json` (`:CocConfig`):
```jsonc
{
"languageserver": {
"lucisv": {
"command": "lucisv-server",
"filetypes": ["verilog", "systemverilog"],
"rootPatterns": ["lucisv.toml", ".lucisv.toml", ".git"]
}
}
}
```
## What you get, and what you don't
Everything in `docs/features/lucisv-server/README.md`'s capability table:
`gd` (definition), `gr` (references, in-file only for now), `K` (hover,
including `` `define`` expansion), `vim.lsp.buf.format()`, document and
workspace symbols, diagnostics as you type, and semantic tokens — Neovim
applies those on top of its treesitter/syntax highlighting with no extra setup.
Range formatting, completion, rename and signature help are advertised too —
Neovim's built-in client wires all four up with no extra config, same as
everything above.
**Inline completion (ghost text) needs a client that speaks it.** The server
advertises `inlineCompletionProvider` — grey `) begin … end` after an `if (`,
a matching `end` after a `begin` — but that is `textDocument/inlineCompletion`,
still proposed in LSP 3.18, and Neovim's built-in LSP client does not implement
it yet. Nothing is lost: the same skeletons are in the completion list, where
they have been since `docs/features/completion-templates`. Turn the server side
off with `lucisv.inlineTemplates = false` in your `settings` table if you would
rather it never answered.
Two behaviors worth knowing before you file a bug:
- **The workspace index rebuilds on save, not on keystroke.** Cross-file
answers about file A reflect A as of its last write. A's own buffer is always
current. This is the documented staleness model, not a lag.
- **`lucisv.toml` is honored.** The server discovers it per file exactly as
the CLI does; a config setting beats your `shiftwidth`/`tabstop` (an
editor default is not a deliberate override), and without a config your
editor's tab size governs the indent.
Format on save, if you want it — one `autocmd`, and your client stays in
charge of when it runs:
```lua
vim.api.nvim_create_autocmd('BufWritePre', {
pattern = { '*.v', '*.vh', '*.sv', '*.svh' },
callback = function() vim.lsp.buf.format() end,
})
```
Or let the server do it, for a client that speaks
`textDocument/willSaveWaitUntil` — it asks before every write and applies what
comes back:
```lua
vim.lsp.config('lucisv', {
cmd = { 'lucisv-server' },
filetypes = { 'verilog', 'systemverilog' },
root_markers = { 'lucisv.toml', '.lucisv.toml', '.git' },
settings = { lucisv = { formatOnSave = true } },
})
```
Pick one, not both. `lucisv.formatOnSave` is **off** unless you set it: the
server answers the save hook with "no edits" until you ask, so an editor that
already formats on save does not format twice. One difference from the
`autocmd` above is worth knowing: `willSaveWaitUntil` carries no tab settings,
so the indent comes from the project's `lucisv.toml`, then `lucisv.indent`,
then the built-in 2 — your `shiftwidth` is not consulted on this path even
though `vim.lsp.buf.format()` sends it. Set `lucisv.indent` if the two need to
agree.
## Checking it works
```
:checkhealth vim.lsp " Neovim 0.11+; 0.9/0.10: :checkhealth lsp
:LspInfo " nvim-lspconfig only
:lua =vim.lsp.get_clients({ bufnr = 0 })[1].server_capabilities
```
A healthy attach shows one client named `lucisv` with
`documentFormattingProvider`, `hoverProvider`, `definitionProvider`,
`referencesProvider`, `documentSymbolProvider`, `workspaceSymbolProvider` and
`semanticTokensProvider` set, and `positionEncoding` `utf-16`.
If the client never attaches, the binary is the first thing to check, and you
can check it without Neovim at all:
```bash
node ../vscode/smoke.js "$(command -v lucisv-server)"
```
That drives a full LSP session over stdio and exits 0 only if the handshake and
the capabilities are intact — which separates "the server is broken" from "my
editor config is wrong" in one command.