Add AST-guided semantic token overrides in lucisv_server/src/tokens/instantiation.rs and cross-file overlay lookup in tokens.rs without changing the 14-type wire legend: - module/interface/extends names -> class (pkg:: prefixes -> namespace) - parameter-list # (never delays), .PARAM overrides and parameter values -> parameter - instance names (declarations, gate instances, bind lists, hierarchical uses) -> function - named port connections (.port, implicit .port, .*) -> property - port connection signals -> variable Enable editor.semanticHighlighting.enabled by default for [verilog] and [systemverilog] in editors/vscode/package.json and contribute semanticTokenScopes so every role renders with a distinct, non-white colour across VS Code themes. Add editors/vscode/semanticTokens_test.js (75 checks, passing under node --test). Rust tests/fmt/clippy deferred to Gitea CI (no cargo toolchain on this Windows host).
127 lines
7.1 KiB
Markdown
127 lines
7.1 KiB
Markdown
# instantiation-highlighting
|
|
|
|
## Goal
|
|
|
|
Give module and interface instantiations distinct, recognizable syntax colours
|
|
instead of painting every part of an instantiation with the default variable
|
|
foreground. Borrowing the roles other languages assign to constructor and
|
|
component calls (C++, Rust, TypeScript/JSX), each syntactic piece of an
|
|
instantiation takes its own semantic token class and theme-safe TextMate scope:
|
|
|
|
1. **Module / interface name** (`uart_core` in `uart_core #(...) u_uart (...)`,
|
|
`pkg::uart_core` with `pkg` as `namespace`, and lone `bind` targets) →
|
|
`class` (`entity.name.type.class`).
|
|
2. **`#` sign and parameters** (`#` before parameter port or override lists,
|
|
`.BAUD_DIV` dot + parameter-port name, `parameter`/`localparam` symbols, and
|
|
unresolved constant identifiers inside `#(...)`) → `parameter`
|
|
(`keyword.control` / `constant.language` / `variable.parameter`), sharing
|
|
one colour that stays distinct from bracket-pair-coloured `()`.
|
|
3. **Instance name** (`u_uart`, gate instances, `bind` target instances, and
|
|
uses of `SymbolKind::Instance` such as `u_uart.sig`) → `function`
|
|
(`entity.name.function`).
|
|
4. **Port name** (`.clk_i` dot + port name, implicit `.clk_i`, and wildcard
|
|
`.*` in an instance's connection list) → `property`
|
|
(`entity.name.tag.css` / `entity.other.attribute-name` /
|
|
`variable.other.property`).
|
|
5. **Port connection** (`clk` inside `.clk_i(clk)` or positional `(clk)`) →
|
|
`variable` (`support.variable` / `entity.other.attribute-name` /
|
|
`variable.other.readwrite`), keeping signal colouring consistent across the
|
|
file and non-white in themes that leave bare `variable` uncoloured.
|
|
|
|
## Assumptions
|
|
|
|
- **The 14-type wire legend is unchanged.** Every role above maps onto the
|
|
existing `SemanticTokenType` indices (`namespace`, `class`, `parameter`,
|
|
`variable`, `property`, `function`), so `token_types().len() == 14` and
|
|
`token_modifiers().len() == 1` stay untouched on the wire.
|
|
- **AST spans decide instantiation structure; single-file + overlay semantics
|
|
decide expressions.** A buffer opened before workspace indexing finishes, a
|
|
standalone file, or an instantiation of an unindexed vendor macro still
|
|
highlights its module name, `#`, `.PARAM`, instance name, and `.port` from
|
|
`Document.tree` alone. Identifiers that resolve through `Document.external`
|
|
also take their cross-file `SymbolKind` instead of degrading to `variable`.
|
|
- **Parameter `#` only, never delay `#`.** Only the `#` introducing a parameter
|
|
port list, parameter override list, or parameterized `DataType` receives
|
|
`Highlight::Parameter`; `#5` and `#(1:2:3)` net, assignment, gate, and
|
|
procedural delays remain unemitted punctuation.
|
|
- **Large-file fast path (`Document::large`) stays lexer-only.** Because the
|
|
fast path builds no AST or symbol table, AST-driven `#`, `.`, and `.*` tokens
|
|
are emitted only by the full pipeline, alongside identifier refinement.
|
|
- **Editor defaults remain user-overridable.** Setting
|
|
`editor.semanticHighlighting.enabled = true` in `configurationDefaults` for
|
|
`[verilog]` and `[systemverilog]` activates semantic tokens in themes whose
|
|
own `semanticHighlighting` flag is unset or `false`, while any explicit user
|
|
or workspace setting still wins.
|
|
|
|
## Handshakes
|
|
|
|
- **Consumed from `vlog_parser`:** `SourceFile`, `Item`/`ItemKind`, `Module`,
|
|
`Instantiation`, `Instance`, `Connections`, `Connection`, `BindDirective`,
|
|
`GateInstantiation`, `ClassDecl`, `ClassExtends`, `DataType::params`,
|
|
`ListElem`, `RawText`, `Token`, `TokenKind`, `TextRange`. No parser changes.
|
|
- **Consumed from `vlog_semantic`:** `Semantics`, `SymbolKind`,
|
|
`ExternalResolutions::definition_of`, `Definition`. No semantic changes.
|
|
- **Promised to LSP clients (`crates/lucisv_server/src/tokens.rs`):** identical
|
|
14-entry `token_types` legend and 1-entry `token_modifiers` legend; sorted,
|
|
non-overlapping single-line UTF-16 tokens; exact `full/delta` round-trip.
|
|
- **Shared with `editors/vscode/package.json`:** `contributes.semanticTokenScopes`
|
|
keys for `verilog` and `systemverilog` are a subset of `tokens::token_types()`,
|
|
checked by `editors/vscode/semanticTokens_test.js`.
|
|
|
|
## Status / TODO
|
|
|
|
- [x] Add `crates/lucisv_server/src/tokens/instantiation.rs` for AST-guided
|
|
instantiation and parameter-header highlight overrides.
|
|
- [x] Update `crates/lucisv_server/src/tokens.rs` to apply overrides, consult
|
|
`Document.external` via `definition_of`, map `SymbolKind::Instance` to
|
|
`Highlight::Function`, and add unit tests covering instantiation shapes,
|
|
delay `#` exclusion, recovered entries, and `large-file-mode` window
|
|
agreement.
|
|
- [x] Configure `editor.semanticHighlighting.enabled` and
|
|
`contributes.semanticTokenScopes` for `verilog` and `systemverilog` in
|
|
`editors/vscode/package.json`, with headless verification in
|
|
`editors/vscode/semanticTokens_test.js` (and `.vscodeignore` exclusion).
|
|
- [x] Update `docs/features/lucisv-server/README.md` and
|
|
`docs/features/large-file-mode/README.md` for the refined mapping.
|
|
|
|
## Work log
|
|
|
|
### 2026-11-17 — dev
|
|
|
|
- Audited `tokens.rs`, `editors/vscode/package.json`, and VS Code theme scope
|
|
tables across Dark Modern/Dark+, Light Modern/Light+, GitHub Dark, One Dark
|
|
Pro, Monokai, and Visual Studio Dark. Found two root causes for flat white
|
|
instantiations: (1) `tokens.rs` consulted only single-file `Semantics`
|
|
(leaving external module names, `.PARAM` overrides, `.port` names, and
|
|
`SymbolKind::Instance` all on `Highlight::Variable`, and leaving `#`
|
|
unemitted); (2) `package.json` neither defaulted
|
|
`editor.semanticHighlighting.enabled` on nor mapped semantic token types to
|
|
distinct TextMate scopes for themes where `variable`/`parameter`/`property`
|
|
collapse to white or one shared colour.
|
|
- Added `crates/lucisv_server/src/tokens/instantiation.rs` (~280 total lines)
|
|
and wired `crates/lucisv_server/src/tokens.rs` without changing the 14-type
|
|
wire legend:
|
|
- Module/interface/`extends` names → `Highlight::Class` (`pkg::` prefixes →
|
|
`Highlight::Namespace`);
|
|
- Parameter-list `#` (headers, instantiations, parameterized `DataType`s,
|
|
never delays), `.PARAM` overrides (`.` + name), and unresolved constant
|
|
identifiers inside `#(...)` → `Highlight::Parameter`;
|
|
- `SymbolKind::Instance`, `Instance.name_span`, gate instances, and `bind`
|
|
instance lists → `Highlight::Function`;
|
|
- Named port connections (`.` + name, implicit `.name`, wildcard `.*`),
|
|
including recovered unfinished entries while typing → `Highlight::Property`;
|
|
- Port connection expressions stay on `identifier_type` (`Highlight::Variable`
|
|
for signals), now backed by `ExternalResolutions::definition_of`.
|
|
- Added `editor.semanticHighlighting.enabled: true` under
|
|
`configurationDefaults` and `semanticTokenScopes` for `verilog` and
|
|
`systemverilog` in `editors/vscode/package.json`; added
|
|
`editors/vscode/semanticTokens_test.js` (75 checks, all green under `node`)
|
|
and listed it in `editors/vscode/.vscodeignore`.
|
|
- Cargo/Rust toolchain is not installed on this Windows host; Rust formatting
|
|
(`use_small_heuristics = "Max"`, ≤100 cols), clippy rules, and test
|
|
invariants were audited manually for Gitea CI execution.
|
|
|
|
## QA log
|
|
|
|
## Review
|