LSP §9a: applyEdit compliance, pull diagnostics, expand selection; v0.8.0
release / build-and-publish (push) Successful in 3m29s
release / build-and-publish (push) Successful in 3m29s
The three top findings of the LSP 3.18 audit (TODO.md §9), one round of dev (Opus) + QA (Sonnet) + lead review: - executeCommand now pushes its WorkspaceEdit as workspace/applyEdit and reads the client's verdict; the old return-the-edit behavior stays as the documented fallback for clients without the capability. This fixes the three port commands doing nothing in stock clients — the returned edit was dropped by vscode-languageclient and Neovim alike. docs/features/apply-edit/README.md - textDocument/diagnostic + workspace/diagnostic (LSP 3.17), served from the same parse+lint pass the push model publishes, with resultId / unchanged caching on one generation counter; a pulling client is pushed nothing, a pushing client is unchanged. QA's exhaustive input trace found no stale-unchanged path. docs/features/pull-diagnostics/README.md - textDocument/selectionRange: chains from token spans, the tolerant parse's item/statement spans and the scope-pair matcher, filtered to strict nesting; the invariant swept over all 860 corpus files (6,880 positions, held everywhere). docs/features/selection-range/README.md 43 tests added across unit/e2e (server 557 -> 594+ unit, 29 -> 32 e2e); fmt/clippy/test/smoke all clean, re-verified independently by QA and by the lead. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
d3081d6aaf
commit
aa303ce9ae
14 files changed
+2378
-54
No files matched your search
@@ -0,0 +1,288 @@
|
||||
# pull-diagnostics
|
||||
|
||||
## Goal
|
||||
|
||||
Serve diagnostics the modern way (LSP 3.17): the client asks
|
||||
`textDocument/diagnostic` for the buffer it is showing and
|
||||
`workspace/diagnostic` for the rest, when *it* decides — so the visible editor
|
||||
is prioritised, nothing is computed for a buffer nobody is looking at, and the
|
||||
client caches by `resultId` instead of re-drawing everything on every
|
||||
keystroke. lucisv had only the push model (`textDocument/publishDiagnostics`
|
||||
on every change). This round adds the pull model beside it, off the same
|
||||
parse+lint pass, and makes sure **one client is never served both** — two sets
|
||||
of squiggles for one file is the classic way to ship this feature wrong.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **The capability is the switch.** A client that sent
|
||||
`textDocument.diagnostic` at initialize is a pulling client and is pushed
|
||||
*nothing at all*, ever. A client that did not keeps today's push behavior
|
||||
byte for byte. There is no setting: the protocol already asks the question.
|
||||
- **The `didClose` clear is not pushed to a pulling client either.** In the
|
||||
push model an empty publish is how a server erases what it drew, and that
|
||||
stays. In the pull model the client owns the whole lifecycle of what it
|
||||
pulled — it decides when to ask and drops a closed document's diagnostics
|
||||
itself (`vscode-languageclient`'s diagnostic feature does exactly this) —
|
||||
so a publish arriving at close would be the server's only push of the
|
||||
session and would land in a channel the client is not reading for this
|
||||
document. The gate therefore sits in `send_diagnostics`, which both callers
|
||||
go through: one place, no way to leak a push.
|
||||
- **`resultId` is a single generation counter, and nothing else.** It is
|
||||
bumped in `set_document` (a buffer's text changed) and in `reindex` (the
|
||||
workspace index changed). A pull whose `previousResultId` equals the
|
||||
current generation is answered `unchanged`; anything else is a full report.
|
||||
This is deliberately **coarser** than per-buffer versioning: editing file A
|
||||
invalidates the client's cached stamp for file B, which costs one extra
|
||||
full report — a cheap, correct answer. The error the coarse direction
|
||||
cannot make is the expensive one: a stale `unchanged` is a wrong squiggle
|
||||
left on screen. (The brief suggested `generation/doc-version`; the server
|
||||
does not track document versions at all — full-text sync ignores them — so
|
||||
the second half would have been a constant. One number, documented, beats a
|
||||
format that implies a precision that is not there.)
|
||||
- **`inter_file_dependencies: true` is honest.** A save rebuilds the
|
||||
workspace index, and a buffer's diagnostics are computed against that index
|
||||
(`resolve_external` in `state.rs`), so a save in file A really can change
|
||||
what file B reports. That is exactly why `reindex` bumps the generation.
|
||||
- **`workspace/diagnostic` reports the open buffers only.** This server has
|
||||
never diagnosed a file it was not shown: `publish` is per open buffer, and
|
||||
`reindex` republishes only open buffers. Linting the whole workspace on a
|
||||
pull would be a parse of every in-scope file per request, on a request a
|
||||
client may send after every keystroke. So the workspace report is the open
|
||||
buffers, in URI order. **This is the honest limit of the feature**: a
|
||||
client using workspace diagnostics as its only source sees findings for
|
||||
files it has open, not for the project. Widening it is its own round, with
|
||||
its own cost model (and probably `workDoneProgress`, TODO §9b).
|
||||
- **No partial results, no streaming, and no
|
||||
`workspace/diagnostic/refresh`.** Partial results are not advertised, so no
|
||||
client will ask for them. A refresh request would let the server tell a
|
||||
pulling client "ask again, the index moved"; it is not sent, so such a
|
||||
client sees post-save changes at its own next pull. Stated because it is
|
||||
the one place the pull model is *lazier* than the push model this replaces.
|
||||
- **Both models answer from one function.** `Server::diagnostics_of` is the
|
||||
single computation (`diagnostics::all`, i.e. parse errors, then the
|
||||
missing-closer warnings, then lint), and `publish` and both pull handlers
|
||||
all call it. A second conversion path would be a second set of off-by-one
|
||||
bugs; pinned by `both_models_say_exactly_the_same_thing_about_a_buffer`.
|
||||
- **A pull for a buffer that is not open is an empty full report**, not an
|
||||
error: the client asked about a document this server knows nothing about,
|
||||
and "no findings" is the true answer.
|
||||
|
||||
## Handshakes
|
||||
|
||||
### `lucisv_server::main`
|
||||
|
||||
- `capabilities()` gains `diagnostic_provider: DiagnosticServerCapabilities::Options`
|
||||
with `identifier: "lucisv"` (the same string every diagnostic's `source`
|
||||
carries — one constant, `diagnostics::SOURCE`), `inter_file_dependencies:
|
||||
true`, `workspace_diagnostics: true`.
|
||||
- `pull_diagnostics_support(&InitializeParams)` reads
|
||||
`text_document.diagnostic`; its two fields (dynamic registration, related
|
||||
documents) are about things this server does not do, so the presence of the
|
||||
capability is the whole of the statement.
|
||||
|
||||
### `lucisv_server::server`
|
||||
|
||||
- `ClientAbilities` gains `pull_diagnostics: bool`.
|
||||
- `Server` gains `generation: u64`, bumped in `set_document` and `reindex`.
|
||||
- New handlers: `DocumentDiagnosticRequest`, `WorkspaceDiagnosticRequest`.
|
||||
- `send_diagnostics` is now the single gate on pushing anything.
|
||||
- `diagnostics_of(uri)` is the one computation both models read.
|
||||
|
||||
### `diagnostics`
|
||||
|
||||
Unchanged. `diagnostics::all` and `diagnostics::SOURCE` are consumed as they
|
||||
already were; nothing was added to that module.
|
||||
|
||||
### `editors/*`
|
||||
|
||||
No change. `vscode-languageclient` 9.x advertises the diagnostic capability
|
||||
and drives the pull itself, so the VS Code extension switches models with no
|
||||
edit — and `editors/vscode/smoke.js` sends `capabilities: {}`, so it stays on
|
||||
the push model and keeps asserting what it always asserted.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] `DiagnosticOptions` advertised, identifier pinned to the publish source
|
||||
- [x] `textDocument/diagnostic`: full report with a `resultId`, `unchanged`
|
||||
when the generation stands
|
||||
- [x] `workspace/diagnostic`: open buffers in URI order, `previousResultIds`
|
||||
honoured per file
|
||||
- [x] Push suppressed for a pulling client — including the `didClose` clear
|
||||
- [x] One computation behind both models
|
||||
- [x] Tests: never-pushed, push-client-unchanged, full-then-unchanged-then-
|
||||
full, reindex moves the stamp, unopened buffer, workspace report and
|
||||
its stamps, both models identical
|
||||
- [ ] Not done, deliberately: workspace diagnostics do not cover unopened
|
||||
workspace files — see Assumptions.
|
||||
- [ ] Not done, deliberately: no `workspace/diagnostic/refresh`, no partial
|
||||
results, no `relatedDocuments`.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-08-26 — dev agent, §9a
|
||||
|
||||
- **The gate went into `send_diagnostics`, not into `publish`.** Both the
|
||||
change-driven publish and the `didClose` clear go through it, so one `if`
|
||||
covers every push the server can make. Putting it in `publish` would have
|
||||
left the close path pushing to a pulling client.
|
||||
- **One generation counter** instead of the suggested
|
||||
`generation/doc-version` pair: the server does not track document versions
|
||||
(`DidChangeTextDocumentParams.version` is ignored under full-text sync), so
|
||||
the second component would always have been the same string. Recorded in
|
||||
Assumptions as a deliberate deviation from the brief, with the failure mode
|
||||
it cannot have.
|
||||
- **URI order in the workspace report** because `open_uris()` comes off a
|
||||
`HashMap` and would otherwise shuffle between two pulls of identical state,
|
||||
which reads as churn to a human and makes a test flaky.
|
||||
- **`version: None`** on the workspace reports: the protocol wants the
|
||||
document version the diagnostics were computed for, and this server has
|
||||
none to give.
|
||||
- Files touched: `crates/lucisv_server/src/server.rs`,
|
||||
`crates/lucisv_server/src/main.rs`, `crates/lucisv_server/tests/e2e.rs`, and
|
||||
the capability table in `docs/features/lucisv-server/README.md` (the
|
||||
`publishDiagnostics` row is now conditional). Nothing in `diagnostics.rs`,
|
||||
`lint.rs` or any engine crate.
|
||||
|
||||
**Verification.** `cargo fmt`, `cargo clippy --all-targets` (zero warnings),
|
||||
`cargo test --workspace`, `node editors/vscode/smoke.js` (still on the push
|
||||
model, unchanged) — all clean. 8 new unit tests in `server.rs`, 2 in `main.rs`
|
||||
(the options, and the capability probe), and one e2e session
|
||||
(`a_pulling_client_is_answered_and_never_pushed_over_the_wire`) whose central
|
||||
assertion is that the *next thing the server says* after a pull request is the
|
||||
answer and not a push.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-08-26 — QA agent, §9a
|
||||
|
||||
**Re-ran the dev's verification, clean.** `cargo fmt --all -- --check`,
|
||||
`cargo clippy --all-targets --workspace` (zero warnings, rebuilt from a
|
||||
touched source tree so this wasn't answered from cache), `cargo test
|
||||
--workspace` (3 full runs, no failures), `node editors/vscode/smoke.js
|
||||
target/debug/lucisv-server` (exit 0, still on the push model as claimed).
|
||||
|
||||
**The stale-`unchanged` hunt — this was the main assignment.** Traced every
|
||||
input `Server::diagnostics_of` reads (`diagnostics::all`: parse errors +
|
||||
`pairs::missing_end_diagnostics` + `lint::diagnostics`, all three reading only
|
||||
`doc.text`/`doc.tokens`/`doc.tree`/`doc.line_index`/`doc.semantics` —
|
||||
confirmed by reading `diagnostics.rs`, `lint.rs`'s `context()`, and
|
||||
`vlog_linter::registry::default_rules()`) against every event that can reach
|
||||
the server without going through `set_document` (which bumps `generation`)
|
||||
or `reindex` (same):
|
||||
|
||||
- `DidChangeConfiguration` (`server.rs`'s `notification` handler): the
|
||||
settings it can change are `line_length`, `indent`, `exclude`, `filelist`,
|
||||
`inline_templates` (`settings.rs`). Checked each against what
|
||||
`diagnostics_of` actually reads: `line_length`/`indent` only ever reach
|
||||
`format.rs` (the formatting request), never the lint or parse-error path;
|
||||
`inline_templates` is ghost-text only, read nowhere near diagnostics.
|
||||
`exclude`/`filelist` *do* trigger `self.reindex()` when
|
||||
`set_client_settings` reports a real change — which bumps `generation`
|
||||
anyway, so even though this pair does not currently touch a single open
|
||||
buffer's own diagnostics, the code already treats it as invalidating.
|
||||
**No live bug**, but see the finding below.
|
||||
- `lucisv.toml` picked up via file watchers (`DidChangeWatchedFiles`,
|
||||
`watch::touches_scope`): any matched source file always routes to
|
||||
`self.reindex()`, unconditionally bumping `generation` — including for a
|
||||
file nobody has open. Coarser than necessary (an edit to an unrelated file
|
||||
invalidates every open buffer's stamp) but never stale-in-the-dangerous-
|
||||
direction.
|
||||
- `reindex` paths generally (save, watched-file change, exclude/filelist
|
||||
change, `didOpen` with no workspace root): all funnel through the one
|
||||
`reindex()` method, which increments `generation` unconditionally before
|
||||
doing anything else — verified by reading the method body, not just the
|
||||
call sites.
|
||||
- **`doc.external`** (`resolve_external`, the thing the README's own
|
||||
Assumptions section cites as *why* `inter_file_dependencies: true` is
|
||||
honest) is read only by `hover.rs` and `nav.rs` — grepped every non-test
|
||||
use. **Diagnostics never read it.** So today, no lint rule or parse error
|
||||
actually depends on the workspace index at all; the README's justification
|
||||
for `inter_file_dependencies` describes a coupling that does not yet exist
|
||||
in the diagnostics path (it exists for hover/definition). This is not
|
||||
presently a correctness bug — bumping `generation` on `reindex` is the
|
||||
*safe* direction regardless of whether anything currently needs it — but
|
||||
the README's Assumptions text over-claims the *reason*. **Finding
|
||||
(informational, not a defect):** the real invariant this feature depends on
|
||||
is "every diagnostic-affecting input bumps `generation`," which today is
|
||||
satisfied only because diagnostics happen to have no configurable/workspace-
|
||||
dependent input at all. `lint.rs`'s own doc comment says as much
|
||||
("Selection (`--select`/`--ignore`) has no `lucisv.toml` key yet"). The
|
||||
day a lint rule becomes configurable or cross-file-aware, whoever adds it
|
||||
must also audit whether it needs to bump `generation` — nothing today
|
||||
enforces that, and this feature's tests cannot catch a violation of an
|
||||
invariant about code that doesn't exist yet. Flagged for the lead/dev to
|
||||
decide whether to soften the Assumptions wording; not fixed directly since
|
||||
it is a wording call, not a code defect.
|
||||
- Conclusion: **no reproducible stale-`unchanged` sequence exists against
|
||||
the current codebase.** I looked for one (attempted repro via a
|
||||
`lineLength` push mid-session expecting it to be invisible to a pull
|
||||
client — it is, but it is also invisible to a *push* client for the same
|
||||
reason: line length never touched diagnostics before this feature either)
|
||||
and could not construct one.
|
||||
|
||||
**Push/pull exclusivity, verified structurally, not just by test.** Grepped
|
||||
`server.rs` for every call site of `send_diagnostics` (the only place
|
||||
`PublishDiagnosticsParams` is constructed): exactly two — `publish()` (open/
|
||||
change/reindex) and the `didClose` clear. Both funnel through
|
||||
`send_diagnostics`, which is the single `if self.abilities.pull_diagnostics
|
||||
{ return; }` gate. There is no third path that could bypass it. Existing
|
||||
test `a_pulling_client_is_never_pushed_diagnostics` already exercises
|
||||
didOpen/didChange/didSave/didClose; added no new test here since the
|
||||
structural argument (one gate, two call sites, both covered) is stronger
|
||||
than another sequence test would be.
|
||||
|
||||
**`workspace/diagnostic` edge cases — added three tests** in `server.rs`,
|
||||
all passing:
|
||||
|
||||
- `an_empty_workspace_answers_a_well_formed_empty_report` — no open buffers
|
||||
at all: `items` is `[]`, not an error, not a missing field.
|
||||
- `a_previous_result_id_for_a_uri_that_is_since_closed_is_harmless` — a
|
||||
`previousResultIds` entry for a URI the client closed after its last pull:
|
||||
the closed URI is simply absent from the answer (it is not among
|
||||
`open_uris()`), never phantom-reported, never an error.
|
||||
- `a_previous_result_id_for_a_uri_never_seen_is_ignored` — a
|
||||
`previousResultIds` entry for a URI this server never opened: ignored,
|
||||
does not disturb the report for URIs that *are* open.
|
||||
|
||||
**`applyEdit`-adjacent note:** `diagnostics_of`'s early-return
|
||||
(`self.workspace.document(uri).map(...).unwrap_or_default()`) means a pull
|
||||
for an unopened buffer is `Full` with empty `items` rather than `Unchanged`
|
||||
— checked this always answers `Full` regardless of what `previousResultId`
|
||||
the client sends for an unopened URI, which is correct (an unopened buffer's
|
||||
"generation" was never established for that client, so there is nothing to
|
||||
consider unchanged).
|
||||
|
||||
**CLAUDE.md compliance:** no `unwrap()`/`expect()`/`panic!` in the new
|
||||
non-test code in `server.rs`/`main.rs`; `ClientAbilities::pull_diagnostics`
|
||||
and `Server::generation`/`applying` (shared with apply-edit) carry doc
|
||||
comments; `DiagnosticServerCapabilities` construction and
|
||||
`pull_diagnostics_support` read capabilities defensively
|
||||
(`.as_ref()`/`.is_some_and()`), confirmed no panic on
|
||||
`InitializeParams::default()` by the existing test. README has all seven
|
||||
sections; TODO.md checkbox is checked with item text unchanged.
|
||||
|
||||
**Verdict: no blocking findings.** One informational finding recorded above
|
||||
(Assumptions text describes a coupling that isn't live code yet — cosmetic,
|
||||
not a defect) for the lead to weigh in on. Three new edge-case tests added,
|
||||
all passing; the exhaustive input trace found no stale-`unchanged` path.
|
||||
|
||||
## Review
|
||||
|
||||
### 2026-08-26 — lead
|
||||
|
||||
Reviewed the diff, the work log and the QA log; re-ran all gates myself,
|
||||
clean. One computation (`diagnostics_of`) behind both models, one push gate
|
||||
(`send_diagnostics`), one generation counter as the whole `resultId` — the
|
||||
boring shape CLAUDE.md asks for, and QA's exhaustive input trace confirms
|
||||
the coarse counter cannot produce a stale `unchanged` today.
|
||||
|
||||
On QA's informational finding (the Assumptions justify
|
||||
`inter_file_dependencies: true` via the index, which the diagnostics path
|
||||
does not read yet): accepted as written. Bumping on reindex is the safe
|
||||
direction and the semantic-lint roadmap (§9's future rounds, cross-file
|
||||
rules) is precisely what will make the index a real input; the README
|
||||
already states the true invariant — *every diagnostic-affecting input bumps
|
||||
`generation`* — and whoever adds a lint config key or a cross-file rule
|
||||
inherits it. The `both_models_say_exactly_the_same_thing_about_a_buffer`
|
||||
test is the right tripwire for divergence. No change requested. Accepted
|
||||
as shipped.
|
||||
Reference in new issue
Block a user