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]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-08-26 12:21:00 -07:00
1 parent c2ea1a11f6
commit 80b9afdfe3
11 files changed
+939 -11

No files matched your search

+27 -3
View File
@@ -98,8 +98,9 @@ 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.
Not advertised by the server, so your client will correctly refuse them: range
formatting, completion, rename, signature help, and cross-file references.
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 (`,
@@ -120,7 +121,8 @@ Two behaviors worth knowing before you file a bug:
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:
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', {
@@ -129,6 +131,28 @@ vim.api.nvim_create_autocmd('BufWritePre', {
})
```
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
```
+5
View File
@@ -168,6 +168,11 @@
"default": true,
"markdownDescription": "Show grey ghost text that finishes a block as you open it: `if (` suggests `) begin … end`, a `case (` suggests its arms and `endcase`, and a `begin`, `fork`, `generate` or `module` at the end of a line suggests its closer. Tab accepts it as a snippet, so the cursor lands in the condition first and in the body second; where more than one shape fits (`always @(`), `Alt+]` cycles them. The accepted text is indented with the editor's own `editor.tabSize`/`editor.insertSpaces`, not with `#lucisv.indent#`. Requires `editor.inlineSuggest.enabled`."
},
"lucisv.formatOnSave": {
"type": "boolean",
"default": false,
"markdownDescription": "Let the server format the file when you save it, over `textDocument/willSaveWaitUntil`. Off by default, and **not** what a VS Code user wants: `#editor.formatOnSave#` already formats through lucisv and turning both on formats twice. This exists for the editors that have no format-on-save of their own. The indent comes from the project's `lucisv.toml`, then `#lucisv.indent#`, then the built-in 2 — never from `#editor.tabSize#`, which the protocol does not send with this request."
},
"lucisv.lineLength": {
"type": [
"number",