LSP §9b: semantic tokens range + full/delta
tokens.rs is now one tokenizer behind three pure steps — absolute() classifies and splits, within() filters by overlap, encode() delta- encodes — so textDocument/semanticTokens/range and /full share one implementation and cannot drift; QA proved the refactor byte-identical to the old encoder over a 41k-token corpus file against the pre-change binary. Range answers are self-contained (overlapping tokens kept whole, re-encoded from the document start) and carry no resultId — a delta never diffs against a partial view. /full/delta remembers each open buffer's last answer under a per-answer id (dropped on didClose; stale or foreign ids answer full) and diffs by common-prefix/suffix trim to a single edit, the suffix counted over what the prefix left — the classic overlap trap, deliberately broken by dev and QA separately and caught by the suite both times. Edit indices are wire-array u32 positions (5 per token), pinned. No token request touches the pull-diagnostics generation. 38 tests added (dev 29 + QA 9), including two independently written edit appliers cross-checked over 200 random pairs and two differently seeded randomized sweeps through the real tokenizer. docs/features/semantic-tokens-delta/README.md Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
80b9afdfe3
commit
00c03eccf9
7 files changed
+1732
-43
No files matched your search
@@ -23,7 +23,9 @@ looks like language knowledge in here is a bug or a `Handshake` request.
|
||||
| `textDocument/didChange` | `sync::apply_changes` | Incremental sync: the ranges are applied in order to the buffer the server holds, then one `set_document` + one `publish`. A rangeless change still replaces the whole buffer, so a full-sync client is unaffected. See `docs/features/incremental-sync/README.md` |
|
||||
| `textDocument/diagnostic`, `workspace/diagnostic` | the same parse+lint pass | The 3.17 pull model, served to a client that advertised `textDocument.diagnostic` — which is then pushed nothing at all. `resultId` is one generation counter, bumped by a buffer change and by an index rebuild; the workspace report covers the **open buffers**. Same feature README |
|
||||
| `textDocument/selectionRange` | `Document.tokens`, AST spans, `pairs::analyze` | Expand-selection: one strictly nesting chain per requested position, token → statement → block → item → file. No expression step. See `docs/features/selection-range/README.md` |
|
||||
| `textDocument/semanticTokens/full` | `vlog_parser::tokenize` + `Semantics` | Delta-encoded, split at line boundaries |
|
||||
| `textDocument/semanticTokens/full` | `vlog_parser::tokenize` + `Semantics` | Delta-encoded, split at line boundaries. Stamped with a `resultId` since 2026-08-26, so a delta can name it |
|
||||
| `textDocument/semanticTokens/range` | the same classification pass | The visible lines only, for the first paint of a large file. A **self-contained** answer: the tokens overlapping the range, kept whole, re-encoded from the start of the document. No `resultId` — a partial view is not what a delta is computed against. See `docs/features/semantic-tokens-delta/README.md` |
|
||||
| `textDocument/semanticTokens/full/delta` | the same classification pass | What changed since the answer the client names: one edit replacing everything between the common prefix and the common suffix (the suffix capped so the two cannot overlap — identical lines of Verilog encode identically, which is exactly the trap). An id the server does not hold, including one from before a `didClose`, is answered in full. Same feature README |
|
||||
| `textDocument/hover` | `DefineTable`, `Semantics`, `WorkspaceIndex`, `includes::IncludeGraph`, `expand` | Macro body, or declaration kind + snippet. A macro this file does not define is answered from the workspace: the definition it **reaches through its `` `include``s** when exactly one is reachable, and every candidate otherwise. A macro card also shows what the hovered use **expands to in one step** — the body with this call's arguments substituted — when that says more than the body already does; a nested `` `INNER`` is left as written, an argument count that does not match expands nothing, and several candidates expand nothing. See `docs/features/macro-expansion/README.md` |
|
||||
| `textDocument/definition` | `includes::IncludeGraph`, then `Semantics`, then `ExternalResolutions` | A cursor on an `` `include`` line jumps to the resolved file's first byte; otherwise the in-file symbol table, then the workspace overlay, whose `Ambiguous` answer returns every location. See `docs/features/include-nav/README.md` |
|
||||
| `textDocument/documentLink` | `includes::IncludeGraph` | One link per **resolvable** `` `include``, covering the quoted path, target already resolved (`resolveProvider: false`). Search order: the including file's own directory, then each `+incdir+` of the configured filelist in order; the `<angled>` form skips the first rung. An include nothing answers to gets no link and no error. Same feature README |
|
||||
@@ -392,7 +394,18 @@ Two rules that are easy to get wrong and are tested:
|
||||
three multi-line token shapes that would violate it — a block comment, a
|
||||
continued `` `define``, and a multi-line macro invocation. Every span is
|
||||
split at `\n` before encoding, and the pieces are sorted by (line, start)
|
||||
before the delta encoding runs.
|
||||
before the delta encoding runs. Single-line tokens are also what lets the
|
||||
`range` filter reason about overlap without looking at the text at all.
|
||||
|
||||
Since 2026-08-26 that classification feeds three requests, not one: the pass
|
||||
produces an intermediate **absolute** form (line, column, length, type,
|
||||
modifiers), `range` filters it, and one pure encoder delta-encodes whatever is
|
||||
left — from the start of the document in every case, so a range answer stands
|
||||
on its own. The `resultId` bookkeeping that makes `full/delta` possible lives
|
||||
in `server.rs` (one counter, one remembered answer per open buffer, dropped on
|
||||
`didClose`), because `tokens.rs` owns no state. Rules, the prefix/suffix
|
||||
overlap trap and the round-trip property:
|
||||
`docs/features/semantic-tokens-delta/README.md`.
|
||||
|
||||
## Hover, and the order it tries things
|
||||
|
||||
@@ -456,7 +469,10 @@ list to `vlog_parser::KEYWORDS`. Rationale and inventory:
|
||||
`Semantics`, `DefineTable`, overlay), workspace walk, index rebuild.
|
||||
- [x] `textDocument/formatting`.
|
||||
- [x] Diagnostics on `didOpen`/`didChange`/`didSave`.
|
||||
- [x] `textDocument/semanticTokens/full`.
|
||||
- [x] `textDocument/semanticTokens/full`, joined by `/range` and `/full/delta`
|
||||
(2026-08-26) — one tokenizer and one encoder behind all three, plus a
|
||||
per-buffer `resultId` dropped on `didClose`.
|
||||
`docs/features/semantic-tokens-delta/README.md`.
|
||||
- [x] `textDocument/hover`.
|
||||
- [x] `textDocument/definition`.
|
||||
- [x] `textDocument/references`.
|
||||
|
||||
Reference in new issue
Block a user