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
839a28ec8d
commit
203e9b1a4f
7 files changed
+2028
-6
No files matched your search
@@ -866,9 +866,32 @@ and are not gaps.
|
||||
the `;` is the one closing a module header. `pairs.rs` gained three
|
||||
`pub(crate)` accessors so the matcher and the indent model read one
|
||||
keyword table.
|
||||
- [ ] **Type hierarchy (3.17)** — arguably the semantically correct
|
||||
- [x] **Type hierarchy (3.17)** — arguably the semantically correct
|
||||
home for the module hierarchy (and later interface/class extends
|
||||
chains); keep callHierarchy as the compatibility surface.
|
||||
→ delivered 2026-08-26 by `docs/features/type-hierarchy/README.md`:
|
||||
`typeHierarchyProvider` + `crates/lucisv_server/src/type_hierarchy.rs`,
|
||||
all three requests. **Classes, not modules** — the lead's scope call:
|
||||
an instantiation is a containment edge and `extends` is an inheritance
|
||||
edge, so the module hierarchy stays on callHierarchy exactly as this
|
||||
item's second clause asks, and typeHierarchy serves one node kind
|
||||
well. `supertypes` is not a new lookup: `extends Base` is already a
|
||||
`vlog_semantic` reference and overlay-promotion already made a bare
|
||||
cross-file class name reachable through it, so the answer is
|
||||
`definition_of` asked at the last byte of the extends name span —
|
||||
which is the tail of `pkg::base`, the whole of a bare `base`, and the
|
||||
bare name of a parameterized `base #(8)`. A base the workspace does
|
||||
not index (every UVM chain top) yields no item rather than a guess.
|
||||
`subtypes` is `hierarchy::callers_of_each`'s census in another key —
|
||||
one `sources()` pass, substring prefilter, deterministic sort — at
|
||||
55 ms over the 860-file corpus, 53 ms of it file I/O; the
|
||||
inheritance-edge table that would make it a lookup is filed beside the
|
||||
instantiation-edge table §9c's code-lens item already recorded. Two
|
||||
gaps recorded there: `lsp-types` 0.97 has no `typeHierarchyProvider`
|
||||
field, so the capability is inserted into the serialized `initialize`
|
||||
result by hand, and `vlog_parser` rejects `interface class`, so
|
||||
`implements` can never resolve and no item can carry
|
||||
`SymbolKind::Interface`.
|
||||
- [ ] **File operations** — `workspace/willRenameFiles`: renaming a
|
||||
`.sv/.svh` rewrites `` `include`` lines that reference it (the
|
||||
include graph exists); `didRename/didDelete` as cheaper index nudges
|
||||
|
||||
@@ -39,6 +39,7 @@ mod sync;
|
||||
mod templates;
|
||||
mod tokens;
|
||||
mod type_def;
|
||||
mod type_hierarchy;
|
||||
mod uri;
|
||||
mod watch;
|
||||
|
||||
@@ -79,7 +80,7 @@ fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||
code_lens_refresh: code_lens_refresh_support(¶ms),
|
||||
show_document: show_document_support(¶ms),
|
||||
};
|
||||
connection.initialize_finish(id, serde_json::to_value(initialize_result())?)?;
|
||||
connection.initialize_finish(id, initialize_value()?)?;
|
||||
|
||||
Server::new(connection, roots, abilities).run()?;
|
||||
io_threads.join()?;
|
||||
@@ -285,6 +286,22 @@ fn commands() -> Vec<String> {
|
||||
commands
|
||||
}
|
||||
|
||||
/// The `initialize` result exactly as it goes on the wire.
|
||||
///
|
||||
/// `typeHierarchyProvider` is written in here rather than in [`capabilities`]
|
||||
/// because `lsp-types` 0.97 models type hierarchy on the *client* side only:
|
||||
/// `ServerCapabilities` has no field for it, and `experimental` is a different
|
||||
/// key that no client reads for this. So the one capability this server
|
||||
/// advertises that the crate cannot spell is inserted into the serialized
|
||||
/// object, which is the same JSON a field would have produced.
|
||||
fn initialize_value() -> Result<serde_json::Value, serde_json::Error> {
|
||||
let mut value = serde_json::to_value(initialize_result())?;
|
||||
if let Some(caps) = value.get_mut("capabilities").and_then(serde_json::Value::as_object_mut) {
|
||||
caps.insert("typeHierarchyProvider".to_string(), serde_json::Value::Bool(true));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn initialize_result() -> lsp_types::InitializeResult {
|
||||
lsp_types::InitializeResult {
|
||||
capabilities: capabilities(),
|
||||
@@ -434,6 +451,51 @@ mod tests {
|
||||
assert!(caps.document_on_type_formatting_provider.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_type_hierarchy_is_advertised_even_though_lsp_types_cannot_spell_it() {
|
||||
// `ServerCapabilities` has no `type_hierarchy_provider` field in
|
||||
// lsp-types 0.97 — the crate models type hierarchy on the client side
|
||||
// only — so the capability is written into the serialized object. A
|
||||
// client keys entirely off this key: without it the three requests are
|
||||
// never sent, however well they are implemented.
|
||||
let value = initialize_value().expect("the initialize result serializes");
|
||||
assert_eq!(
|
||||
value["capabilities"]["typeHierarchyProvider"],
|
||||
serde_json::json!(true),
|
||||
"{value:#?}"
|
||||
);
|
||||
// And the rest of the object is untouched by the insertion.
|
||||
assert_eq!(value["capabilities"]["callHierarchyProvider"], serde_json::json!(true));
|
||||
assert_eq!(value["serverInfo"]["name"], serde_json::json!("lucisv-server"));
|
||||
}
|
||||
|
||||
// QA (2026-08-26): the spot checks above name two fields; this pins the
|
||||
// whole object instead. `initialize_result()` and `capabilities()` are
|
||||
// untouched by this round (confirmed against `24e8eab`), so the only way
|
||||
// the insertion could disturb anything is the one `caps.insert` call
|
||||
// itself — this proves that byte-for-byte rather than by inspection: pull
|
||||
// the one inserted key back out and what remains must equal the plain,
|
||||
// uninserted serialization exactly. A future round that lets the
|
||||
// insertion clobber an existing key, or that adds a field to
|
||||
// `ServerCapabilities` under the same JSON name, fails this immediately.
|
||||
#[test]
|
||||
fn the_json_insertion_disturbs_nothing_else_in_the_initialize_result() {
|
||||
let mut with_insertion = initialize_value().expect("the initialize result serializes");
|
||||
let plain = serde_json::to_value(initialize_result()).expect("serializes on its own too");
|
||||
let caps =
|
||||
with_insertion["capabilities"].as_object_mut().expect("capabilities is a JSON object");
|
||||
assert_eq!(
|
||||
caps.remove("typeHierarchyProvider"),
|
||||
Some(serde_json::json!(true)),
|
||||
"the one key the insertion is supposed to add"
|
||||
);
|
||||
assert_eq!(
|
||||
with_insertion, plain,
|
||||
"removing the inserted key must restore exactly what capabilities() \
|
||||
and initialize_result() produce on their own, key for key, value for value"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_type_formatting_asks_for_the_newline_and_the_semicolon_and_nothing_else() {
|
||||
// The trigger set is the feature: a client sends this request on every
|
||||
|
||||
@@ -27,8 +27,9 @@ use lsp_types::request::{
|
||||
InlayHintRequest, InlineCompletionRequest, LinkedEditingRange, OnTypeFormatting,
|
||||
PrepareRenameRequest, RangeFormatting, References, RegisterCapability, Rename, Request as _,
|
||||
SelectionRangeRequest, SemanticTokensFullDeltaRequest, SemanticTokensFullRequest,
|
||||
SemanticTokensRangeRequest, ShowDocument, Shutdown, SignatureHelpRequest, UnregisterCapability,
|
||||
WillSaveWaitUntil, WorkDoneProgressCreate, WorkspaceDiagnosticRequest, WorkspaceSymbolRequest,
|
||||
SemanticTokensRangeRequest, ShowDocument, Shutdown, SignatureHelpRequest, TypeHierarchyPrepare,
|
||||
TypeHierarchySubtypes, TypeHierarchySupertypes, UnregisterCapability, WillSaveWaitUntil,
|
||||
WorkDoneProgressCreate, WorkspaceDiagnosticRequest, WorkspaceSymbolRequest,
|
||||
};
|
||||
use lsp_types::{
|
||||
ApplyWorkspaceEditParams, ApplyWorkspaceEditResponse, CallHierarchyIncomingCallsParams,
|
||||
@@ -48,7 +49,8 @@ use lsp_types::{
|
||||
SemanticTokens, SemanticTokensDelta, SemanticTokensDeltaParams, SemanticTokensFullDeltaResult,
|
||||
SemanticTokensParams, SemanticTokensRangeParams, SemanticTokensRangeResult,
|
||||
SemanticTokensResult, ShowDocumentParams, ShowMessageParams, SignatureHelpParams,
|
||||
TextDocumentPositionParams, UnchangedDocumentDiagnosticReport, UnregistrationParams, Uri,
|
||||
TextDocumentPositionParams, TypeHierarchyPrepareParams, TypeHierarchySubtypesParams,
|
||||
TypeHierarchySupertypesParams, UnchangedDocumentDiagnosticReport, UnregistrationParams, Uri,
|
||||
WillSaveTextDocumentParams, WorkDoneProgress, WorkDoneProgressBegin,
|
||||
WorkDoneProgressCreateParams, WorkDoneProgressEnd, WorkspaceDiagnosticParams,
|
||||
WorkspaceDiagnosticReport, WorkspaceDiagnosticReportResult, WorkspaceDocumentDiagnosticReport,
|
||||
@@ -62,7 +64,7 @@ use crate::state::Workspace;
|
||||
use crate::{
|
||||
code_action, completion, diagnostics, folding, format, hierarchy, hover, includes, inlay,
|
||||
inline, lens, linked, nav, on_type, pairs, ports, rename, selection, settings, signature,
|
||||
symbols, sync, tokens, type_def, watch,
|
||||
symbols, sync, tokens, type_def, type_hierarchy, watch,
|
||||
};
|
||||
|
||||
/// What the client said it can do, read once at `initialize` because that is
|
||||
@@ -585,6 +587,29 @@ impl Server {
|
||||
to_value(hierarchy::outgoing(&self.workspace, &p.item))
|
||||
})
|
||||
}
|
||||
// The class inheritance tree. Same contract as the call hierarchy
|
||||
// above: `prepare` answers `null` for a position that is not a
|
||||
// class name, and the two directions answer one hop each while the
|
||||
// client drives the expansion.
|
||||
TypeHierarchyPrepare::METHOD => {
|
||||
decode(request).and_then(|p: TypeHierarchyPrepareParams| {
|
||||
let at = p.text_document_position_params;
|
||||
let (uri, position) = (at.text_document.uri, at.position);
|
||||
self.offset(&uri, position)
|
||||
.and_then(|offset| type_hierarchy::prepare(&self.workspace, &uri, offset))
|
||||
.map_or(Ok(Value::Null), to_value)
|
||||
})
|
||||
}
|
||||
TypeHierarchySupertypes::METHOD => {
|
||||
decode(request).and_then(|p: TypeHierarchySupertypesParams| {
|
||||
to_value(type_hierarchy::supertypes(&self.workspace, &p.item))
|
||||
})
|
||||
}
|
||||
TypeHierarchySubtypes::METHOD => {
|
||||
decode(request).and_then(|p: TypeHierarchySubtypesParams| {
|
||||
to_value(type_hierarchy::subtypes(&self.workspace, &p.item))
|
||||
})
|
||||
}
|
||||
WorkspaceSymbolRequest::METHOD => {
|
||||
decode(request).and_then(|p: WorkspaceSymbolParams| {
|
||||
to_value(WorkspaceSymbolResponse::Flat(symbols::workspace_symbols(
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -3539,3 +3539,100 @@ fn a_save_asks_a_capable_client_to_refresh_its_code_lenses_over_the_wire() {
|
||||
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
const TYPE_BASE: &str = "class type_base;\n int x;\nendclass\n";
|
||||
const TYPE_MID: &str = "class type_mid extends type_base;\n int y;\nendclass\n";
|
||||
const TYPE_LEAF: &str = "class type_leaf extends type_mid;\nendclass\n";
|
||||
|
||||
#[test]
|
||||
fn the_class_hierarchy_round_trips_over_the_wire_in_both_directions() {
|
||||
// What only an e2e test can check: that `typeHierarchyProvider` is
|
||||
// advertised in the shape a client reads — `lsp-types` has no field for it,
|
||||
// so it is written into the serialized capabilities by hand — and that an
|
||||
// item the *client* sends back, rather than one this process still holds,
|
||||
// is what the two directions are answered from.
|
||||
let dir = temp_dir("type_hierarchy");
|
||||
let base = dir.join("type_base.sv");
|
||||
std::fs::write(&base, TYPE_BASE).expect("write");
|
||||
let mid = dir.join("type_mid.sv");
|
||||
std::fs::write(&mid, TYPE_MID).expect("write");
|
||||
let leaf = dir.join("type_leaf.sv");
|
||||
std::fs::write(&leaf, TYPE_LEAF).expect("write");
|
||||
|
||||
let root = format!("file://{}", dir.display());
|
||||
let mid_uri = format!("file://{}", mid.display());
|
||||
let base_uri = format!("file://{}", base.display());
|
||||
let leaf_uri = format!("file://{}", leaf.display());
|
||||
// The item a client holds after `prepareTypeHierarchy` and sends back for
|
||||
// each direction: `type_mid`, declared on lines 0..2 of `type_mid.sv`.
|
||||
let mid_item = format!(
|
||||
r#"{{"name":"type_mid","kind":5,"uri":"{mid_uri}","range":{{"start":{{"line":0,"character":0}},"end":{{"line":2,"character":8}}}},"selectionRange":{{"start":{{"line":0,"character":6}},"end":{{"line":0,"character":14}}}}}}"#
|
||||
);
|
||||
|
||||
let session = [
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":1,"method":"initialize","params":{{"processId":null,"rootUri":"{root}","capabilities":{{}}}}}}"#
|
||||
)),
|
||||
frame(r#"{"jsonrpc":"2.0","method":"initialized","params":{}}"#),
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{{"textDocument":{{"uri":"{mid_uri}","languageId":"systemverilog","version":1,"text":{}}}}}}}"#,
|
||||
serde_json::to_string(TYPE_MID).expect("json")
|
||||
)),
|
||||
// The cursor on the `type_mid` of its own declaration.
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":2,"method":"textDocument/prepareTypeHierarchy","params":{{"textDocument":{{"uri":"{mid_uri}"}},"position":{{"line":0,"character":8}}}}}}"#
|
||||
)),
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":3,"method":"typeHierarchy/supertypes","params":{{"item":{mid_item}}}}}"#
|
||||
)),
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":4,"method":"typeHierarchy/subtypes","params":{{"item":{mid_item}}}}}"#
|
||||
)),
|
||||
// A property name is not a class, so there is no hierarchy to open.
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":5,"method":"textDocument/prepareTypeHierarchy","params":{{"textDocument":{{"uri":"{mid_uri}"}},"position":{{"line":1,"character":7}}}}}}"#
|
||||
)),
|
||||
frame(r#"{"jsonrpc":"2.0","id":9,"method":"shutdown","params":null}"#),
|
||||
frame(r#"{"jsonrpc":"2.0","method":"exit","params":null}"#),
|
||||
]
|
||||
.concat();
|
||||
|
||||
let messages = talk(&session);
|
||||
let response = |id: u32| -> &serde_json::Value {
|
||||
messages.iter().find(|m| m["id"] == id).unwrap_or_else(|| panic!("no {id}: {messages:#?}"))
|
||||
};
|
||||
|
||||
let capabilities = &response(1)["result"]["capabilities"];
|
||||
assert_eq!(capabilities["typeHierarchyProvider"], serde_json::json!(true));
|
||||
|
||||
let prepared = response(2)["result"].as_array().expect("a list of items");
|
||||
assert_eq!(prepared.len(), 1, "{prepared:#?}");
|
||||
assert_eq!(
|
||||
prepared[0],
|
||||
serde_json::from_str::<serde_json::Value>(&mid_item).expect("json"),
|
||||
"the item the client will send back is exactly the one built here"
|
||||
);
|
||||
|
||||
let supertypes = response(3)["result"].as_array().expect("a list of items");
|
||||
assert_eq!(supertypes.len(), 1, "one base: {supertypes:#?}");
|
||||
assert_eq!(supertypes[0]["name"], "type_base");
|
||||
assert_eq!(supertypes[0]["uri"], base_uri.as_str());
|
||||
assert_eq!(supertypes[0]["kind"], 5, "SymbolKind.Class");
|
||||
assert_eq!(
|
||||
supertypes[0]["selectionRange"],
|
||||
serde_json::json!({
|
||||
"start": { "line": 0, "character": 6 }, "end": { "line": 0, "character": 15 }
|
||||
}),
|
||||
"the base's own name span, in its own file"
|
||||
);
|
||||
|
||||
let subtypes = response(4)["result"].as_array().expect("a list of items");
|
||||
assert_eq!(subtypes.len(), 1, "one subtype: {subtypes:#?}");
|
||||
assert_eq!(subtypes[0]["name"], "type_leaf");
|
||||
assert_eq!(subtypes[0]["uri"], leaf_uri.as_str());
|
||||
assert_eq!(subtypes[0]["kind"], 5, "SymbolKind.Class");
|
||||
|
||||
assert_eq!(response(5)["result"], serde_json::Value::Null, "a property name is no class");
|
||||
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
@@ -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.**
|
||||
|
||||
@@ -0,0 +1,581 @@
|
||||
# type-hierarchy
|
||||
|
||||
TODO.md §9c: **the class `extends` tree, both directions, over LSP
|
||||
`typeHierarchy`.**
|
||||
|
||||
## Goal
|
||||
|
||||
"What does this class extend?" and "who extends it?" are the two questions a
|
||||
verification engineer asks about a UVM testbench they did not write, and until
|
||||
now lucisv could answer neither without a grep. LSP has had the shape for both
|
||||
since 3.17: its type hierarchy is a graph of supertypes and subtypes, and
|
||||
SystemVerilog's `extends` is exactly that graph — the classes are the nodes and
|
||||
`class d extends b` is the edge. So `textDocument/prepareTypeHierarchy` picks a
|
||||
class out of the text under the cursor, `typeHierarchy/supertypes` answers "what
|
||||
does X extend" and `typeHierarchy/subtypes` answers "who extends X", and every
|
||||
LSP client draws the tree with its own hierarchy view — no editor code at all.
|
||||
|
||||
Each request answers **one hop**. The client drives the expansion, so a cycle
|
||||
needs no handling here beyond not crashing: `class a extends a;` simply appears
|
||||
again one level down, and an `a → b → a` pair unrolls as far as the user keeps
|
||||
clicking.
|
||||
|
||||
**Scope decision, made by the lead before the round: classes only.** The module
|
||||
hierarchy stays on `callHierarchy`, where it shipped and is tested
|
||||
(`docs/features/hierarchy/README.md`). Mapping modules onto `typeHierarchy` as
|
||||
well was considered and rejected: an instantiation is a *containment* edge and
|
||||
`extends` is an *inheritance* edge, and serving both from one request would put
|
||||
two unrelated relations behind one node kind with no way for a client — or a
|
||||
reader — to tell them apart. One item kind, done well.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **`extends` is the edge, and nothing else is.** `implements` names an
|
||||
**interface class**, which is a different construct (IEEE 1800 §8.26) that
|
||||
`vlog_parser` does not model at all — `interface class ic; ... endclass` is
|
||||
rejected as an unsupported construct
|
||||
(`vlog_parser::parser::parse_keyword_item`, and its own
|
||||
`interface_class_is_not_an_interface` test). So an `implements` target can
|
||||
never be a class declaration this server holds, and matching one by name would
|
||||
claim an unrelated ordinary class of that name. `implements` therefore
|
||||
contributes no supertype. Pinned by
|
||||
`an_implements_clause_names_no_supertype` and
|
||||
`an_interface_class_is_not_a_node_because_the_parser_does_not_model_one`,
|
||||
the second named so a future parser round that models interface classes is
|
||||
forced past it.
|
||||
- **Every item is `SymbolKind::CLASS`.** Following from the above: there is no
|
||||
node in this feature that could carry `INTERFACE`, because there is no AST
|
||||
node for an interface class to build one from.
|
||||
- **A class has exactly one base**, which is what the AST gives
|
||||
(`ClassDecl::extends` is an `Option<ClassExtends>`) and what the LRM says for
|
||||
ordinary classes. `supertypes` is therefore a list of at most one — except
|
||||
under the workspace's documented duplicate policy, below.
|
||||
- **The base is resolved by the same two layers `textDocument/definition`
|
||||
uses**, and by nothing of this feature's own: the file's symbol table first,
|
||||
then the workspace overlay. `vlog_semantic` already records `extends Base` as
|
||||
a reference (`docs/features/class-semantics/README.md` rule 5), and the
|
||||
overlay-promotion round made a bare cross-file class name reachable through
|
||||
that same reference, so a base in another file needs no lookup here. The one
|
||||
thing this feature computes is *which offset* to ask about: the **last byte**
|
||||
of the extends clause's `name_span`. For a bare `base` that is that one
|
||||
reference; for `pkg::base` it is inside the **tail's** reference, which is the
|
||||
one that names a class (the head names the package), and it is the right byte
|
||||
whatever spacing the source used around the `::`.
|
||||
- **A parameterized base needs no unwrapping.** The parser keeps `#( ... )` on
|
||||
its own field, so `extends base #(8)` stores `base` in `ClassExtends::name`
|
||||
and its `name_span` covers `base` alone. This is the class-semantics policy
|
||||
already, verified by reading `parse_class_extends`, and pinned by
|
||||
`a_parameterized_base_resolves_by_its_bare_name`.
|
||||
- **An unresolvable base yields no item, never a guess.** `extends uvm_object`
|
||||
in a workspace that does not index UVM has nowhere honest to point: an item
|
||||
carries a `uri` and a `range`, and a wrong one sends the user to the wrong
|
||||
file with no way to tell. So the chain simply stops. This is not rare — it is
|
||||
the normal top of every UVM chain in the corpus — and it is what the corpus
|
||||
test asserts at `core_ibex_base_test extends uvm_test`.
|
||||
- **`subtypes` matches the base name exactly as written**, which is the
|
||||
`hierarchy` feature's own "the walk is by name" assumption applied to
|
||||
`extends`. Two consequences, both deliberate:
|
||||
- A **qualified** base is not matched: `class d extends other_pkg::base;` is
|
||||
not offered as a subtype of a file-scope `base`, because matching on the
|
||||
trailing segment would silently claim it. Measured: **0 of the 270 `extends`
|
||||
clauses in the checked-in 860-file corpus are qualified**, so this costs
|
||||
nothing observable here. It does make the two directions asymmetric —
|
||||
`supertypes` *does* follow `pkg::base`, through the package — which is
|
||||
stated rather than hidden, and pinned by
|
||||
`a_qualified_base_is_not_claimed_by_the_bare_name_it_ends_with`.
|
||||
- Two classes of the same name in different files get the **same** subtype
|
||||
list. `subtypes` reads the item's `name`, not its `uri` — exactly as
|
||||
`callHierarchy/incomingCalls` does for a module name — because the text
|
||||
`extends base` says which *name* was extended and nothing more.
|
||||
- **Ambiguity is answered the same way in both directions, and differently from
|
||||
`outgoingCalls`.** A base name two files declare gives **two** supertype
|
||||
items. This is a deliberate departure from `hierarchy::outgoing`, which skips
|
||||
an ambiguous target: an outgoing *call* carries `fromRanges`, so two items
|
||||
would double one edge, whereas a supertype is a bare item in a flat list —
|
||||
the same list shape `prepare` returns, where showing both is how the user is
|
||||
told the ambiguity exists. It also comes for free from the shared overlay,
|
||||
whose documented policy is to offer every declaration
|
||||
(`docs/features/workspace-index/README.md`).
|
||||
- **A cursor immediately after the last character of a name is on that name.**
|
||||
`TextRange::contains` excludes the end, which is right for a span of text and
|
||||
wrong for a caret — that is where a double-click and an end-of-word motion
|
||||
leave it. Same convention `hierarchy.rs` states.
|
||||
- **The scope ladder decides which files are searched.** `subtypes` reads
|
||||
`Workspace::sources()`, so a file a filelist or an `exclude` keeps out of the
|
||||
index extends nothing, exactly as it references nothing. Open buffers beat
|
||||
disk, so an `extends` just typed and not yet saved is already a subtype.
|
||||
- **Classes are found wherever they can be written**: at file scope, inside a
|
||||
`package` (the dominant UVM shape), inside a `module`, and nested inside
|
||||
another class. A generate block is not descended into. QA traced the parser and corrected
|
||||
the original justification: classes inside generate blocks DO parse into
|
||||
real `ClassDecl` nodes — the walk simply does not recurse there. Zero such
|
||||
classes exist in the 860-file corpus, so the gap is theoretical today; the
|
||||
pinning test (`a_class_declared_inside_a_generate_block_is_not_found_by_this_walk`)
|
||||
makes a future round close it on purpose.
|
||||
|
||||
## Handshakes
|
||||
|
||||
- **Consumes `vlog_parser`** — `parse_source_tolerant`, `ast::ClassDecl` /
|
||||
`ClassExtends` (read-only, for `name`, `name_span` and `extends`),
|
||||
`Item::span`, `LineIndex`. Nothing new is asked of the crate.
|
||||
- **Consumes `vlog_semantic`** — `ExternalResolutions::definition_of` and
|
||||
`Definition`, `Semantics::reference_at`, `SymbolKind::Class`,
|
||||
`WorkspaceIndex::path`. **Nothing was changed in the crate.** The whole
|
||||
cross-file half of this feature is the overlay-promotion round's work being
|
||||
consumed: `extends Base` was already a reference carrying the bare name as its
|
||||
last candidate path, so the workspace already had the answer and this feature
|
||||
only had to ask for it at the right offset.
|
||||
- **Consumes `crate::state::{Workspace, Document}`** — `document`, `index`,
|
||||
`text_of`, `sources`, and `Document::new` for the one case an item names a
|
||||
file no editor has open (see the work log). Nothing in `state.rs` was changed;
|
||||
the workspace stays immutable through all three handlers, and no cache was
|
||||
added.
|
||||
- **Promises `lucisv_server`** — `type_hierarchy::{prepare, supertypes,
|
||||
subtypes}` never panic, never return an item whose `selectionRange` is outside
|
||||
its `range`, and never return an item for a class the workspace does not
|
||||
really declare.
|
||||
- **Requested of `vlog_semantic`, not done here: an inheritance edge table in
|
||||
`WorkspaceIndex`.** This is the *same* Handshake `docs/features/hierarchy`
|
||||
filed for instantiation edges and `docs/features/code-lens` rode past — the
|
||||
index records what a file *declares* and not what it uses, so "who extends X"
|
||||
has to be a workspace walk. One table keyed by base name, built with the
|
||||
index, would make `subtypes` a map lookup at the cost of one extra field per
|
||||
class at index time. Filed together with the instantiation table rather than
|
||||
separately: the two want the same shape and should land as one round when
|
||||
something finally justifies widening the index's contract. Today one request
|
||||
in 55 ms does not.
|
||||
- **`editors/vscode` needs no change.** `vscode-languageclient` 9.0.1 ships the
|
||||
type-hierarchy feature and enables it off the advertised capability; the
|
||||
extension sets no `initializationOptions` that would suppress it, and
|
||||
Vim/Neovim clients drive it through their own commands.
|
||||
`editors/vscode/smoke.js` checks a fixed capability list and was deliberately
|
||||
left untouched (it is editor-packaging's file) — it still passes.
|
||||
|
||||
## The one thing `lsp-types` could not spell
|
||||
|
||||
`lsp-types` 0.97 models type hierarchy on the **client** side only:
|
||||
`TypeHierarchyClientCapabilities` exists, the three request types and
|
||||
`TypeHierarchyItem` exist, and `ServerCapabilities` has **no**
|
||||
`type_hierarchy_provider` field. A capability a client cannot see is a feature
|
||||
that is never requested, however well it is implemented — so `initialize_value`
|
||||
in `main.rs` serializes the `InitializeResult` and inserts
|
||||
`"typeHierarchyProvider": true` into the capabilities object, which is the same
|
||||
JSON a field would have produced. `experimental` was not used: it is a different
|
||||
key and no client reads it for this. Pinned twice — in `main.rs` (the JSON
|
||||
carries the key, and the insertion disturbs nothing else) and over the wire in
|
||||
`tests/e2e.rs`.
|
||||
|
||||
## What it looks like
|
||||
|
||||
`type_mid.sv`:
|
||||
|
||||
```systemverilog
|
||||
class type_mid extends type_base;
|
||||
int y;
|
||||
endclass
|
||||
```
|
||||
|
||||
Cursor on `type_mid` anywhere — its own declaration, its `extends` in another
|
||||
class, or a `type_mid handle;` — and the hierarchy view shows:
|
||||
|
||||
```
|
||||
supertypes (what type_mid extends) subtypes (who extends type_mid)
|
||||
type_base type_base.sv:1 type_leaf type_leaf.sv:1
|
||||
```
|
||||
|
||||
## Cost
|
||||
|
||||
Release build, this machine, the checked-in 860-file corpus, worst of three
|
||||
(printed by `the_corpus_uvm_classes_answer_all_three_requests`):
|
||||
|
||||
| request | measured |
|
||||
|---|---:|
|
||||
| `subtypes` for `core_ibex_base_test` (10 subclasses across the corpus) | **55 ms** |
|
||||
| — of which reading the 860 files (`Workspace::sources()`) | **53 ms** |
|
||||
| — of which the substring prefilter over all of them | 0.28 ms |
|
||||
| — of which parsing + walking the **3** files that mention the name | ~2 ms |
|
||||
| `supertypes` for `core_ibex_debug_intr_basic_test` | **0.69 ms** |
|
||||
| the same `subtypes` in a debug build | 101 ms |
|
||||
|
||||
The shape is the same one `callHierarchy/incomingCalls` measured (56 ms), and
|
||||
for the same reason: what is left after the prefilter is **almost entirely file
|
||||
I/O**, because `sources()` reads every in-scope file whether it will be parsed
|
||||
or not. That is the shared cost of every cross-file answer in this server and
|
||||
the place a future win lives (the edge table above, or a cheaper `sources()`);
|
||||
nothing in this feature can shave it alone. The prefilter itself is not a
|
||||
heuristic — `extends base` has to write `base` — and here it skips 857 of 860
|
||||
files.
|
||||
|
||||
`supertypes` never walks the workspace at all: it parses one file (the item's
|
||||
own) and, at most, re-reads the one file that declares the base. The same
|
||||
worst-case caveat `hierarchy` records applies to `subtypes` in principle — a
|
||||
class name that is a substring of nearly every file defeats the prefilter — but
|
||||
UVM class names are long and specific, and no such name exists in the corpus.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] `crates/lucisv_server/src/type_hierarchy.rs`: the class walk,
|
||||
`prepare`, `supertypes`, `subtypes`
|
||||
- [x] `typeHierarchyProvider` in `main.rs` (inserted into the serialized
|
||||
capabilities, because `lsp-types` 0.97 has no field for it); three
|
||||
dispatch arms in `server.rs`
|
||||
- [x] `prepare` on a declaration / on a use (`extends` base, a property's type,
|
||||
a method local's type) / on anything else (`null`), including a property
|
||||
name, a module, a wire and the `class` keyword
|
||||
- [x] Ambiguity: every declaration from `prepare` **and** from `supertypes`,
|
||||
with the departure from `outgoingCalls` argued
|
||||
- [x] Bases in-file, cross-file through the overlay, package-qualified,
|
||||
parameterized, and unresolvable (no item)
|
||||
- [x] `subtypes` in-file, cross-file, sorted deterministically and stable across
|
||||
two calls; scope ladder and unsaved-buffer overlay honoured
|
||||
- [x] Self-extends and a two-class cycle: one hop each, no duplicate, no hang
|
||||
- [x] Classes in a package, in a module and nested in a class
|
||||
- [x] UTF-16 positions, an untitled buffer, an unopened document, a file that
|
||||
has since moved, a nameless item, a buffer that does not parse
|
||||
- [x] `selectionRange` inside `range` asserted for every item the feature can
|
||||
hand out, in three tests including the corpus one
|
||||
- [x] Unit tests (31 in `type_hierarchy.rs`, 1 capability test in `main.rs`) and
|
||||
one e2e stdio round trip: prepare → supertypes → subtypes across three
|
||||
files
|
||||
- [x] Corpus smoke: 30 classes of `core_ibex_test_lib.sv` through all three
|
||||
requests, plus the real `core_ibex_debug_intr_basic_test →
|
||||
core_ibex_base_test → (uvm_test, unindexed)` chain
|
||||
- [x] Cost measured over the 860-file corpus, with the I/O split out
|
||||
- [x] `cargo fmt --all -- --check`, `cargo clippy --all-targets --workspace`,
|
||||
`cargo test --workspace`, `editors/vscode/smoke.js`
|
||||
- [x] `docs/features/lucisv-server/README.md` capability table + work log;
|
||||
TODO.md §9c
|
||||
- [ ] Not done, backlog: the **inheritance edge table in `WorkspaceIndex`**,
|
||||
filed with the instantiation-edge table it should ship beside (Handshakes
|
||||
above).
|
||||
- [ ] Not done, blocked: **interface classes**. `vlog_parser` rejects
|
||||
`interface class`, so `implements` can never resolve and no item can carry
|
||||
`SymbolKind::INTERFACE`. When the parser models them, this feature needs
|
||||
one arm in the walk, one kind, and `implements` added to `supertypes`.
|
||||
- [ ] Not done, deliberately: chasing a chain server-side (the client drives
|
||||
it), a whole-tree "show me every class" view, and typedef/struct
|
||||
hierarchies — SystemVerilog has no inheritance for them.
|
||||
|
||||
## Work log
|
||||
|
||||
- **2026-08-26 (dev)** — read CLAUDE.md, then `lucisv-server`, `hierarchy`,
|
||||
`class-semantics` and `overlay-promotion` READMEs, then `hierarchy.rs`,
|
||||
`instantiations.rs`, `type_def.rs`, `nav.rs`, `state.rs`,
|
||||
`vlog_semantic`'s `workspace.rs` and `vlog_parser`'s `parse_class` before
|
||||
writing anything.
|
||||
|
||||
**What the class model gave, and what it did not.** It gave everything the
|
||||
cross-file half needs and it gave it *already resolved*: `ClassDecl` carries a
|
||||
parser `name_span`, `ClassExtends` carries the base name with its `::` chain
|
||||
and its own span, `extends` is recorded as a reference by `vlog_semantic`, and
|
||||
since the overlay-promotion round that reference reaches the workspace unit
|
||||
table carrying the bare name. So `supertypes` is not a lookup this feature
|
||||
wrote — it is `definition_of` asked at one computed offset. What the model did
|
||||
**not** give is interface classes: `interface class` does not parse at all, so
|
||||
`implements` is a dead end and `SymbolKind::INTERFACE` is unreachable. Checked
|
||||
rather than assumed, and recorded in Assumptions with the parser's own test as
|
||||
the citation.
|
||||
|
||||
**Design decision 1 — resolve the base through the semantic reference, not
|
||||
through the index.** The alternative was `WorkspaceIndex::units(base_name)`,
|
||||
which is what `hierarchy::outgoing` does for an instantiated module. It would
|
||||
have been wrong here for two reasons: it cannot see a base declared **in the
|
||||
same file** (a very common shape — a base and its children in one `_lib.sv`,
|
||||
which is exactly what the corpus test file is), and it cannot follow
|
||||
`pkg::base` (the unit table holds no package-scoped class). `definition_of`
|
||||
handles both, in the documented order, and is the same answer F12 gives on the
|
||||
same token — so the two can never disagree about what `extends base` names.
|
||||
That is also what made the round small: the only new idea is *which offset*.
|
||||
|
||||
**Design decision 2 — the offset is the last byte of the extends name span.**
|
||||
For `pkg::base` the clause records two references (head and tail); the head
|
||||
names the package and the tail names the class, so the answer has to come from
|
||||
the tail. Taking `name_span.end - 1` lands inside the tail under every
|
||||
spelling, including the `pkg :: base` one that class-semantics warns can glue
|
||||
its `::`. Taking `name_span.start` would have answered the *package* for every
|
||||
qualified base — a wrong file, silently.
|
||||
|
||||
**Design decision 3 — `subtypes` is a name walk, like `callers_of_each`.**
|
||||
The brief asked for the census to be modelled on it and it is: one
|
||||
`sources()` pass, a substring prefilter before any parse, and a deterministic
|
||||
sort at the end. The precision question it raises — should `other_pkg::base`
|
||||
count as extending `base`? — was settled by measurement rather than taste:
|
||||
**0 of 270 `extends` clauses in the corpus are qualified** (count per QA's
|
||||
reproducible grep — the work log's original 309 did not reproduce), so the precise
|
||||
version (resolve every candidate's base semantically and compare identities)
|
||||
would have bought nothing measurable for a large multiple of the cost and a
|
||||
second resolution path to keep honest. The asymmetry it leaves with
|
||||
`supertypes` is documented and pinned rather than papered over.
|
||||
|
||||
**Design decision 4 — ambiguity is shown, not skipped.** `hierarchy::outgoing`
|
||||
skips an ambiguous target and says why: a call carries `fromRanges`, so two
|
||||
items for one edge would double the edge. A supertype has no such payload — it
|
||||
is one item in a flat list, the same shape `prepare` returns — so listing both
|
||||
candidate declarations tells the user the ambiguity exists instead of hiding
|
||||
it behind silence. Argued in Assumptions so the inconsistency with the
|
||||
neighbouring feature is on the record.
|
||||
|
||||
**The capability had to be hand-written.** `ServerCapabilities` in `lsp-types`
|
||||
0.97 has no `type_hierarchy_provider` field (grepped the crate: the only
|
||||
`type_hierarchy` in `lib.rs` is the *client* capability at line 1453). Rather
|
||||
than fork the crate or abuse `experimental`, `initialize_value` inserts the
|
||||
key into the serialized object. It is three lines, it returns `Result` rather
|
||||
than unwrapping, and it is pinned at both layers. Recorded here because it is
|
||||
the one place this feature is not simply "call the crate".
|
||||
|
||||
**`Document::new` for a closed file.** Items carry no `data` payload — they
|
||||
are re-derived per request, like the call hierarchy's — so a client is free to
|
||||
send back an item naming a file no editor has open, which is exactly what
|
||||
happens the moment a user expands a subtype and then asks *it* for its base.
|
||||
`hierarchy::outgoing` needs only a parse there and re-parses; `supertypes`
|
||||
needs a *resolution*, so it builds a full `Document` (parse + analyze +
|
||||
overlay) for that one file. Pinned by
|
||||
`supertypes_answer_for_a_file_no_editor_has_open`, which walks base →
|
||||
subtype → base across an unopened file.
|
||||
|
||||
**Three one-line helpers restated rather than shared** (`touches`, `span`,
|
||||
`key`). Each is a statement of a convention this handler makes — a caret at
|
||||
the end of a name is on it; a range sorts by line then character — and the two
|
||||
handlers share no logic a common helper would keep honest. Said out loud in
|
||||
the source so the duplication reads as a choice.
|
||||
|
||||
**Files touched.** New: `crates/lucisv_server/src/type_hierarchy.rs`, this
|
||||
README. Edited: `crates/lucisv_server/src/main.rs` (one module declaration,
|
||||
`initialize_value`, one test), `crates/lucisv_server/src/server.rs` (three
|
||||
dispatch arms and their imports), `crates/lucisv_server/tests/e2e.rs` (one new
|
||||
test), `docs/features/lucisv-server/README.md` (capability table and work
|
||||
log), `TODO.md` (§9c).
|
||||
|
||||
**Not touched, deliberately:** `hierarchy.rs` and `instantiations.rs` (the
|
||||
module hierarchy is untouched by the scope decision), `vlog_semantic`,
|
||||
`vlog_parser`, `vlog_refactor`, `editors/`, `docs/site/`. No version bump, no
|
||||
new dependency, no commits.
|
||||
|
||||
**Gates.** `cargo fmt --all -- --check` clean; `cargo clippy --all-targets
|
||||
--workspace` zero warnings; `cargo test --workspace` green at **2 060 passed,
|
||||
4 ignored, 0 failed** (2 027 before; +33 = 31 in `type_hierarchy.rs`, 1 in
|
||||
`main.rs`, 1 e2e round trip). `cargo build --release -p lucisv_server && node
|
||||
editors/vscode/smoke.js target/release/lucisv-server`: `smoke: OK`.
|
||||
|
||||
## QA log
|
||||
|
||||
- **2026-08-26 (QA)** — re-ran every gate, then attacked the seven surfaces the
|
||||
lead named plus three of my own. Verdict: **committable as-is**. Two
|
||||
findings filed, both non-blocking (documentation/completeness, not
|
||||
correctness or corruption); everything else verified clean. +12 tests added
|
||||
(11 in `type_hierarchy.rs`, 1 in `main.rs`); all green alongside the dev's
|
||||
+33. Full workspace total after this round: **2 072 passed, 4 ignored, 0
|
||||
failed** (2 060 before QA, +12 from this pass; confirmed on two full runs).
|
||||
|
||||
**Gates.**
|
||||
- `cargo fmt --all -- --check`: clean (after `cargo fmt --all` reformatted
|
||||
two lines in the tests I added — reflowing, not a substantive change;
|
||||
re-checked clean).
|
||||
- `cargo clippy --all-targets --workspace`: zero warnings, before and after
|
||||
my additions.
|
||||
- `cargo test --workspace`: **2 072 passed, 4 ignored, 0 failed**, both
|
||||
before and after my +12 tests landed (2 060 → 2 072), 0 failed throughout.
|
||||
- `cargo build && node editors/vscode/smoke.js target/debug/lucisv-server`:
|
||||
`smoke: OK`. Confirmed `smoke.js` checks a fixed capability list
|
||||
(`documentFormattingProvider`, `definitionProvider`, `hoverProvider`,
|
||||
`semanticTokensProvider`, `documentHighlightProvider`,
|
||||
`inlineCompletionProvider` — `editors/vscode/smoke.js:140-145`) that does
|
||||
**not** include `typeHierarchyProvider`, matching the README's claim that
|
||||
this file was deliberately left untouched.
|
||||
|
||||
**1. `initialize_value()` JSON injection — verified clean, one test added.**
|
||||
`git diff 24e8eab -- crates/lucisv_server/src/main.rs` shows `capabilities()`
|
||||
and `initialize_result()` are **byte-for-byte unchanged**; the only new code
|
||||
is `initialize_value()` itself, which calls the same
|
||||
`serde_json::to_value(initialize_result())` as before and then does exactly
|
||||
one `caps.insert(...)`. Since `ServerCapabilities` has no
|
||||
`type_hierarchy_provider` field (confirmed by grep — the crate's only
|
||||
`type_hierarchy` hit is the client-side capability), the inserted key cannot
|
||||
collide with or overwrite an existing one — structurally, not just by test
|
||||
luck. Added
|
||||
`the_json_insertion_disturbs_nothing_else_in_the_initialize_result`
|
||||
(`main.rs`), which strips the one inserted key back out of
|
||||
`initialize_value()`'s output and asserts the remainder equals
|
||||
`serde_json::to_value(initialize_result())` exactly — every key, every
|
||||
value, not just the two the dev's existing test spot-checked. Passes.
|
||||
`to_value` failing: propagated via `?` all the way out of `main()`
|
||||
(`Result<(), Box<dyn Error + Sync + Send>>`), no `unwrap`/`expect` — the
|
||||
process exits with an error rather than sending a malformed or partial
|
||||
`initialize` response. `serverInfo` and other siblings: covered by the new
|
||||
test's full-object comparison. The e2e test decodes
|
||||
`capabilities["typeHierarchyProvider"] == true` off the real stdio wire
|
||||
(`tests/e2e.rs`, `the_class_hierarchy_round_trips_over_the_wire_in_both_directions`)
|
||||
— confirmed by reading it and by re-running it standalone.
|
||||
|
||||
**2. Last-byte offset — verified clean, 5 tests added.** Read
|
||||
`parse_class_extends`/`parse_scoped_name` in `vlog_parser`: `extends` is
|
||||
called with `?` from `parse_class`, so every one of "empty target"
|
||||
(`extends ;`), "EOF right after the base name", and "`pkg::` with nothing
|
||||
after the `::`" fails the *entire* `class` item's parse (it becomes
|
||||
`ItemKind::Error`) rather than producing a `ClassExtends` with an empty or
|
||||
truncated `name_span` — the defensive `if extends.name_span.is_empty()`
|
||||
guard at `type_hierarchy.rs:156-158` is therefore not reachable through any
|
||||
input the parser can produce today, but it costs nothing and is the right
|
||||
thing to keep given that guarantee lives in a different crate. Added
|
||||
`an_extends_clause_with_no_base_name_never_panics`,
|
||||
`an_extends_clause_at_eof_never_panics`,
|
||||
`a_qualified_base_with_nothing_after_the_double_colon_never_panics`,
|
||||
`a_single_character_base_name_resolves`, and
|
||||
`multibyte_text_immediately_after_the_extends_name_does_not_shift_the_offset`
|
||||
(the last puts a `🎉 日本語` block comment starting at the very next byte
|
||||
after the base name, since `name_span` is measured in bytes independent of
|
||||
what follows). All pass, none panic. `TextRange::contains` excludes `end`
|
||||
(`vlog_parser/src/span.rs`), which is exactly why `.end - 1` rather than
|
||||
`.end` is needed to land on the tail reference of `pkg::base` — confirmed by
|
||||
reading `use_scoped_unit` in `vlog_semantic/src/bind.rs`, where the tail
|
||||
reference's span ends exactly at `ext.name_span.end` and the head
|
||||
reference's ends earlier.
|
||||
|
||||
**3. The supertypes/subtypes asymmetry — pinned correctly, one gap in
|
||||
coverage found and closed.** `a_qualified_base_is_not_claimed_by_the_bare_name_it_ends_with`
|
||||
exercises exactly the shape asked for: `pkg::base` written by a real class,
|
||||
a file-scope `base`, `subtypes(base)` empty. The README's "two
|
||||
consequences" prose also claims same-named classes in different files get
|
||||
the *same* subtype list (name-only match), but this was **not previously
|
||||
pinned by a test** — added
|
||||
`subtypes_of_two_same_named_classes_in_different_files_share_one_list`,
|
||||
which declares `base` in `a.sv` and `b.sv`, has `sub` extend the bare name,
|
||||
and asserts both `base` items' `subtypes()` include `sub`. Passes, confirms
|
||||
the documented (not hidden) imprecision and gives it a regression test it
|
||||
didn't have.
|
||||
|
||||
**4. Ambiguous-base = two items — verified clean.**
|
||||
`a_class_two_files_declare_prepares_both_rather_than_guessing` already
|
||||
distinguishes the two items by file name, which is `uri` under the hood —
|
||||
no additional test needed for identity (uri+range differ, per spec
|
||||
equality).
|
||||
|
||||
**5. Census correctness — verified clean, two tests added, one real gap
|
||||
found.**
|
||||
- Substring prefilter vs. match step: added
|
||||
`a_file_containing_the_name_as_a_substring_but_no_matching_extends_is_not_a_false_positive`
|
||||
— a file with `class database;` and `class d extends database;` alongside
|
||||
`class base;`; `subtypes(base)` is empty. Passes: the match step
|
||||
(`extends_name(decl.class) != Some(item.name.as_str())`) is a full string
|
||||
compare, so the prefilter's looseness never leaks through.
|
||||
- Self-extends / cycle: re-read the existing
|
||||
`a_self_extending_class_answers_one_hop_in_both_directions_without_duplicating`
|
||||
and `a_two_class_cycle_terminates_in_both_directions` — both correctly
|
||||
assert **one** item per hop, not a duplicate or a hang. Fine as written.
|
||||
- **Finding (informational, non-blocking): generate-block classes are
|
||||
invisible to this feature, and the README's given reason is not quite
|
||||
right.** The Assumptions section says "A generate block is not descended
|
||||
into — no class lives there." Traced the parser: `parse_gen_block`
|
||||
dispatches through the same `item_or_recover`/`parse_keyword_item` path
|
||||
ordinary module items use, so `class Foo; ... endclass` written inside
|
||||
`generate`/`if`-generate/`for`-generate **does** parse into a real
|
||||
`ItemKind::Class(ClassDecl)` node — it is just nested one level inside
|
||||
`ItemKind::GenerateRegion`/`GenIf`/`GenFor`/`GenCase`, which
|
||||
`type_hierarchy::collect()` (lines ~262-274) does not recurse into.
|
||||
Confirmed empirically: added
|
||||
`a_class_declared_inside_a_generate_block_is_not_found_by_this_walk`,
|
||||
which parses a module with `generate if (1) begin class Foo; endclass end
|
||||
endgenerate` and asserts `prepare` on `Foo` answers `None` today. This
|
||||
does not corrupt anything and does not violate a hard invariant — it is a
|
||||
completeness gap for a construct that is legal per IEEE 1800
|
||||
(`package_or_generate_item_declaration` includes `class_declaration`) but
|
||||
vanishingly rare in real UVM code (0 occurrences in the 860-file corpus).
|
||||
Recommend the dev correct the README's wording from "no class lives
|
||||
there" to something like "the walk does not descend into
|
||||
`GenerateRegion`/`GenIf`/`GenFor`/`GenCase`, so a class declared inside
|
||||
one is not found — legal per the LRM, not observed in the corpus" — a
|
||||
one-line wording fix, not a redesign, so left for the dev/lead rather than
|
||||
changed here.
|
||||
|
||||
**6. Corpus test honesty — mostly confirmed, one citation could not be
|
||||
reproduced.** Ran `the_corpus_uvm_classes_answer_all_three_requests` twice:
|
||||
stable both times (860 files, 30 classes in
|
||||
`core_ibex_test_lib.sv`, 30 with an indexed base, `core_ibex_base_test` has
|
||||
10 subtypes; `subtypes` 99.7 ms / 100.9 ms on the two runs, `supertypes` 3.3
|
||||
ms both — both inside the stated debug-build budget, and roughly matching
|
||||
the dev's own "101 ms" debug figure). The **860-file** count reproduces
|
||||
exactly via an independent `find corpus -name '*.sv' -o -name '*.svh' -o
|
||||
-name '*.v' -o -name '*.vh'`. The **"0 of 309 `extends` clauses are
|
||||
qualified"** claim: the "0 qualified" half reproduces — a plain `grep -c
|
||||
'::'` over every `extends` occurrence in the corpus returns 0, confirming
|
||||
the safety-relevant part of the claim. The **309** denominator did not: an
|
||||
independent `grep -ohE '\bextends\b'` count over the same file set returns
|
||||
**270**, not 309 (checked for multi-line `extends` clauses and
|
||||
backtick-macro bases as possible explanations for undercounting — found
|
||||
zero of either, so that gap is not explained). No script computing "309" is
|
||||
checked into `tools/`. This does not change any correctness verdict (the
|
||||
load-bearing claim, zero qualified, holds under both my recount and the
|
||||
existing `a_qualified_base_is_not_claimed_by_the_bare_name_it_ends_with`
|
||||
unit test), but the specific number in two README passages
|
||||
(`docs/features/type-hierarchy/README.md:80,298` and
|
||||
`docs/features/lucisv-server/README.md:49`) is currently uncited and
|
||||
unreproducible — flagging for the dev to either recheck the corpus snapshot
|
||||
they measured against or drop the precise figure in favor of "a small
|
||||
double-digit number, all unqualified."
|
||||
|
||||
**7. CLAUDE.md compliance — verified clean.** `grep -n
|
||||
"unwrap()\|expect(\|panic!" crates/lucisv_server/src/type_hierarchy.rs`
|
||||
shows every hit inside `#[cfg(test)] mod tests` (line ≥ 326 in the
|
||||
post-QA file); none in `prepare`/`supertypes`/`subtypes` or their helpers.
|
||||
Same check on `main.rs`'s `initialize_value` — clean, uses `?`. Public
|
||||
items (`prepare`, `supertypes`, `subtypes`) all carry doc comments. README
|
||||
sections (`Goal`, `Assumptions`, `Handshakes`, `Status / TODO`, `Work log`,
|
||||
`QA log`, `Review`) each appear exactly once. `TODO.md`'s §9c item text is
|
||||
intact — checkbox flipped `[ ]` → `[x]`, original sentence unchanged, a
|
||||
`→ delivered …` paragraph appended after it rather than replacing anything.
|
||||
|
||||
**Beyond the list.**
|
||||
- Deep chain: added `a_ten_deep_chain_answers_each_hop_without_recursing`
|
||||
(`c0 extends c1 extends … extends c9`, 10 files) — walks all nine hops of
|
||||
`supertypes`, one call at a time, asserting each answers exactly the next
|
||||
link and the chain terminates. No recursion in the implementation (each
|
||||
call is `O(1)` hops by construction), and the test's own structure never
|
||||
recurses either. Passes.
|
||||
- `prepare` on the `extends` **keyword** itself: added
|
||||
`prepare_on_the_extends_keyword_itself_prepares_nothing` — offset inside
|
||||
the literal word `extends` (not the name after it) answers `None`.
|
||||
Passes, because the keyword is outside every reference span
|
||||
`definition_of`/`reference_at` would match.
|
||||
- Class name shadowed by a local variable: added
|
||||
`a_class_name_shadowed_by_a_local_variable_prepares_the_variable_use_as_nothing`
|
||||
— a class `base`, a method-local `int base;`, and a use `base = base +
|
||||
1;`; `prepare` at that use answers `None` because `definition_of`
|
||||
resolves it to the local variable's `Symbol` (kind `Var`, not `Class`),
|
||||
and `classes_at` checks `symbol.kind != SemanticKind::Class` before ever
|
||||
looking at the name. Passes — confirms the feature keys off semantic kind,
|
||||
not name matching, exactly as claimed.
|
||||
|
||||
**Files touched (QA only).** `crates/lucisv_server/src/type_hierarchy.rs`
|
||||
(+11 tests), `crates/lucisv_server/src/main.rs` (+1 test). No production
|
||||
code changed — every finding above is either a passing defensive check, a
|
||||
documentation wording gap, or an unreproducible citation, none of which
|
||||
rose to "small unambiguous fix" territory in the sense of a code change;
|
||||
the README wording fix is left for the dev per the workflow (don't touch
|
||||
files outside the stated scope of a fix that isn't mine to make).
|
||||
|
||||
## Review
|
||||
|
||||
### 2026-08-26 — lead
|
||||
|
||||
Reviewed the diff, the work log and the QA log; re-ran all gates myself
|
||||
(2072 workspace tests, 0 failed), clean. The round's hard problem was
|
||||
handled the right way twice over. First, the lsp-types gap: injecting
|
||||
the one missing key into the serialized initialize result is the honest
|
||||
minimal answer, and QA's strip-and-compare test — remove the inserted
|
||||
key, assert full object equality with the plain serialization — turns
|
||||
"disturbs nothing else" from a claim into a property. Second, the
|
||||
last-byte offset for qualified bases: the design reasoning was good and
|
||||
QA's parser trace showed the degenerate spans it guards against cannot
|
||||
even be constructed, which is the best kind of defensive code.
|
||||
|
||||
The supertypes/subtypes asymmetry is accepted as designed and now
|
||||
pinned from both directions, including the same-name/different-file
|
||||
consequence QA added a regression test for. Both QA findings were
|
||||
accepted and fixed by the lead before commit: the extends-clause
|
||||
denominator corrected to QA's reproducible 270 (in both READMEs), and
|
||||
the generate-block justification rewritten to what the parser actually
|
||||
does — the walk not recursing is a scoped choice with a pinning test,
|
||||
not a fact about where classes can live. The inheritance-edge-table
|
||||
want is filed beside the instantiation-edge request, correctly, as one
|
||||
future index round. Interface classes stay blocked on the parser and
|
||||
are pinned. Accepted as shipped.
|
||||
Reference in new issue
Block a user