Fix inlay hint port targets#133
Closed
roife wants to merge 2 commits into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines SystemVerilog port-related IDE features so inlay hints, semantic tokens, and go-to-definition resolve and anchor to the correct port “name” locations (especially for named/ordered connections and ANSI vs non-ANSI ports), and adds targeted regression tests.
Changes:
- Update semantic token collection to use
name_range()for named port connections and add a regression test. - Rework inlay hint port-connection resolution to align hint targets/positions with the displayed port (including direction indicators) and add extensive tests.
- Add scope/query helpers to resolve non-ANSI port declaration IDs by name, plus a new
check_or_throw!utility macro used in the refactor.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/utils/src/utry.rs | Adds check_or_throw! macro to simplify early-exit control flow in Option-returning try {} blocks. |
| crates/ide/src/semantic_tokens.rs | Switches named port-connection token ranges to name_range() and adds a regression test. |
| crates/ide/src/inlay_hint.rs | Refactors port hint collection/resolution and adds many new port-hint behavior tests. |
| crates/ide/src/definitions.rs | Adds a go-to-definition regression test for named port connection names resolving to the target port. |
| crates/hir/src/scope.rs | Adds ModuleScope::non_ansi_port_decl_id_by_name helper for resolving non-ANSI port decl IDs by name. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+317
to
+324
| let label = if should_skip(module.get(*expr), name) { | ||
| arrow.to_string() | ||
| } else { | ||
| format!("{name} {arrow}") | ||
| }; | ||
| let edit = edits_for_conn(name, conn_src); | ||
| let position = src_map.get(*expr).map_or_else(|| conn_start, |src| src.range().start()); | ||
| collector.collect_hint(conn_src, Some(target_src), Some(position), label, edit); |
Comment on lines
+284
to
+288
| pub fn non_ansi_port_decl_id_by_name( | ||
| &self, | ||
| module: &Module, | ||
| name: &SmolStr, | ||
| ) -> Option<PortDeclId> { |
Comment on lines
+311
to
+315
| PortConn::Empty => { | ||
| let label = format!("{name} {arrow}"); | ||
| let edit = edits_for_conn(name, conn_src); | ||
| collector.collect_hint(conn_src, Some(target_src), None, label, edit); | ||
| } |
| #[test] | ||
| fn named_port_hint_is_clickable() { | ||
| let text = "module child(output out); endmodule\n\ | ||
| module top; logic instr_addr_o; child u(instr_addr_o); endmodule\n"; |
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
Verification