LSP §9c: type hierarchy over extends
textDocument/prepareTypeHierarchy + typeHierarchy/supertypes/subtypes for SystemVerilog classes. Supertypes is one computed offset into the existing resolution machinery — the overlay promotion made cross-file bare class names answerable, and the offset is the LAST byte of the extends name span so pkg::base lands in the tail's reference, never the package's. Subtypes is a workspace census on the callers_of_each pattern (one sources() pass, prefilter, deterministic sort), matching the base name as written — 0 of the corpus's 270 extends clauses are qualified, and the asymmetry with supertypes is documented and pinned from both directions, including the same-name/different-file consequence. Ambiguous bases answer every declaration, like definition. Modules stay on callHierarchy by scope ruling. lsp-types 0.97 has no server-side typeHierarchyProvider field, so initialize_value() inserts the one key into the serialized result — QA's strip-and-compare test proves every other key survives with identical values. QA also traced the parser to show the degenerate extends spans the code guards against cannot be constructed, corrected two README figures the lead applied (the 309 extends count did not reproduce; 270 does), and pinned the generate-block walk gap as a scoped choice. Interface classes stay blocked on the parser, pinned. 45 tests added (dev 33 + QA 12), including the real ibex UVM chain and a 10-deep expansion. The inheritance-edge index want is filed beside the instantiation-edge Handshake as one future round. docs/features/type-hierarchy/README.md Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
24e8eab78b
commit
bf17ddd1e5
7 files changed
+2028
-6
No files matched your search
@@ -44,6 +44,9 @@ looks like language knowledge in here is a bug or a `Handshake` request.
|
||||
| `textDocument/prepareCallHierarchy` | `instantiations::{sites,declarations}`, `WorkspaceIndex::units` | The module under the cursor as a hierarchy node (`SymbolKind::Module`), from its own declaration or from any instantiation of it. Every other position answers `null`; an ambiguous name returns every declaration, as `definition` does. See `docs/features/hierarchy/README.md` |
|
||||
| `callHierarchy/incomingCalls` | `instantiations::sites` over `Workspace::sources` | "Who instantiates X": one call per **instantiating module**, `fromRanges` naming every site inside it. Walks the in-scope files — the index holds no instantiation edges — skipping any file whose text does not contain the name (56 ms over the 860-file corpus). Since 2026-08-26 this is `hierarchy::callers_of_each` with a one-name batch; the batched form is what `textDocument/codeLens` counts from, so there is exactly one census. Same feature README |
|
||||
| `callHierarchy/outgoingCalls` | `instantiations::sites`, `WorkspaceIndex::units` | "What X instantiates": one call per **distinct instantiated module**, `fromRanges` naming its sites. A target the index does not hold, or holds twice, is skipped silently. Same feature README |
|
||||
| `textDocument/prepareTypeHierarchy` | the class walk over `Document.tree`, then `ExternalResolutions::definition_of` | The **class** under the cursor as a type hierarchy node (`SymbolKind::Class`), from its own declaration or from any use of its name (an `extends` base, a property's type, a method local's type). Every other position answers `null`; a name two files declare returns both, as `definition` does. Advertised by hand — `lsp-types` 0.97's `ServerCapabilities` has no `typeHierarchyProvider` field. See `docs/features/type-hierarchy/README.md` |
|
||||
| `typeHierarchy/supertypes` | `ClassDecl::extends` + `ExternalResolutions::definition_of` | "What X extends": its base class, resolved by the same two layers F12 uses — in-file first, then the workspace overlay — asked at the **last byte** of the extends name, which is the tail of `pkg::base` and the whole of a bare `base`. A parameterized base resolves by its bare name; a base the workspace does not index (every UVM chain top) yields **no** item rather than a guess. Same feature README |
|
||||
| `typeHierarchy/subtypes` | the class walk over `Workspace::sources` | "Who extends X": every class in scope whose `extends` names it, sorted by file then position. Walks the in-scope files — the index holds no inheritance edges — skipping any file whose text does not contain the name (55 ms over the 860-file corpus, 53 ms of it file I/O). A **qualified** base is not matched by a bare name, the `callHierarchy` precedent; 0 of the corpus's 270 `extends` clauses are qualified. Same feature README |
|
||||
| `textDocument/codeLens` | `instantiations::declarations` + `hierarchy::callers_of_each` | **"N instantiations"** above every module and interface declaration in the buffer, on the declaration's own name span. N is the number of instantiation *sites* across the workspace — the same population `callHierarchy/incomingCalls` reports, from the same walk asked about every module in the file at once, so the two can never disagree. `resolveProvider: false`: every lens is complete. Clicking runs `lucisv.showInstantiations`; a module with **no** instantiations gets a display-only lens (empty `command`) instead of a click that leads nowhere. Unopened buffer → `null`; a declaration with no name span gets no lens. See `docs/features/code-lens/README.md` |
|
||||
| `workspace/executeCommand` → `lucisv.showInstantiations` | `hierarchy::callers_of_each` | The code lens's own jump: `["module-name"]` in, every site as a `Location` out — one per site, file-then-position order. For a client that advertised `window.showDocument`, the server also pushes a `window/showDocument` for the **first** site, which is what makes the click navigate; LSP has no server-initiated peek-references, and this repo's extension declares no client-side command. A name with no sites answers `[]`; a missing or empty name is `RequestFailed`. Same feature README |
|
||||
| `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 |
|
||||
@@ -577,6 +580,11 @@ list to `vlog_parser::KEYWORDS`. Rationale and inventory:
|
||||
the module hierarchy both directions, modules as the nodes and
|
||||
instantiations as the calls, off a walk shared with the inlay hints.
|
||||
`docs/features/hierarchy/README.md`.
|
||||
- [x] `typeHierarchy` (all three requests) — delivered by **type-hierarchy**
|
||||
(2026-08-26, TODO.md §9c): the class `extends` tree both directions,
|
||||
classes as the nodes. The capability is inserted into the serialized
|
||||
`initialize` result because `lsp-types` 0.97 has no field for it.
|
||||
`docs/features/type-hierarchy/README.md`.
|
||||
- [x] Single-step macro expansion on a hover card (`src/expand.rs`, M14) —
|
||||
`docs/features/macro-expansion/README.md`.
|
||||
- [x] `$/cancelRequest` — delivered by **cancel-request** (2026-08-26,
|
||||
@@ -588,6 +596,43 @@ list to `vlog_parser::KEYWORDS`. Rationale and inventory:
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-08-26 — dev agent (type-hierarchy, TODO.md §9c)
|
||||
|
||||
- **One new capability, one new module, nothing else moved.** The three
|
||||
`typeHierarchy` requests are served from
|
||||
`crates/lucisv_server/src/type_hierarchy.rs`; `server.rs` gained three
|
||||
dispatch arms. No engine change — `vlog_semantic` and `vlog_parser` are
|
||||
untouched, and `hierarchy.rs`/`instantiations.rs` were not opened.
|
||||
- **The capability is written by hand.** `lsp-types` 0.97 models type hierarchy
|
||||
on the *client* side only: `ServerCapabilities` has no
|
||||
`type_hierarchy_provider` field. `main.rs`'s new `initialize_value` serializes
|
||||
the `InitializeResult` and inserts `"typeHierarchyProvider": true` into the
|
||||
capabilities object — the same JSON a field would have produced — because a
|
||||
capability a client cannot see is a feature that is never requested.
|
||||
`experimental` was not used: different key, and no client reads it for this.
|
||||
- **Classes, not modules.** The lead's scope decision, argued in the feature
|
||||
README: an instantiation is a containment edge and `extends` is an
|
||||
inheritance edge, so the module hierarchy stays on `callHierarchy` where it
|
||||
shipped, and this request serves one node kind well.
|
||||
- **`supertypes` is `definition_of` at a computed offset**, not a new lookup.
|
||||
`extends Base` is already a reference, and the overlay-promotion round already
|
||||
made a bare cross-file class name reachable through it, so the only new idea
|
||||
is *which* offset to ask about: the last byte of the extends name span, which
|
||||
is the tail of `pkg::base` and the whole of a bare `base`. That gets in-file
|
||||
bases, cross-file bases, package-qualified bases and parameterized bases from
|
||||
one line, and can never disagree with F12 on the same token.
|
||||
- **`subtypes` is `callers_of_each`'s census in another key**: one
|
||||
`sources()` pass, a substring prefilter before any parse, a deterministic
|
||||
sort. 55 ms over the 860-file corpus, 53 ms of it file I/O — the same shape
|
||||
`incomingCalls` measured, and the same backlog item (an edge table in
|
||||
`WorkspaceIndex`, now filed for inheritance edges beside the instantiation
|
||||
ones).
|
||||
- **What the class model lacked:** interface classes. `vlog_parser` rejects
|
||||
`interface class` outright, so `implements` can never resolve and no item can
|
||||
carry `SymbolKind::Interface`; both facts are pinned by tests named to force a
|
||||
future parser round past them. Full details, assumptions, cost table and the
|
||||
ambiguity argument: `docs/features/type-hierarchy/README.md`.
|
||||
|
||||
### 2026-08-25 — dev agent (M14 macro-expansion, 0.5.0)
|
||||
|
||||
- **No new capability, one new module, one card grew a section.**
|
||||
|
||||
Reference in new issue
Block a user