Add design instantiation hierarchy queries#461
Open
nohous wants to merge 1 commit intoVHDL-LS:masterfrom
Open
Conversation
Adds a walker over the analyzer's named-entity model that, given a top
entity, produces the elaborated design instantiation tree. Component
instantiations are followed through default binding to the bound entity;
configuration instantiations and unbound components appear as annotated
leaves; cycles are detected and truncated. A second helper enumerates
every entity in the design ranked as a top-level candidate, with roots
(no incoming instantiations) sorted deepest-first - useful for picking a
top in a UI without typing the name blind.
vhdl_lang
- New module `hierarchy` with `compute_design_hierarchy`,
`list_top_candidates`, `DesignHierarchyNode`, `HierarchyKind`,
`HierarchyError`, `TopCandidate`. When an entity has multiple
architectures the one named `rtl` is preferred, otherwise the
alphabetically first architecture, with a note recorded on the node.
- `Project::design_hierarchy`, `design_hierarchy_candidates`, and
`library_names` thin wrappers.
- CLI flags `--hierarchy [LIB.]ENTITY`, `--hierarchy-format text|json`,
`--hierarchy-quiet`. JSON output via serde. A bare entity name
resolves against the project's libraries: prefers `work`, otherwise
the single user library, otherwise lists known libraries and exits
non-zero. `serde` and `serde_json` are now direct dependencies.
vhdl_ls
- New custom requests `vhdl/designHierarchy` and
`vhdl/designHierarchyCandidates`. Responses are LSP-shaped trees /
arrays with `Location`s for the instantiation site and the entity
declaration. `kind` is one of `top`, `entity`, `boundComponent`,
`unboundComponent`, `configuration`, `unresolved`. Unknown library
or entity yields `InvalidRequest` with a message listing the known
names.
Tests
- Nine new tests under `analysis::tests::design_hierarchy` covering
three-level entity nesting, component default-binding, unbound
component, multi-architecture preference for `rtl` and alphabetical
fallback, cycle protection, error messages, and candidate ranking.
Documentation
- README "Design hierarchy" section documenting both LSP requests
(params, response shape, error semantics) and the CLI counterpart.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
Contributor
|
Hi! Thanks for tackling this issue! I think this is a feature many (including myself) will appreciate. I have a couple of comments though.
|
Author
|
Noted and thanks for the pointers - I just wanted to share this early (so maybe sorry for making it a PR) - so you can build and see it work and give your feedback - which you have did. I will go through it, make it more consistent with your intents and get back to you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a walker over the analyzer's named-entity model that, given a top entity, produces the elaborated design instantiation tree, plus a candidate enumerator for "pick a top" UIs. Both are exposed as a CLI flag on
vhdl_langand as two custom LSP requests onvhdl_ls.Companion PR for the official VS Code extension: VHDL-LS/rust_hdl_vscode (will link once opened).
Why
Hardware engineers routinely need a hierarchical overview of their design (top entity -> instantiated children, recursively). The analyzer already binds instantiations and resolves component default-binding; this PR turns that information into a public, well-typed tree and surfaces it via the LSP so editors can render a hierarchy view. A blank "type the entity name" prompt is unhelpful on a fresh project; the candidates query lets a UI pre-populate the picker with real top candidates first.
What's added
vhdl_langhierarchyexposing:compute_design_hierarchy(root, library, entity) -> Result<DesignHierarchyNode, HierarchyError>list_top_candidates(root) -> Vec<TopCandidate>DesignHierarchyNode,HierarchyKind,HierarchyError,TopCandidateProject::design_hierarchy,design_hierarchy_candidates,library_namesthin wrappers--hierarchy [LIB.]ENTITY,--hierarchy-format text|json,--hierarchy-quiet. JSON output is rendered viaserde_json::to_string_pretty(new direct deps:serde,serde_json).work, otherwise the single user library, otherwise lists known libraries and exits non-zero.vhdl_lsTwo custom JSON-RPC requests (documented in README):
vhdl/designHierarchyCandidates->{ candidates: [{ library, entity, depth, instanceCount, isRoot, entityLocation }] }. Sorted roots-first / deepest-first.vhdl/designHierarchywith params{ library, entity }-> tree of{ label, entity, architecture, kind, instanceLocation, entityLocation, notes, children }.kindis one oftop,entity,boundComponent,unboundComponent,configuration,unresolved. Unknown library or entity yieldsInvalidRequestwith a message listing the known names.Behaviour notes
rtlis preferred; otherwise the alphabetically first architecture, with a note recorded on the node.Tests
Nine new tests under
analysis::tests::design_hierarchycovering: three-level entity nesting, component default-binding, unbound component, multi-architecture preference forrtl, alphabetical fallback, cycle protection, error messages with known-name lists, and candidate ranking. Full suite still passes (1417 + 9 = 1426 tests).Test plan
cargo test --release -p vhdl_langpasses (1417 prior + 9 new)vhdl/designHierarchyandvhdl/designHierarchyCandidatesround-trip end-to-end against a stdio-launchedvhdl_ls--hierarchy gev(no library prefix) on a project with multiple user libraries errors out and lists them; the same on a project with a single user library auto-resolves correctly