LSP §9c: didChangeWorkspaceFolders + server-pull configuration
Folders: workspace.workspaceFolders advertised with change notifications; added/removed folders adjust the root set through one 8-line Workspace::change_roots (removals first, dedup, did-it-move bool) and one reindex per moving notification — progress bar, code- lens refresh and diagnostics generation all ride along, pinned. Open buffers in a removed folder keep today's rootless conventions with no new code. The source watcher's base-less glob needs no re- registration; the absolute-path filelist watcher re-registers through the same before/after comparison the settings push already ran. Configuration: clients advertising workspace.configuration get one pull at startup and one per empty didChangeConfiguration; the answer funnels through the same parser and applier as the push, so the two doors cannot drift, and every malformed answer shape lands on defaults, silently. The outstanding-request routing refactored to one Pending enum map — applyEdit's shipped behavior re-proven under three-way out-of-order interleaving. Push-with-payload stays the unchanged legacy path. 38 tests added (dev 27 + QA 11, closing every claim that lacked one: roots.first() reordering, last-root-removed totality, double pulls, stale answers, the pull-answer-moves-the-filelist chain, rootless- gains-first-folder). QA's F1 — a subfolder added as its own root is its own root, outside the parent's exclude — accepted as the per-root model and documented in Assumptions. docs/features/folders-and-config/README.md Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
8dc8f6489f
commit
17fb2129db
9 files changed
+2097
-52
No files matched your search
@@ -51,6 +51,17 @@ per notification.
|
||||
current scope: the scope ladder re-applies during the rebuild anyway, and
|
||||
one rebuild for a stray in-tree `.sv` is much cheaper than duplicating the
|
||||
ladder's logic per event and getting it subtly wrong.
|
||||
- **A workspace-folder change does not need a new registration for the source
|
||||
glob** (added 2026-08-27 by folders-and-config). `SOURCE_GLOB` is a
|
||||
base-less *string* pattern, which the client matches against the workspace
|
||||
it currently holds, so a folder added mid-session is covered by the
|
||||
registration already in force; the `RelativePattern` form, which anchors a
|
||||
glob to one folder's URI and would have to be re-sent per folder, is
|
||||
deliberately not used. The **filelist** watcher is the exception: it is an
|
||||
absolute path, and a relative `lucisv.filelist` is resolved against the
|
||||
*first* root — so `server.rs` re-registers on a folder change whose
|
||||
`filelist_path()` differs, exactly as it already did for a changed setting.
|
||||
See `docs/features/folders-and-config/README.md`.
|
||||
- **Only the root filelist is watched, not its nested `-f` targets.**
|
||||
`lucisv_core::filelist::Filelist` reports the files a filelist names but not
|
||||
the filelists it *read*, and adding that field is a change to another
|
||||
|
||||
@@ -0,0 +1,568 @@
|
||||
# folders-and-config
|
||||
|
||||
Two small §9c items, one round, because they are the same shape: both are a
|
||||
piece of the session's *setup* that the server used to read exactly once and
|
||||
never again.
|
||||
|
||||
## Goal
|
||||
|
||||
**`workspace/didChangeWorkspaceFolders`.** Until this round the workspace
|
||||
roots were read at `initialize` and frozen for the life of the process, so
|
||||
"Add Folder to Workspace" (or closing one) changed nothing until the editor
|
||||
was restarted — a multi-repo SV project, which is the normal shape for a
|
||||
design plus its verification IP, could not be assembled without a reload. The
|
||||
server now advertises `workspace.workspaceFolders` (both halves) and adjusts
|
||||
its root set from the notification, rebuilding the index once per event.
|
||||
|
||||
**`workspace/configuration` (server-pull).** The `lucisv.*` settings only ever
|
||||
arrived by *push*, and the push is the legacy path: `vscode-languageclient`
|
||||
sends `didChangeConfiguration` with a real payload only where a
|
||||
`synchronize.configurationSection` is configured, and the modern arrangement
|
||||
is for the client to say "something changed" and for the server to fetch what
|
||||
it needs. The server now asks for the `lucisv` section at startup, and again
|
||||
on every empty `didChangeConfiguration`, gated on the client's own
|
||||
`workspace.configuration` capability. The answer goes through **the same
|
||||
parser** a push does, so the two paths cannot drift.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **A subdirectory added as its own workspace folder is its own root.** It
|
||||
resolves its own `lucisv.toml` from its own tree, so the parent root's
|
||||
`exclude` does not reach into it — files the parent excluded become
|
||||
indexable through the child root (QA log F1, 2026-08-27; no
|
||||
double-indexing, no ambiguity). This is the per-root config model applied
|
||||
consistently to a shape that could not previously occur; a user who adds a
|
||||
subfolder as a root is asking for exactly that folder.
|
||||
|
||||
|
||||
- **A workspace folder is a directory on disk.** A folder whose URI is not a
|
||||
`file:` URI is dropped rather than guessed at — `uri.rs`'s rule everywhere
|
||||
else, and there is nothing to walk for a `vscode-vfs://` folder anyway.
|
||||
- **The root set is a list, not a set with an identity.** Roots are compared
|
||||
by path. A client that re-adds a folder it already sent, or removes one it
|
||||
never sent, changes nothing and is told nothing: the notification has no
|
||||
reply, and re-scanning to discover that the answer is the same is pure
|
||||
cost. Removals are applied before additions, so a folder named in *both*
|
||||
lists of one event survives (some clients spell a moved folder that way).
|
||||
- **Removing a folder does not close its buffers.** The client owns buffer
|
||||
lifecycle; LSP has no "the server dropped your file" message. An open buffer
|
||||
whose folder was closed keeps exactly the deal every out-of-scope buffer has
|
||||
always had — it is analyzed, diagnosed, formatted, and it still overrides
|
||||
disk in the index by contributing itself (`Workspace::collect_sources` adds
|
||||
every open document with a path, whatever the scope ladder said). Removing
|
||||
the *last* folder is not a special case either: the session becomes the
|
||||
rootless one rung 3 of the scope ladder already describes, where the scope
|
||||
is the open buffers' own directories.
|
||||
- **One set of settings per session, not one per folder.** The pull sends no
|
||||
`scopeUri`. `ClientSettings` is a single struct read by `format::settings_for`
|
||||
and the index scope, with no notion of "these settings, for files under that
|
||||
folder" — asking per-resource would be asking for answers there is nowhere
|
||||
to put. A multi-folder workspace where two folders want different indents
|
||||
should say so in a `lucisv.toml` per folder, which already works and already
|
||||
beats the editor setting.
|
||||
- **A pull answer is never an error.** A refusal, a `null` entry, an empty
|
||||
array, an object where an array belongs — all mean the same thing, "no
|
||||
settings for you", which is the defaults. The user did not ask for this
|
||||
request and cannot act on its failure, so nothing here opens a popup.
|
||||
- **Settings can arrive after the first index build**, and this round does not
|
||||
change that. The pull is sent at the same moment the watchers are registered
|
||||
— the earliest legal point for a server-initiated request — and answered
|
||||
later, in the loop. That is exactly what a pushed `didChangeConfiguration`
|
||||
has always done too (it cannot arrive before `initialized` either): the
|
||||
first index is built against the default scope, and a pulled
|
||||
`lucisv.exclude`/`lucisv.filelist` costs one extra rescan when it lands.
|
||||
Nothing is *wrong* in between, it is simply the wider scope.
|
||||
|
||||
## The settings model, stated once
|
||||
|
||||
| what arrives | what the server does |
|
||||
|---|---|
|
||||
| `didChangeConfiguration` with a payload (any non-empty object) | applied directly, through `settings::from_payload` — the legacy path, unchanged |
|
||||
| `didChangeConfiguration` with `settings: null` or `{}`, **and** `workspace.configuration` | pulls `workspace/configuration` for the `lucisv` section; nothing is applied until the answer comes back |
|
||||
| `didChangeConfiguration` with `settings: null` or `{}`, **no** capability | applied directly, which resolves to "no opinion about anything" — exactly what such a client got before this round |
|
||||
| startup, with `workspace.configuration` | one pull, unprompted |
|
||||
| startup, without it | nothing; settings only ever arrive by push |
|
||||
|
||||
Whichever door they came in, settings are adopted by one function —
|
||||
`Server::apply_settings` — so `exclude`/`filelist` cost the same rescan and the
|
||||
same watcher re-registration on both paths, and no third path can be added
|
||||
without going through it.
|
||||
|
||||
## The watcher determination
|
||||
|
||||
**The source-glob registration does not need re-sending when folders change.**
|
||||
`watch::registration` sends a `FileSystemWatcher` whose `globPattern` is the
|
||||
plain string `**/*.{v,vh,sv,svh}`. In LSP a *string* glob pattern carries no
|
||||
base URI, and the client matches it against the workspace it holds — VS Code
|
||||
re-evaluates such a pattern against its current folder set, so a folder added
|
||||
after registration is watched by the registration already in force. (The
|
||||
alternative shape, `RelativePattern`, anchors a glob to one folder's URI and
|
||||
*would* have to be re-sent per folder; this server has never used it, and
|
||||
adopting it would mean one watcher per root for no gain.)
|
||||
|
||||
**The filelist watcher does.** The second watcher in the same registration is
|
||||
an absolute path, and `Workspace::filelist_path` resolves a *relative*
|
||||
`lucisv.filelist` against `roots.first()`. So a folder event that changes which
|
||||
root is first — or that removes the root the setting was anchored to — moves
|
||||
the watched path without anyone touching the setting. The handler therefore
|
||||
compares `filelist_path()` before and after and re-registers when it moved:
|
||||
literally the same two lines `didChangeConfiguration` already ran, for the
|
||||
same reason (the watched path is baked into the registration).
|
||||
|
||||
## Handshakes
|
||||
|
||||
**Consumed from `lsp-types` 0.97:** `WorkspaceFoldersServerCapabilities
|
||||
{ supported, change_notifications }` — `change_notifications` is
|
||||
`OneOf<bool, String>` and is sent as `Left(true)`; the string form exists so
|
||||
the registration can be undone by id, and this server never unregisters it.
|
||||
`DidChangeWorkspaceFoldersParams { event: { added, removed } }`,
|
||||
`ConfigurationParams`/`ConfigurationItem`, and `WorkspaceConfiguration`
|
||||
(`Result = Vec<Value>`).
|
||||
|
||||
**Asked of `state.rs` (delivered, minimal):** one new public method,
|
||||
|
||||
```rust
|
||||
pub fn change_roots(&mut self, added: Vec<PathBuf>, removed: &[PathBuf]) -> bool
|
||||
```
|
||||
|
||||
which adjusts the private `roots` list and reports whether it moved, in the
|
||||
same shape `set_client_settings` already reports "you owe a rebuild". Nothing
|
||||
else in `state.rs` changed: `rebuild_index` walks `self.roots` and so already
|
||||
does the right thing for a wider or narrower set, and the rootless fallback
|
||||
(`default_files` → `sibling_files`) already covers "the last folder went
|
||||
away". The root list is deliberately *not* exposed — the server has no use for
|
||||
it beyond changing it, and `has_roots()` already answers the one question it
|
||||
does ask.
|
||||
|
||||
**Promised to `server.rs`'s other handlers:** `Pending` replaces the
|
||||
`applying: HashMap<RequestId, String>` map. Every server-initiated request
|
||||
whose answer matters is registered in one `pending: HashMap<RequestId,
|
||||
Pending>`; everything else (watcher registration, `workDoneProgress/create`,
|
||||
`codeLens/refresh`, `showDocument`) is still absent from it and still falls
|
||||
through `response` untouched. A future request kind that needs its answer read
|
||||
adds a variant, and the compiler names every place that must handle it. Two
|
||||
maps would have meant two lookups in `response` and two chances to forget one.
|
||||
|
||||
**`settings.rs` gained** `SECTION` (the one spelling of `"lucisv"`, used by the
|
||||
parser and by the pull's `ConfigurationItem`), `from_section` (a pull answer,
|
||||
wrapped back into the push shape so there is exactly one parser) and
|
||||
`says_nothing` (whether a push payload is really a pull signal).
|
||||
|
||||
**Nothing outside `crates/lucisv_server` was touched**, and no dependency was
|
||||
added. `editors/vscode` was deliberately left alone, and the interplay is
|
||||
worth stating: `extension.js` still sets
|
||||
`synchronize: { configurationSection: 'lucisv' }`, so VS Code keeps *pushing*
|
||||
a real payload — the legacy path, unchanged — while `vscode-languageclient`
|
||||
advertises `workspace.configuration` and `workspace.workspaceFolders` on its
|
||||
own and therefore also answers the startup pull (with the same section, read
|
||||
by the same parser, to the same result). Dropping the `synchronize` line
|
||||
would leave the pull in sole charge and is a client-side change for another
|
||||
round. `smoke.js` sends `capabilities: {}` — the no-capability polarity, and
|
||||
the one worth keeping under test.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] `workspace.workspaceFolders: { supported: true, changeNotifications: true }`
|
||||
advertised, and pinned as JSON at the key a client reads.
|
||||
- [x] `workspace/didChangeWorkspaceFolders` handled: added/removed adjust the
|
||||
root set, one `reindex()` per notification.
|
||||
- [x] A removed folder's files leave the index; its open buffers stay open and
|
||||
keep being diagnosed.
|
||||
- [x] Duplicate adds, removing a never-added folder, an empty event, params
|
||||
that do not parse, a non-`file:` folder — all no-ops, none of them a
|
||||
rescan.
|
||||
- [x] Watcher determination made and implemented: source glob workspace-wide
|
||||
(no re-registration), filelist path anchored at the first root
|
||||
(re-registered when it moves).
|
||||
- [x] `workspace.configuration` read from the client's capabilities.
|
||||
- [x] One `workspace/configuration` at startup, gated on that capability.
|
||||
- [x] An empty `didChangeConfiguration` pulls instead of resetting; a
|
||||
populated one still applies directly.
|
||||
- [x] The answer applies through `settings::from_section` → the same
|
||||
`from_payload` a push uses, and through one `apply_settings`.
|
||||
- [x] `null`/empty/malformed/errored answers are total and leave the defaults.
|
||||
- [x] `applying` → `pending: HashMap<RequestId, Pending>`; three-way
|
||||
interleave tested.
|
||||
- [x] Tests: **27 new** — 4 in `settings.rs`, 4 in `state.rs`, 14
|
||||
`Session`-level in `server.rs`, 3 capability tests in `main.rs`, 2 e2e
|
||||
sessions against the real binary.
|
||||
- [x] `docs/features/lucisv-server/README.md` capability table and the
|
||||
roots/settings model text updated; `docs/features/file-watching/README.md`
|
||||
told about the folder interaction; TODO.md §9c boxes checked.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-08-27 — dev agent
|
||||
|
||||
**Item 1, `didChangeWorkspaceFolders`.**
|
||||
|
||||
- `main.rs::capabilities` now sends `workspace.workspaceFolders` with both
|
||||
fields. They are separate statements and a client reads them separately:
|
||||
`supported` says the server understands a multi-folder workspace at all,
|
||||
`changeNotifications` is what makes the client *send* the notification.
|
||||
`change_notifications` is `OneOf<bool, String>` in lsp-types 0.97 (checked
|
||||
against the crate source, not assumed); `Left(true)` is the right form here
|
||||
because the id-string variant exists only so the registration can later be
|
||||
unregistered by name, which this server never does.
|
||||
- `state.rs::change_roots` is the whole of the state change — 8 lines. Roots
|
||||
were already a private `Vec<PathBuf>` that `rebuild_index` re-walks from
|
||||
scratch, so widening and narrowing the set is genuinely nothing more than
|
||||
editing that list. Removals before additions; `bool` out, in the same shape
|
||||
`set_client_settings` uses, so the server's "did this cost a rescan?"
|
||||
question is asked the same way for both kinds of change.
|
||||
- The handler is five lines of body: parse, convert URIs to paths, change the
|
||||
roots, reindex if they moved, re-register the watchers if the *filelist*
|
||||
path moved. One `reindex()` per notification — an event carries both lists,
|
||||
and the progress bar, the code-lens refresh and the diagnostics generation
|
||||
all ride inside `reindex()` already, which
|
||||
`one_folder_notification_is_one_rescan_with_one_bar_and_one_generation` pins
|
||||
rather than assumes.
|
||||
- **The open-buffer question resolved by reading, not by inventing.** The
|
||||
brief asked that buffers in a removed folder keep behaving like rootless /
|
||||
out-of-scope buffers. They already do, and no code was needed:
|
||||
`collect_sources` appends every open document with a path *after* the scope
|
||||
ladder has spoken, so such a buffer stays in the index as itself; `reindex`
|
||||
republishes every open URI whatever the roots say; and `didOpen`'s
|
||||
root-conditional (`has_roots()` → publish, else reindex) reads the current
|
||||
root set, so a session that has lost its last folder starts behaving like
|
||||
the single-file case from the next `didOpen` on. The two tests
|
||||
(`a_removed_folder_leaves_the_index_and_its_open_buffer_keeps_being_diagnosed`,
|
||||
`removing_the_last_root_falls_back_to_the_rootless_model`) exist to keep
|
||||
that true, not to describe something new.
|
||||
- **The watcher determination** is written up in its own section above. Short
|
||||
version: the source glob is a base-less string pattern and is workspace-wide,
|
||||
so it needs no re-registration; the filelist watcher is an absolute path
|
||||
anchored at the first root, so it does — and the handler reuses the exact
|
||||
before/after comparison `didChangeConfiguration` already made.
|
||||
|
||||
**Item 2, `workspace/configuration`.**
|
||||
|
||||
- `ClientAbilities::configuration`, read in `main.rs` from
|
||||
`capabilities.workspace.configuration`, in the same shape as its five
|
||||
siblings.
|
||||
- `Server::request_configuration` sends one item, `section: "lucisv"`, no
|
||||
`scopeUri`, and records the id as `Pending::Configuration`. It is called
|
||||
from `Server::new` (immediately after `register_watchers`, which is the
|
||||
earliest legal moment and already proven so by the file-watching round) and
|
||||
from the `didChangeConfiguration` handler when the payload says nothing.
|
||||
- **Pending-map decision: one map, an enum, refactored.** The alternative was
|
||||
a second `HashMap<RequestId, ()>` beside `applying`. One map won: `response`
|
||||
is then a single lookup and a single `match`, the "which of our requests is
|
||||
this?" question has exactly one answer rather than one per map, and a third
|
||||
kind is a variant the compiler makes you handle instead of a map somebody
|
||||
forgets to consult. The cost is a rename (`applying` → `pending`) and one
|
||||
extracted function (`applied`, which is the old body verbatim). The
|
||||
fall-through that makes every *other* server-initiated request's answer
|
||||
ignorable is unchanged and still the documented rule.
|
||||
- **One parser, spelled out.** A pull answers the *contents* of the section;
|
||||
a push nests them under `lucisv`. Rather than a second reader,
|
||||
`settings::from_section` wraps the answer back into the push shape and calls
|
||||
`from_payload`. `a_pulled_section_is_read_by_exactly_the_same_rules_as_a_pushed_one`
|
||||
asserts the two agree on a fully-populated section *and* on a fully-junk
|
||||
one, which is the half that would actually rot.
|
||||
- **One applier.** The body of the old `didChangeConfiguration` arm became
|
||||
`Server::apply_settings` (rescan on a scope change, re-register on a moved
|
||||
filelist path) and both doors now go through it. There is no way to adopt
|
||||
settings without paying what they cost.
|
||||
- `settings::says_nothing` decides push-vs-pull: `null` and `{}` are the
|
||||
client saying "come and ask"; anything with a key in it is a payload, even
|
||||
when the key is some other server's section (that case has always meant "no
|
||||
opinion about anything" and still does).
|
||||
- **Deliberate non-change:** the pull's answer can land after the first index
|
||||
build. Stated in Assumptions, not fixed — blocking `Server::new` on a client
|
||||
round trip would be a deadlock waiting to happen (the spec lets a client
|
||||
answer whenever it likes) and the push path has always had the same shape.
|
||||
|
||||
**Tests.** 4 new in `settings.rs` (pull/push parser agreement, unusable
|
||||
answers, the push-empty predicate, the section constant), 4 new in `state.rs`
|
||||
(add/remove, every no-op shape, a folder in both lists, the last-folder
|
||||
fallback), 14 new `Session`-level tests in `server.rs` (folder add reaching
|
||||
`workspace/symbol`, removal with a still-diagnosed buffer, one-rescan-per-
|
||||
notification with bar/publish/refresh/generation counts, the six no-op shapes,
|
||||
the watcher re-registration polarity, the startup pull's params, the no-pull
|
||||
polarity, a pulled answer reaching the formatter, a pulled `exclude` rebuilding
|
||||
the index, seven unusable answers plus an error response, empty-push-pulls,
|
||||
empty-push-without-the-capability, populated-push-applies-directly, and the
|
||||
three-way interleave), 3 new capability tests in `main.rs`, and 2 new e2e
|
||||
sessions (a folder added and removed over the wire with a definition resolving
|
||||
into it, and a full pull round trip including the re-pull and the `null`
|
||||
answer).
|
||||
|
||||
**Gates.** `cargo fmt --all -- --check` clean; `cargo clippy --all-targets`
|
||||
clean; `cargo test --workspace` green (982 in the server binary, 48 e2e);
|
||||
`node editors/vscode/smoke.js` OK. One flake seen and *not* caused here:
|
||||
`lens::code_lenses_for_a_whole_file_cost_about_one_workspace_walk` is a
|
||||
wall-clock ratio test and fails under a loaded machine — it passes on its own
|
||||
and in a normal `--workspace` run.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-08-27 — QA agent
|
||||
|
||||
Reviewed the working tree on top of `45db6cd` (`git diff 45db6cd`), against
|
||||
the dev's claims above and the lead's attack-surface list. Verified by
|
||||
reading every changed line in `main.rs`/`server.rs`/`settings.rs`/`state.rs`/
|
||||
`tests/e2e.rs`, then attacking each surface below — mostly by adding a
|
||||
pinning test that exercises it directly rather than by inspection alone,
|
||||
since a claim about interleaving or wire order is only as good as a test
|
||||
that would fail if it were wrong. No redesign; two small additions beyond
|
||||
tests (both noted below) were within "small and unambiguous."
|
||||
|
||||
**Gates.**
|
||||
- `cargo fmt --all -- --check`: clean (after my own additions were formatted
|
||||
— one round of `cargo fmt --all` was needed once I'd added tests by hand).
|
||||
- `cargo clippy --all-targets`: clean, no warnings, before and after my
|
||||
additions.
|
||||
- `cargo test --workspace`, run twice end-to-end: green both times, no
|
||||
failures, no flake. Baseline was 982 `lucisv_server` unit tests as the dev
|
||||
reported; ended at 993 after the 11 tests I added (see below). 48 e2e tests
|
||||
green throughout.
|
||||
- The lens flake (`lens::code_lenses_for_a_whole_file_cost_about_one_workspace_walk`,
|
||||
`crates/lucisv_server/src/lens.rs:652`): did **not** fire in two full
|
||||
`cargo test --workspace` runs, nor in 5 back-to-back runs of that test
|
||||
alone with four `yes > /dev/null` processes competing for CPU
|
||||
(ratio stayed ~1.4–1.5x against the 2x budget each time). Did not need to
|
||||
check it at `45db6cd` since it never reproduced here — nothing in this
|
||||
diff touches `lens.rs`, and the test is a wall-clock ratio exactly as the
|
||||
dev described, so I take the dev's report at face value. Not a blocker.
|
||||
- `node editors/vscode/smoke.js target/debug/lucisv-server` (had to pass the
|
||||
path explicitly — `lucisv-server` is not on `PATH` in this checkout):
|
||||
`OK`. This is the no-capability (`capabilities: {}`) polarity, so it
|
||||
exercises the "client can't be asked, keeps today's behaviour" branch of
|
||||
both features.
|
||||
|
||||
**Attack surfaces — verdicts.**
|
||||
|
||||
1. **`roots.first()` dependency.** Verified clean, with new pins.
|
||||
`Workspace::change_roots` (`state.rs:138`) removes before adding and dedups
|
||||
adds via `contains`, so insertion order is preserved and a folder can only
|
||||
ever appear once — confirmed by
|
||||
`a_folder_added_twice_across_two_events_is_absent_after_one_removal`
|
||||
(new, `state.rs`): two separate add events for the same path plus one
|
||||
removal leaves it fully absent, not merely "count decremented." The
|
||||
remove-then-add-reorders-first case is exactly what
|
||||
`a_folder_change_re_registers_the_watchers_only_when_the_watched_path_moves`
|
||||
(existing, `server.rs:4908`) already pinned end to end (drop the first
|
||||
root, watch the second's `files.f`, both the reindex and the
|
||||
unregister+register fire). The "no roots left" total case was **not**
|
||||
pinned before this round: added
|
||||
`removing_the_last_root_leaves_a_relative_filelist_unanchored`
|
||||
(`state.rs`, near line 549) — `filelist_path()` returns the bare relative
|
||||
path (`PathBuf::from("files.f")`), anchored at nothing, once the last root
|
||||
is gone. Nothing panics and `source_files` still degrades to the rootless
|
||||
walk with a warning when that bare path can't be read
|
||||
(`a_filelist_that_cannot_be_read_falls_back_to_the_walk_and_says_so`
|
||||
already covers that half) — but it is a real, newly-reachable oddity
|
||||
(see finding F1 below) rather than an outright bug.
|
||||
|
||||
2. **`Pending` refactor / applyEdit routing.** Verified clean. The pre-existing
|
||||
applyEdit round's tests (`a_command_pushes_its_edit_...`,
|
||||
`a_response_with_a_jsonrpc_error_is_reported_too`,
|
||||
`a_cancel_naming_a_server_initiated_id_does_not_touch_response_routing`,
|
||||
etc.) are untouched by the diff and green. `three_outstanding_requests_are_answered_by_id_in_any_order`
|
||||
(`server.rs:5127`) does genuinely have all three requests
|
||||
(`applyEdit`, `workDoneProgress/create`, `workspace/configuration`)
|
||||
outstanding simultaneously before any answer — confirmed by reading
|
||||
`Session::sent`: it drains the channel once and the test pulls all three
|
||||
ids from that single drain — and answers them out of the send order
|
||||
(pull, then create, then edit) with each answer reaching the right
|
||||
handler. Two follow-up questions the dev's tests didn't cover, both now
|
||||
pinned: **two `Configuration` entries pending at once, answered out of
|
||||
order** — new `two_outstanding_configuration_pulls_are_each_answered_by_their_own_id`
|
||||
(`server.rs`): each answer is applied independently through its own id;
|
||||
whichever is *processed* last is what's in force after, no id-based
|
||||
precedence, which is the only sane semantics for a `HashMap` keyed by id.
|
||||
**An answer to an id `pending` doesn't hold** — new
|
||||
`an_answer_to_a_request_the_server_never_tracked_is_silently_ignored`
|
||||
(`server.rs`): a stale re-answer to an already-consumed id, and an id
|
||||
never sent at all, are both no-ops (trivially true from
|
||||
`HashMap::remove`'s `Option`, but worth a test that would catch a future
|
||||
refactor that made `response` assume the id is always present).
|
||||
|
||||
3. **Settings pull correctness.** Verified clean, with one real gap closed.
|
||||
`configured` (`server.rs:1174`) reads `response_result.unwrap_or(Value::Null)`
|
||||
then `answered.get(0)` — a client answering with 2 entries silently uses
|
||||
only entry 0 (correct: exactly one item was asked for), 0 entries or a
|
||||
non-array (`get(0)` on a string/number returns `None`) both fall through
|
||||
to `Value::Null` → defaults; `an_unusable_pull_answer_leaves_the_defaults_and_says_nothing`
|
||||
(`server.rs:5091`, pre-existing) already covers `null`, `[]`, `[null]`, a
|
||||
bare string, an object, junk-typed fields, and a `lucisv`-nested answer
|
||||
(the pull/push shape mismatch), plus an actual JSON-RPC error response —
|
||||
all resolve to defaults with no popup. `a_pulled_answer_that_changes_the_scope_rebuilds_the_index`
|
||||
(`server.rs:5048`, pre-existing) does assert the **index** actually
|
||||
changed (`indexed(&session, "scratch_pkg")` flips from 1 to 0), not just
|
||||
"no crash" — confirmed by reading it, not just trusting the name.
|
||||
**Gap found and closed:** nothing exercised a pulled *filelist* moving the
|
||||
watched path — `apply_settings` is shared code so it was very likely
|
||||
already correct, but "very likely" isn't "pinned." Added
|
||||
`a_pulled_filelist_re_registers_the_watchers_through_the_same_chain_a_push_uses`
|
||||
(`server.rs`, next to the exclude test): a pulled `{"filelist": "files.f"}`
|
||||
does cost an unregister+register with the new absolute path in the
|
||||
registration, exactly like the pushed case. **Precedence, traced and now
|
||||
pinned both directions:** the loop is single-threaded and processes
|
||||
messages in strict receive order; `apply_settings` always replaces the
|
||||
whole `ClientSettings` struct rather than merging, so whichever message is
|
||||
*processed* last wins, full stop. `a_push_with_a_payload_is_applied_directly_even_when_the_client_could_be_asked`
|
||||
(pre-existing) covers pull-then-push; added
|
||||
`a_late_pull_answer_overrides_a_push_that_landed_while_it_was_outstanding`
|
||||
for the other direction (push arrives while a pull is still outstanding,
|
||||
the pull's answer lands after and clobbers it). Both are "last processed
|
||||
wins," no special-casing either way — worth knowing, not worth fixing.
|
||||
|
||||
4. **Folder-change semantics.** Mostly verified clean; one real (low-severity,
|
||||
arguably by-design) finding.
|
||||
- Definition into an added folder: `a_folder_added_mid_session_is_indexed_over_the_wire`
|
||||
(e2e, pre-existing) asserts the returned location's `uri` string equals
|
||||
the expected `file://` URI exactly, which is as much "decoded correctly"
|
||||
as a same-process round trip can show without deliberately using a
|
||||
percent-encoded character in the added folder's path (this round's e2e
|
||||
test doesn't; existing coverage for URI-decoding a workspace path with
|
||||
unusual characters lives in `include_nav_round_trips_in_a_workspace_whose_directory_has_a_space`,
|
||||
unrelated to folder-add specifically). Did not add a new e2e test for
|
||||
this — the marginal risk is in `uri::uri_to_path`, which is untouched by
|
||||
this round and already has its own coverage.
|
||||
- Removed folder's symbols gone from `workspace/symbol`:
|
||||
`a_removed_folder_leaves_the_index_and_its_open_buffer_keeps_being_diagnosed`
|
||||
confirms via `indexed()` (an index-membership check, equivalent to what
|
||||
`workspace/symbol` reads from) that the removed folder's non-open file
|
||||
drops to 0 hits; `a_folder_added_mid_session_is_indexed_and_answers_workspace_symbol`
|
||||
drives a real `workspace/symbol` request for the added-folder case.
|
||||
- **F1 — subdirectory added as its own root bypasses the parent's
|
||||
`exclude`.** New test
|
||||
`a_subdirectory_of_an_existing_root_added_as_its_own_root_is_not_double_indexed`
|
||||
(`state.rs`) confirms there is **no** double-indexing/ambiguity when an
|
||||
already-covered subdirectory is added as a second root — `walked_files`'s
|
||||
`sort()`+`dedup()` on the combined path list handles that correctly, and
|
||||
`indexed()`'s "found exactly once" check would have caught an ambiguous
|
||||
double-registration if there were one. But a directory the parent root's
|
||||
`lucisv.toml` excludes **is** reachable once it's added as a root in its
|
||||
own right, because `walked_files` (`state.rs:365`) resolves each root's
|
||||
`exclude` independently via `Discovery::for_dir(root)`, and nothing
|
||||
excludes a root from itself. This is consistent with the documented
|
||||
per-root config model (`walked_files`'s own doc comment says so) and
|
||||
arguably *correct* — "Add Folder to Workspace" on a specific directory is
|
||||
an explicit ask to index it — but it was unreachable before this round
|
||||
(roots were frozen at `initialize`), so it's a genuinely new behavior the
|
||||
dev's README doesn't mention. Recommend a one-line callout in
|
||||
Assumptions if the lead agrees it's intentional; not a blocker either way,
|
||||
and not a corruption risk (formatter output is verified regardless of
|
||||
what got indexed).
|
||||
- Folder added twice then removed once: set semantics confirmed (new test,
|
||||
see item 1 above) — present after two adds, absent after one removal,
|
||||
not "still there because it was added twice."
|
||||
- Trailing slash: verified clean, and pinned anyway since the README calls
|
||||
it out as a boundary worth checking. `uri_to_path` decodes the URI
|
||||
verbatim (trailing slash included), but `PathBuf`/`Path` equality
|
||||
compares `Components`, not raw bytes — `Path::new("/a/b/") == Path::new("/a/b")`
|
||||
is `true` in std, confirmed with a throwaway `rustc` check before writing
|
||||
the test — so `change_roots`'s `contains`/`retain` already treat them as
|
||||
the same folder with no code needed. New:
|
||||
`a_trailing_slash_in_the_removed_folder_still_matches_the_held_root`
|
||||
(`state.rs`).
|
||||
|
||||
5. **Open-buffer convention.** Verified clean, one gap closed.
|
||||
`a_removed_folder_leaves_the_index_and_its_open_buffer_keeps_being_diagnosed`
|
||||
does assert diagnostics *content* — `!published[0].diagnostics.is_empty()`
|
||||
after editing the buffer to be broken, not merely "a publish happened."
|
||||
Closing such a buffer was **not** exercised — added a continuation of the
|
||||
same test (`server.rs`, same test) that sends `didClose` afterward and
|
||||
confirms the diagnostics clear (`published[0].diagnostics.is_empty()`).
|
||||
The code path (`DidCloseTextDocument` handling, `server.rs:1100`) is
|
||||
pre-existing and untouched by this diff — it doesn't special-case removed
|
||||
folders at all, which is correct: closing is generic.
|
||||
|
||||
6. **Startup pull ordering.** Verified clean, gap closed. `Server::new`
|
||||
(`server.rs:178`) calls `register_watchers()` then `request_configuration()`
|
||||
in that order in the source, but nothing checked the *wire*. Added
|
||||
`the_startup_pull_is_sent_after_the_watcher_registration_on_the_wire`
|
||||
(`server.rs`): checks both the drained-channel order and, independently,
|
||||
that the `RegisterCapability` request's `lucisv-N` id number is lower than
|
||||
the pull's (every outgoing request id comes off one monotonically
|
||||
increasing counter in `send_request`, `server.rs:1251`, so the numeric
|
||||
suffix *is* the send order — a second, independent way to catch a future
|
||||
reordering that a channel-order check alone might not). The full chain —
|
||||
pull answer → `apply_settings` → filelist moved → re-register — is now
|
||||
pinned by item 3's `a_pulled_filelist_re_registers_the_watchers_...` test.
|
||||
"Pulled settings can land after the first index build" is honestly
|
||||
documented in Assumptions and in the Work log; I didn't find anywhere it's
|
||||
overstated.
|
||||
|
||||
7. **CLAUDE.md compliance.** Clean.
|
||||
- No `unwrap()`/`expect()`/`panic!` in the non-test portion of
|
||||
`main.rs`/`server.rs`/`settings.rs`/`state.rs` (checked by slicing each
|
||||
file at its `#[cfg(test)]` boundary and grepping the part before it —
|
||||
all four files have exactly one such boundary).
|
||||
- New public items have doc comments: `Workspace::change_roots`,
|
||||
`settings::SECTION`, `settings::from_section`, `settings::says_nothing`,
|
||||
`ClientAbilities::configuration` all do. (Three *pre-existing* undocumented
|
||||
`pub fn`s in `state.rs` — `index`, `document`, `close_document` — are out
|
||||
of this round's diff and not this review's problem.)
|
||||
- `docs/features/folders-and-config/README.md` has every required section
|
||||
exactly once (Goal, Assumptions, Handshakes, Status/TODO, Work log, QA
|
||||
log, Review), plus two extra explanatory sections which the template
|
||||
doesn't forbid.
|
||||
- Both `TODO.md` §9c items are checked with their original text intact and
|
||||
a `→ delivered ...` addendum appended, not rewritten.
|
||||
- `crates/vlog_formatter/src/verify.rs`: zero diff against `45db6cd`
|
||||
(`git diff 45db6cd -- '**/verify.rs'` is empty) — untouched, as this
|
||||
round should never need it (nothing here touches formatting or
|
||||
verification).
|
||||
- `docs/site/` untouched by both the dev's diff and by me (per this
|
||||
round's instructions, never opened it).
|
||||
|
||||
**C. Beyond the list — "own shapes."**
|
||||
- `a_rapid_add_remove_add_of_the_same_folder_costs_three_rescans_and_ends_up_added`
|
||||
(`server.rs`): add, remove, add of the same folder across three separate
|
||||
notifications costs three separate rescans (no cross-notification
|
||||
batching — `change_roots` only batches within one event, as designed) and
|
||||
the net state (two adds, one remove) is "present," matching set semantics.
|
||||
- `a_rootless_session_gaining_its_first_folder_flips_didopen_from_reindex_to_publish`
|
||||
(`server.rs`): a session that starts with no roots at all (impossible to
|
||||
change mid-session before this round) gains its first folder via
|
||||
`didChangeWorkspaceFolders`, and the very next `didOpen` correctly takes
|
||||
the `has_roots()` branch — publish only, no second rescan — where it would
|
||||
have reindexed before the folder arrived. (Caught my own arithmetic error
|
||||
writing this: `generation` counts *both* a buffer's text and the index, so
|
||||
a rootless `didOpen` costs two bumps — `set_document` plus `reindex` — not
|
||||
one; fixed the assertion rather than the code, since the code is correct
|
||||
and pre-existing.)
|
||||
|
||||
**Fixes made directly (small, unambiguous, noted here per the workflow).**
|
||||
- None to production code. Everything above is test-only: 11 new tests
|
||||
across `state.rs` (5) and `server.rs` (6), all passing, `cargo fmt`/
|
||||
`clippy` clean throughout. `cargo test --workspace` ended at 993
|
||||
`lucisv_server` unit tests (982 dev baseline + 11) plus the unchanged
|
||||
48 e2e, both green across two full runs.
|
||||
|
||||
**Verdict: committable as-is.** No corruption risk, no invariant violated,
|
||||
no test that should exist and doesn't after this pass. F1 (subdirectory
|
||||
root bypassing parent's exclude) is worth a documentation line from the lead
|
||||
or dev — not worth blocking on, since it's arguably correct behavior and
|
||||
carries no data-loss or formatting-correctness risk.
|
||||
|
||||
## Review
|
||||
|
||||
### 2026-08-27 — lead
|
||||
|
||||
Reviewed the diff, the work log and the QA log; re-ran all gates myself,
|
||||
clean. Both items landed the way small protocol features should: the
|
||||
folder handler is one 8-line state method plus the existing reindex
|
||||
machinery (with the bar, the lens refresh and the generation all pinned
|
||||
as riding along rather than assumed), and the config pull reuses the one
|
||||
settings parser and the one applier so the two doors cannot drift. The
|
||||
watcher determination — base-less glob needs nothing, the absolute-path
|
||||
filelist watcher re-registers through the comparison the push path
|
||||
already ran — is the kind of read-first engineering this workflow is
|
||||
for. The Pending-enum refactor is accepted: one map, one match, and a
|
||||
third request kind is now a compiler-enforced variant; QA re-ran the
|
||||
apply-edit suite and interleaved all three answer kinds out of order to
|
||||
prove the shipped routing survived.
|
||||
|
||||
QA's roots.first() attack found the design holds (order preserved,
|
||||
last-root-removal total) and its eleven added tests closed every
|
||||
claim that lacked one, including the previously-untested
|
||||
pull-answer-moves-the-filelist chain. F1 is accepted as designed and
|
||||
now documented in Assumptions: a subdirectory added as its own root is
|
||||
its own root, per-root config applied consistently. The extension's
|
||||
redundant push+pull double-answer stays filed for a client-side round.
|
||||
Accepted as shipped.
|
||||
@@ -52,6 +52,8 @@ looks like language knowledge in here is a bug or a `Handshake` request.
|
||||
| `workspace/codeLens/refresh` | — | Server-**initiated**, once per workspace rescan, straight after the indexing bar comes down: a rescan can change any count on screen. Only for a client that advertised `workspace.codeLens.refreshSupport`; never at startup, where no buffer holds lenses. Same feature README |
|
||||
| `workspace/symbol` | `WorkspaceIndex::workspace_symbols` | Capped at 256 hits |
|
||||
| `workspace/didChangeWatchedFiles` | `Workspace::rebuild_index` | Registered dynamically after the handshake, for a client that advertised it. One rebuild per *notification*, however many files it names. See `docs/features/file-watching/README.md` |
|
||||
| `workspace/didChangeWorkspaceFolders` | `Workspace::change_roots` + `rebuild_index` | Folders added and removed mid-session, since 2026-08-27. One rescan per *notification* (the event carries both lists), and none at all for an event that leaves the root set where it was — a folder already held, one never held, an empty event, a non-`file:` folder. A removed folder's files leave the index; its open buffers stay open and keep being diagnosed, exactly as an out-of-scope buffer always has. Advertised as `workspace.workspaceFolders: { supported, changeNotifications }` — both halves, because a client reads them separately. See `docs/features/folders-and-config/README.md` |
|
||||
| `workspace/configuration` | `settings::from_section` → `from_payload` | Server-**initiated**, since 2026-08-27: the `lucisv` section, asked for once at startup and again on every *empty* `didChangeConfiguration` (the 3.17 client's "something changed, ask me"). Only for a client that advertised `workspace.configuration`; a push with a payload still applies directly, so the legacy path is untouched. The answer is entry 0 of an array and goes through the same parser a push does; an error, a `null`, an empty array or junk all mean the defaults, and none of them says anything to the user. Same feature README |
|
||||
| `workspace/willRenameFiles` | `includes::IncludeGraph` (through `resolve_as_if`) | The client is about to rename files and asks what that costs: every `` `include`` in scope whose **resolved** target moves — never a filename match — is re-spelled so it still resolves, in the form it was written in (bare stays bare where a rung reaches it, angled resolves through `+incdir+`s only, absolute stays absolute), shortest resolving suffix first and a `../`-relative spelling only as a last resort. An include written *in* a file that moves is re-spelled too. An include no spelling can reach is **left exactly as written** and named in a `window/showMessage` warning — nothing is invented. `null` when there is nothing to do. Folders are answered as well as files (LSP sends only the folder's URI; a folder is a path prefix). Every edit covers the path token alone and is verified three ways before it is emitted — see `docs/features/file-operations/README.md` |
|
||||
| `workspace/didRenameFiles`, `workspace/didDeleteFiles` | `Workspace::rebuild_index` | One `reindex()` per notification whose paths touch the index's scope, filtered by the same predicate a watched-file event is. Deliberately not deduplicated against the watcher: a client may send both, and a second rebuild re-reads the tree rather than changing an answer. Source-file filters only — a folder move reaches the index through the watcher's own events. Same feature README |
|
||||
| `window/workDoneProgress/create` + `$/progress` | — | Server-**initiated**: one indeterminate bar per workspace rescan, titled "Indexing Verilog workspace", ending with the indexed file count. Only for a client that advertised `window.workDoneProgress`. See `docs/features/work-done-progress/README.md` |
|
||||
@@ -231,7 +233,7 @@ reasoning and the measurements: `docs/features/cancel-request/README.md`.
|
||||
| layer | rebuilt when | cost |
|
||||
|---|---|---|
|
||||
| a document's `Semantics` + tokens + diagnostics | every `didOpen`/`didChange` — **once per notification**, however many ranges it carried | one file, full recompute |
|
||||
| the `WorkspaceIndex` | `initialize`, every `didSave`, every `workspace/didChangeWatchedFiles`, and a changed `lucisv.exclude`/`lucisv.filelist` | full re-scan of the roots |
|
||||
| the `WorkspaceIndex` | `initialize`, every `didSave`, every `workspace/didChangeWatchedFiles`, every `workspace/didChangeWorkspaceFolders` that moves the root set, and a changed `lucisv.exclude`/`lucisv.filelist` (pushed **or** pulled) | full re-scan of the roots |
|
||||
| the `` `include`` graph | with the `WorkspaceIndex`, from the same file list | a line scan per file (~6ms over the 860-file corpus). An open buffer's *own* includes are re-resolved on every request instead, so a line just typed is clickable before the next save |
|
||||
|
||||
**Per-file recompute on every keystroke** is the strategy TODO.md §6 states
|
||||
@@ -282,6 +284,23 @@ model above; nested `-f` filelists are not watched, only the root one;
|
||||
rebuild from any cause picks it up); and there is no time-based debouncing, so
|
||||
a burst arriving as several separate notifications costs one rebuild each.
|
||||
|
||||
**Settings arrive two ways since 2026-08-27** (folders-and-config): pushed, as
|
||||
they always were, and *pulled*. A client that advertised
|
||||
`workspace.configuration` is sent one `workspace/configuration` for the
|
||||
`lucisv` section at startup, and another whenever it sends a
|
||||
`didChangeConfiguration` whose payload is empty — which is the 3.17 client's
|
||||
way of saying "something changed, come and ask", and is what
|
||||
`vscode-languageclient` sends once no legacy `synchronize.configurationSection`
|
||||
is configured. A push that carries a real payload still applies directly, so
|
||||
nothing about the old path moved. Both doors lead to one parser
|
||||
(`settings::from_payload`) and one applier (`Server::apply_settings`), so a
|
||||
setting cannot mean two things depending on how it arrived, and
|
||||
`exclude`/`filelist` cost the same rescan either way. A pulled answer can land
|
||||
*after* the first index build — as a pushed one always could, since neither
|
||||
can arrive before `initialized` — so the first index is built against the
|
||||
default scope and a narrowing setting costs one extra rescan when it lands.
|
||||
Rules: `docs/features/folders-and-config/README.md`.
|
||||
|
||||
**Definition targets in other files need that file's text** to turn a
|
||||
`TextRange` into a `Range`, and the index deliberately keeps no file contents.
|
||||
The server resolves a target by taking the **open buffer's text if that path
|
||||
@@ -313,6 +332,13 @@ not see.
|
||||
on a POSIX path legitimately named `/C:`.
|
||||
- **The workspace walk is plain.** `initialize`'s `workspace_folders` (falling
|
||||
back to `root_uri`) are walked recursively for `*.v`/`*.sv`/`*.vh`/`*.svh`.
|
||||
~~They are read once and frozen for the session.~~ **Superseded
|
||||
(folders-and-config, 2026-08-27): `workspace/didChangeWorkspaceFolders`
|
||||
adjusts the root set mid-session, one rescan per notification. A removed
|
||||
folder's files leave the index while its open buffers stay open and keep
|
||||
being diagnosed, and removing the *last* folder simply becomes rung 3 of
|
||||
the scope ladder — the rootless case — with no special handling. See
|
||||
`docs/features/folders-and-config/README.md`.**
|
||||
~~`.gitignore` and `--exclude` are **not** honored~~ **Superseded by
|
||||
lucisv-core-lift (lead note): the scan now uses the lifted `lucisv_core` walk —
|
||||
`.gitignore` always on, workspace-root config excludes applied. The old
|
||||
|
||||
Reference in new issue
Block a user