From 8879dd668013fb585f8eb22c804b79609b9d892c Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 19 Aug 2026 01:23:05 -0700 Subject: [PATCH] Promote LSP to a first-class goal; concretize the editor feature set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO.md §6 rewritten per owner requirement: vfmt becomes an LSP server for VS Code and Vim with Pylance/ruff-parity features for Verilog (synthesizable subset first) — semantic tokens, formatting, diagnostics, go-to-definition, references, hover with `define expansion, symbols; cross-file resolution of header imports via a workspace index. Added define-table and workspace-index items and an editor-packaging item; clarified the no-preprocessing non-goal (recording defines for hover is bookkeeping, not expansion). Co-Authored-By: Claude Fable 5 --- TODO.md | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 489d143..3a0472c 100644 --- a/TODO.md +++ b/TODO.md @@ -175,11 +175,28 @@ Adapt each: `cargo insta review` beats `UPDATE_SNAPSHOTS=1`), keeping the idempotency loop from `fixtures.rs`. -## 6. Foundations for LSP / highlighting / navigation +## 6. LSP: full editor support (a first-class goal, not a maybe) -Goal: reuse the frontend as a language-server backend (semantic -highlighting, hover, go-to-definition) the way ruff grew `ruff_server` -(and `ty`) on shared crates. Decisions that are cheap now and expensive +Goal (owner's requirement, 2026-08-19): vfmt becomes a language server +for VS Code and Vim/Neovim with feature parity, for Verilog/ +SystemVerilog, with what the Python VS Code stack (ruff + Pylance) +offers over LSP — scoped to **synthesizable Verilog first**: + +- semantic syntax highlighting (`semanticTokens`) +- formatting (document + range) and lint diagnostics as you type +- go-to-definition and find-all-references +- hover: declaration/type info, and **`` `define`` expansion on hover** + (hover a macro usage → see its value/body) +- document + workspace symbols; later: completion, rename, signature + help for module instantiation +- **cross-file resolution through header imports**: `import pkg::*;` / + `import pkg::name;` at the top of a file or in a module header must + resolve into the package's file anywhere in the workspace (workspace + index of modules/packages; `` `include`` paths resolved too) + +One server binary serves both editors (VS Code via a thin extension, +Vim/Neovim via built-in LSP config); no editor-specific logic below the +protocol layer. Foundation decisions that are cheap now and expensive later: - [ ] **Byte spans on every token and AST node.** Prerequisite for @@ -204,21 +221,40 @@ later: rules (unused-signal, undriven-net) which are the lint rules people actually want and Verible *can't* do (it's syntax-only — this is the differentiation opportunity). +- [ ] **`` `define`` table for hover expansion.** Record every + `` `define`` (name, params, body text, source span) during lexing + instead of treating it as fully opaque — no expansion during + formatting (that non-goal stands), but the table feeds hover + (`` `WIDTH`` → "defined as 8 in defs.svh:12") and later single-step + macro expansion display. Cheap to collect now that directives carry + `RawText`. +- [ ] **Workspace index for cross-file navigation.** Map module/package/ + typedef names → (file, span) across all workspace files, so header + imports (`import pkg::*;`) and instantiations resolve to definitions + in other files. Start as a full-scan-on-startup index (Verilog + codebases are small); incrementality comes with salsa later. - [ ] **New crate `vfmt_server`** (analog of `ruff_server`): LSP over stdio via `tower-lsp` or `lsp-server`. Order of capabilities: 1. `textDocument/formatting` + `rangeFormatting` (reuses §2 `--lines`), 2. publish parse/lint diagnostics, 3. `semanticTokens` for highlighting (needs only the lexer + spans), - 4. `hover` / `definition` (needs `vlog_semantic`). + 4. `hover` (decl info + define table) / `definition` / `references` + (needs `vlog_semantic` + workspace index), + 5. document/workspace symbols; then completion, rename, signature + help for instantiations. +- [ ] **Editor packaging.** A minimal VS Code extension (launch the + server, register file types) and a documented Vim/Neovim `lspconfig` + snippet. No editor-specific features beyond launching. - [ ] **Salsa-style incrementality — defer.** ruff's `ruff_db` uses salsa; don't take that dependency until hover/definition across files exists. Per-file recompute is fine at Verilog file sizes. ## 7. Deliberate non-goals (also a best practice) -- No preprocessor expansion: like Verible, operate on unpreprocessed - source, treat `` `define``/`` `ifdef`` bodies and macro calls as opaque - (current behavior — keep, and document the implications). +- No preprocessor expansion *in the formatter*: like Verible, format + unpreprocessed source and never expand macros into the output. (The + LSP's define table in §6 *records* definitions for hover display — + that is bookkeeping, not expansion, and doesn't weaken this rule.) - No option explosion: Black/ruff's lesson — every knob halves the value of a canonical style. Alignment inference (§2) is the culturally necessary exception.