Inlay hints M8: port and parameter names on ordered lists

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]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-08-24 23:24:01 -07:00
1 parent 3c55783e09
commit fa38fd9dec
8 files changed
+1425 -15

No files matched your search

+103
View File
@@ -1596,3 +1596,106 @@ fn cross_file_references_folding_and_highlights_round_trip_over_the_wire() {
let _ = std::fs::remove_dir_all(&dir);
}
const INLAY_SUB: &str = "\
module inlay_sub #(
parameter int WIDTH = 8,
parameter int DEPTH = 16
) (
input logic clk,
input logic rst_n,
input logic [WIDTH-1:0] data
);
endmodule
";
/// Line 1 is ordered — three ghost labels and two on the overrides. Line 2 is
/// named, so it gets none. Line 3 instantiates a module nothing declares.
const INLAY_TOP: &str = "\
module inlay_top;
inlay_sub #(4, 8) u1 (clk, rst_n, data);
inlay_sub u2 (.clk(clk), .rst_n(rst_n), .data(data));
nope u3 (a, b, c);
endmodule
";
#[test]
fn inlay_hints_round_trip_over_the_wire() {
// What only an e2e test can check: that the capability is advertised in
// the shape a client reads, and that a range-scoped request comes back
// with the exact labels at the exact positions the editor draws at.
let dir = temp_dir("inlay");
std::fs::write(dir.join("inlay_sub.sv"), INLAY_SUB).expect("write");
let top = dir.join("inlay_top.sv");
std::fs::write(&top, INLAY_TOP).expect("write");
let root = format!("file://{}", dir.display());
let uri = format!("file://{}", top.display());
let session = [
frame(&format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"initialize","params":{{"processId":null,"rootUri":"{root}","capabilities":{{}}}}}}"#
)),
frame(r#"{"jsonrpc":"2.0","method":"initialized","params":{}}"#),
frame(&format!(
r#"{{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{{"textDocument":{{"uri":"{uri}","languageId":"systemverilog","version":1,"text":{}}}}}}}"#,
serde_json::to_string(INLAY_TOP).expect("json")
)),
// The whole file.
frame(&format!(
r#"{{"jsonrpc":"2.0","id":2,"method":"textDocument/inlayHint","params":{{"textDocument":{{"uri":"{uri}"}},"range":{{"start":{{"line":0,"character":0}},"end":{{"line":4,"character":0}}}}}}}}"#
)),
// Only the named line, which has nothing to hint.
frame(&format!(
r#"{{"jsonrpc":"2.0","id":3,"method":"textDocument/inlayHint","params":{{"textDocument":{{"uri":"{uri}"}},"range":{{"start":{{"line":2,"character":0}},"end":{{"line":2,"character":60}}}}}}}}"#
)),
frame(r#"{"jsonrpc":"2.0","id":9,"method":"shutdown","params":null}"#),
frame(r#"{"jsonrpc":"2.0","method":"exit","params":null}"#),
]
.concat();
let messages = talk(&session);
let initialize = messages.iter().find(|m| m["id"] == 1).expect("initialize response");
let provider = &initialize["result"]["capabilities"]["inlayHintProvider"];
assert!(provider.is_object(), "options, not a bare `true`: {provider:#?}");
assert!(provider.get("resolveProvider").is_none(), "every hint is complete: {provider:#?}");
let response = |id: u32| -> &serde_json::Value {
messages.iter().find(|m| m["id"] == id).unwrap_or_else(|| panic!("no {id}: {messages:#?}"))
};
let hints: Vec<(u64, u64, String, u64, bool)> = response(2)["result"]
.as_array()
.expect("a hint list")
.iter()
.map(|h| {
(
h["position"]["line"].as_u64().expect("line"),
h["position"]["character"].as_u64().expect("character"),
h["label"].as_str().expect("a string label").to_string(),
h["kind"].as_u64().expect("kind"),
h["paddingRight"].as_bool().expect("paddingRight"),
)
})
.collect();
// ` inlay_sub #(4, 8) u1 (clk, rst_n, data);`
// column 14 is the `4`, 17 the `8`, 24 `clk`, 29 `rst_n`, 36 `data`.
assert_eq!(
hints,
vec![
(1, 14, "WIDTH:".to_string(), 2, true),
(1, 17, "DEPTH:".to_string(), 2, true),
(1, 24, "clk:".to_string(), 2, true),
(1, 29, "rst_n:".to_string(), 2, true),
(1, 36, "data:".to_string(), 2, true),
],
"the ordered line only — the named one and the unknown module say nothing"
);
assert_eq!(
response(3)["result"].as_array().expect("a hint list").len(),
0,
"a named connection list has nothing to add"
);
let _ = std::fs::remove_dir_all(&dir);
}