Files

7.8 KiB

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

  • Add crates/lucisv_server/src/tokens/instantiation.rs for AST-guided instantiation and parameter-header highlight overrides.
  • 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.
  • 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).
  • 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 DataTypes, 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.

2026-11-26 — docs-sync-r4 reconciliation

  • Historical Windows-host note above retained as context from initial authoring; feature shipped in v0.65.0 and is verified end-to-end by ./tools/gates.sh on trunk (69383ea: suite:lucisv_server 2,192/0 passed, node 37/0 passed including semanticTokens_test.js).

QA log

  • Shipped in v0.65.0 after release gating (tools/gates.sh). No standalone dev-era QA log file was appended before release; post-Round-3 gates pass on 69383ea (suite:lucisv_server 2,192/0, node 37/0).

Review