textDocument/inlayHint draws ghost portname:/PARAM: labels on positional connection lists and all-positional #(...) overrides, from the same plan extraction M4 uses — walked off the parse tree, so nested-call commas cannot shift positions. Range filtering runs before any definition is parsed; plans are cached per request (O(distinct modules)); every uncertainty is silent, including QA's find: an ifdef-carrying port list unions its arms in the plan, which is right for an editable skeleton and wrong for a read-only label, so such plans now hint nothing. Co-Authored-By: Claude Fable 5 <[email protected]>
refactor — a rope for Verilog/SystemVerilog (umbrella plan)
This is the umbrella plan for porting the ideas of
rope — Python's refactoring library —
to vfmt. It is the single source of truth for the refactoring roadmap: the
feature list below is the checklist the lead crosses off as milestones land
and pass QA. Each milestone is implemented as its own feature with its own
docs/features/<name>/README.md, per the repo's document-based workflow; this
file links to them.
Goal
Give vfmt the refactoring layer that ruff/Pylance users take for granted and
no Verilog tool ships well: rename that actually updates every reference
across files, module signature changes (add/remove ports) that update every
instantiation, and "module hinting" — instantiation skeletons generated from
the module's real definition, the way type hints drive completion in Python.
All of it server-first (VS Code + Vim through the one vfmt-server binary),
scoped by an explicit filelist when the user has one and by sensible
defaults when they don't, and covered by the same never-corrupt-code contract
as the formatter.
The rope → Verilog/SV mapping
What rope does for Python, and what the honest Verilog/SV equivalent is. This mapping is where the feature list comes from.
| rope feature | Verilog/SV translation |
|---|---|
| Rename (variables, functions, modules, params; optional in-comments) | Rename nets/variables, ports, parameters, modules, instances, functions/tasks, typedefs, enum members, struct fields, packages, genvars — cross-file through the workspace index |
Change signature (add/remove/reorder args, autodef defaults) |
Add/remove/reorder module ports and parameters, updating the declaration and every instantiation (named, ordered, .*), plus task/function arguments |
| Type hinting driving completion | Module hinting: the workspace index knows every module's ports/params, so instantiation is generated, completed and signature-helped from the definition |
| Extract method | Extract module: lift a selected block of logic into a new module with inferred ports (read → input, driven → output), instantiate it in place |
| Inline (function/parameter) | Inline a localparam/parameter value; inline a net with a single continuous assign into its uses |
| Move (class/function to another module) | Move a typedef/function/localparam into a package; move a module to its own file (with module-filename agreement) |
| Organize imports | Sort/dedupe import pkg::* / explicit imports; drop unused imports |
| Restructure (pattern-based rewriting) | Deliberately deferred — a pattern language is a project of its own |
Project scope (.ropeproject) |
Filelist (.f) — the EDA-native project file; fallback scope rules below |
| Undo/redo history | Deliberate non-goal: LSP WorkspaceEdit gives client-side undo, and git is the history (rope predates ubiquitous VCS; we don't) |
| Preview diffs | WorkspaceEdit is previewable in the client; CLI paths get --diff/--check |
| Static object analysis (SOA/DOA) | Already exists: vlog_semantic + WorkspaceIndex are the analysis layer; refactorings consume them, never re-implement resolution |
Feature list — what a good Verilog/SV refactoring tool supports
The lead checks items off only after the milestone's QA log is clean and the work is reviewed. Owner-priority items first (2026-08-24).
Scope / project model
- Filelist support — accept a standard EDA filelist (
-fstyle: one path per line,-fnesting,+incdir+,+define+, comments, env vars); when given, it defines exactly the set of indexed files →docs/features/filelist/README.md(M1) - Fallback scope without a filelist — workspace folders as today; when there is no workspace root (single file opened), index the files sharing the current file's directory → same feature (M1)
Rename
- Rename any symbol the semantic layer resolves — wire/reg/logic
nets and variables, ports, parameters/localparams, genvars, typedefs,
enum members, functions/tasks, modules, instances, packages, class
members — via LSP
textDocument/rename→docs/features/refactor-rename/README.md(M2) prepareRename— reject up front what can't be renamed (keywords, macro uses, unresolved names), so the editor never offers a broken rename → M2- Cross-file rename through the workspace index (module names update every instantiation; package members update every import site) → M2
- Rename safety: refuse on collision with an existing name in any affected scope, on invalid identifiers, and whenever any resulting file would no longer parse — whole-edit-or-nothing, like the formatter → M2
- Rename in comments/strings as an option (rope's
docs=True) — off by default; deferred until asked for
Module signature (change signature)
- Add a port to a module: declaration + every instantiation gains a
named connection (
.p(p)when a same-named signal is in scope at the instantiation, else.p(/* connect */)), non-ANSI decls updated too →docs/features/refactor-ports/README.md(M3) - Remove a port: dropped from the declaration and from every instantiation (named connection deleted; ordered connection turned into an explicit empty positional; refuse if the connected expression has visible side effects to preserve) → M3
- Propagate ports: diff a module's declaration against each instantiation and add the missing named connections — the code action form that needs no free-form input → M3
- Reorder ports / rename-a-port-as-signature-change (rename already covers the references; this is about connection order) — backlog
- Parameter add/remove with default propagation (rope's
autodef) — backlog - Task/function argument add/remove/reorder — backlog
Module hinting (instantiation assist)
- Instantiate-from-definition: completion on a module name at item
position expands a full skeleton — parameter overrides with their
declared defaults, every port as
.port(port)with snippet tabstops →docs/features/refactor-instantiate/README.md(M4) - Auto-connect: a port whose name matches a signal in the enclosing scope is connected to it; the rest get placeholder tabstops → M4
- Signature help inside a connection list — remaining ports, their directions and types, from the definition → M4
- Declare-missing-signals companion action (generate
logicdecls for unconnected skeleton ports) — backlog
Completion (owner request, 2026-08-24 evening)
- Keyword completion — Verilog/SV keywords offered as completion
items alongside everything else →
docs/features/completion-core/README.md(M5) - Project-wide identifier completion — names visible in the current scope (semantics-ranked first) plus identifiers used anywhere in the project scope (filelist, else workspace walk, else same-directory — M1's ladder), harvested from tokens so comments and strings never contribute candidates; no completions offered while typing inside a comment or string → M5
- Version 0.3.0 — workspace + extension bump with a CHANGELOG entry covering the whole refactoring layer (M1–M5) → M5
Templates (owner request, 2026-08-24 night)
- Statement/item template completion — context-gated snippet items
from the server (both editors):
if/if-else/else-if,casewithdefault,always_ff/always_comb/always @(...),for/while,initial, declarations (logic x;-style), each with tabstops (condition first, then body) →docs/features/completion-templates/README.md(M6) - Reconcile with the static VS Code snippets — no prefix offered twice; file-level templates (module, tb, FSM) stay static → M6
- Version 0.4.0 → M6
Structural refactorings (backlog, post-M4)
- Extract module from a selected statement range (infer ports from read/driven sets) — the flagship, hardest one
- Inline localparam/parameter value at every use
- Inline net with a single continuous assign
- Expand
.*into explicit named connections (and the reverse) - Ordered → named connections conversion
- Non-ANSI → ANSI header conversion
reg/wire→logicmodernization (pairs with thewire-reg-mixuplint rule's fix slot)- Move typedef/function/localparam into a package; update imports
- Organize imports (sort, dedupe, drop unused)
- Completion for preprocessor directive words (
`ifdef…) and suppressing self-instantiation skeletons — two LOW QA finds from M5 - Rename module together with its file (
module-filenamerule agreement; needs LSPworkspace/willRenameFilesplumbing)
LSP-parity and plumbing gaps (lead triage, 2026-08-24 night)
Found by auditing the shipped capability set against the LSP end goal (Pylance/ruff parity), the code's own "not shipped" notes, and what M1–M6 built but nothing consumes yet. Ordered by value ÷ cost:
- Cross-file find-all-references —
textDocument/referencesis still in-file only (nav.rs:50; vfmt-server README names it "not done"), yet M2's rename already collects cross-file reference sets invlog_refactor. Rename can change what references can't even list. Reuse M2's collection for the references answer — mostly wiring. - Folding ranges —
pairs.rsalready computes every begin/end/module/generate range for the rainbow;foldingRangeis the same data on a standard capability. Cheapest win on this list. - Document highlight — cursor on a symbol highlights its other
occurrences; one
references_ofcall, no new analysis. - Inlay hints for ordered connections —
u (clk, rst_n, data)shows.clk:/.rst_n:ghost labels from the instantiated module's definition (same index facts as M4); parameter names on ordered#(...)overrides too. High everyday value in RTL review. - External file-change awareness — the index rebuilds on save and
didOpen only; a
git pull, an external edit, or editing the.ffilelist itself goes unnoticed until the next save. Registerworkspace/didChangeWatchedFiles(sources + the filelist) and reindex. `includenavigation and+incdir+consumption — M1 records incdirs and nothing uses them;`include "x.svh"is not clickable and the define table stays per-file. Document links (or definition) on include lines, resolved through the filelist's incdirs, and a cross-file define-table lookup along the include graph.- Module hierarchy — "who instantiates X / what does X instantiate", as LSP callHierarchy (modules as the nodes) or a custom request the extension renders; the index already knows both directions.
- Semantic lint rules — unused-signal, undriven-net,
multiply-driven: TODO.md §7 calls this the differentiation Verible
cannot do,
vlog_semantichas existed for rounds, and no semantic rule ships yet. - CLI
-ffilelist flag — the vfmt.tomlfilelistkey and the server consume M1's parser;vfmt -f files.f(format/lint exactly the project's files) still does not exist. - Single-step macro expansion on hover — the define-table README promised it "later"; hover shows the body but expands nothing.
Already tracked elsewhere, deliberately not duplicated here: the
structural refactorings above, external waiver files, fuzzing, error-case
tests, component-level tests, CST losslessness round-trip, insta,
corpus-check CI wiring, --diff-base, salsa (TODO.md §4–6).
Assumptions
- The semantic layer is the ground truth for "what references what".
Refactorings never do textual search-and-replace; every edit comes
from a resolved reference span. Where resolution is honest about
uncertainty (
InheritedCandidate, ambiguous duplicates), the refactoring refuses rather than guesses — rope's "unsure matches" mode is not ported. - vfmt does not preprocess. A rename target whose name also appears inside
a
`definebody or an`ifdef-excluded region is reported as a warning on the response, and those occurrences are left untouched. - Verification budget: re-parsing every touched file after an edit is
affordable (files are small; the corpus parses at ~ms each). No
refactoring needs the formatter's verify pass, and none touches
verify.rs(hard invariant 4 stays untouched). - Filelist paths are resolved relative to the filelist's own directory,
the EDA convention.
+incdir+/+define+are recorded but only paths feed the index in M1. - Owner interpretation (2026-08-24): "no filelist → index files sharing the current file's path" is implemented as the no-workspace-root fallback; when the editor did open a workspace, the existing folder walk already covers (and supersedes) the sibling-directory behavior.
Handshakes
vlog_semantic: refactorings consumeSemantics(symbol_at,references_of),WorkspaceIndexandExternalResolutionsread-only. Any resolution gap found while refactoring is filed againstvlog-semantic, not patched around in the refactor crate.vfmt_server: owns only the protocol mapping (WorkspaceEdit, completion/snippet encoding, signature help); all edit computation lives in the newvlog_refactorcrate so Vim gets identical behavior.vfmt_core: filelist parsing lives here (next to config/walk), so a future CLI-fflag reuses it unchanged.vlog_formatter: not a dependency. Refactored output is edited source, not reformatted source — the user runs the formatter separately. (Keeps refactor edits minimal and reviewable, and keeps the formatter's safety net out of scope.)editors/vscode: new settingvfmt.filelist(string path, default empty) forwarded like the existingvfmt.*settings.
Milestones
Each is one feature dir, one dev agent, one QA pass, one lead review, one commit — in order:
- M1
filelist—.fparsing invfmt_core(paths,-fnesting with cycle detection,+incdir+/+define+recorded,#////comments,$VAR/${VAR}expansion; unknown+args/-flagsskipped with a warning), server scope resolution (filelist ⊃ workspace walk ⊃ current-file directory),vfmt.filelistVS Code setting + vfmt.tomlfilelistkey. - M2
refactor-rename— new cratevlog_refactorwith the edit-plan model (RefactorEdit { file → Vec<TextEdit> }, verification by re-parse), rename engine, LSPprepareRename/rename. - M3
refactor-ports— add/remove/propagate port across declaration + all instantiations, exposed as code actions +workspace/executeCommand. - M4
refactor-instantiate— instantiation completion snippets, auto-connect, signature help in connection lists. - M5
completion-core— keyword + project-wide identifier completion (token-harvested, comment/string-free), merged with M4's module snippets; version bump to 0.3.0. - M6
completion-templates— context-gated statement/item snippet templates; version 0.4.0. (0.4.1 hover-highlighting grammar and 0.4.2 color-decorator fix landed as owner-reported fixes, not milestones.) - Backlog — triaged 2026-08-24 night; next milestone is picked from the LSP-parity list (cross-file references and folding first) unless the owner reprioritizes.
Status / TODO
- Plan written; rope docs surveyed (overview: rename, extract, inline, move, change signature, restructure, organize imports, SOA/DOA, history)
- M1 filelist — done, QA clean, reviewed
- M2 refactor-rename — done, QA clean after one rework round, reviewed
- M3 refactor-ports — done, QA clean after one rework round, reviewed
- M4 refactor-instantiate — done, QA clean after one rework round, reviewed
- M5 completion-core — done, QA clean first pass, reviewed
- M6 completion-templates — done, QA clean first pass, reviewed
- Backlog triage after M6 — LSP-parity gap list added, 2026-08-24
- M7 references-nav — done, QA clean first pass, reviewed
- M8 inlay-hints — done, one QA HIGH fixed in-round, reviewed
Work log
- 2026-08-24 (lead, backlog triage): Audited the feature list against
the shipped capability set. Nine gaps added under "LSP-parity and
plumbing gaps" — the standouts: references is still in-file while rename
is cross-file (M2's machinery makes the fix cheap), folding is free data
the rainbow already computes, inlay hints for ordered connections, file
watching, and the
+incdir+s M1 records but nothing consumes. Milestone numbering fixed (duplicate "5."). Nothing shipped was found mis-checked. - 2026-08-24 (lead, end of day): M1–M4 all landed the same day, each
through the full dev → QA → rework → re-QA → lead-review loop (commits
315bbf2,33f5819,e338524, 5785fd9). Every milestone needed exactly one QA-driven rework round; the recurring theme was silent-wrongness at the preprocessor boundary (`ifdef arms, macro arguments), now handled uniformly: refuse when placement is uncertain, warn when only visibility is. Workspace suite grew 1007 → 1232 tests. Backlog triage is the next session's first task. - 2026-08-24 (lead): Umbrella plan created from the rope overview docs
and the current state of
vlog_semantic/vfmt_server/WorkspaceIndex. Key decisions: server-first (no CLI surface yet), semantic-resolution-only edits (no textual fallback), whole-edit-or-nothing verification by re-parse, filelist invfmt_core, rope's history/restructure explicitly not ported. Milestone READMEs are created by their dev agents.
QA log
(reserved for the QA agents of the milestone features; this umbrella doc itself carries no code)
Review
(reserved)