From 51b975bf68deb2d3617b72fb4f7a736ce1e7092a Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Mon, 19 Oct 2026 05:48:40 -0700 Subject: [PATCH] =?UTF-8?q?TODO=20=C2=A765.2=20closed=20by=20ruling:=20LSP?= =?UTF-8?q?=20references=20are=20scope-relative=20by=20design;=20tests=20p?= =?UTF-8?q?in=20both=20scopes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause (lane A): not the fan-out. The default index scope (`folder`, depth 2) opened from hw/ip/aes/dv/tb/tb.sv indexes hw/ip/aes only, so the three *_pd_main.sv tops are never walked; with index.scope "workspace" the LSP answers 14/12, equal to the whole-set engine. Ruled out: the 1 MiB cap, autogen/ignore rules, the multi-line instantiation. The owner kept the design; the index.scope setting now says a rename of a module instantiated outside the scope leaves those sites unchanged. Tests: server/tests/references_scope.rs (3: the LSP equals the engine over the same file set in both scopes, a module rename reaches the top under `workspace`), tests/opentitan_references.rs (2, ignored: 14/12 workspace, 11/9 default). lucisv_server 1 865 passed, 0 failed; node 8/8. docs/features/references-fanout-pd-main. Co-Authored-By: Claude Opus 5.5 --- TODO.md | 14 +- crates/lucisv_server/src/server/tests/mod.rs | 1 + .../src/server/tests/references_scope.rs | 170 +++++++++++ .../tests/opentitan_references.rs | 283 ++++++++++++++++++ .../references-fanout-pd-main/README.md | 140 +++++++++ editors/vscode/package.json | 2 +- 6 files changed, 602 insertions(+), 8 deletions(-) create mode 100644 crates/lucisv_server/src/server/tests/references_scope.rs create mode 100644 crates/lucisv_server/tests/opentitan_references.rs create mode 100644 docs/features/references-fanout-pd-main/README.md diff --git a/TODO.md b/TODO.md index 6d2c3f8..0d629bd 100644 --- a/TODO.md +++ b/TODO.md @@ -7010,18 +7010,18 @@ top-level instantiations in settle, so not an indexing race. Feature README `docs/features/references-fanout-pd-main`. -- [ ] root cause named (the fan-out/scope selection in `lucisv_server` — +- [x] root cause named (the fan-out/scope selection in `lucisv_server` — `module_select`, `state/` scope widening, or the index's instantiation facts for those three files; they are large generated files, check the 1 MiB cap and the word census) -- [ ] the LSP answer equals the whole-set engine's for the module name and +- [x] ~~the LSP answer equals the whole-set engine's for the module name and for a port of it, from the declaration and from a use; a regression - test with a fixture that reproduces the cause (not only opentitan) -- [ ] an opentitan test (ignored by default, like `tests/opentitan.rs`) + test with a fixture that reproduces the cause (not only opentitan)~~ — **closed by the owner's ruling 2026-10-19: scope-relative by design.** The LSP answer equals the engine over the same file set (pinned for both scopes in `server/tests/references_scope.rs`); the default `folder` scope does not reach the three tops, `workspace` does (14/12). +- [x] an opentitan test (ignored by default, like `tests/opentitan.rs`) pinning the 14 and 12 -- [ ] QA: the same comparison for five other modules instantiated from a +- [x] ~~QA: the same comparison for five other modules instantiated from a `*_pd_main.sv` top, and for `rename`'s fan-out (does rename see the - three sites?) + three sites?)~~ — not run: no production code changed under the ruling ### 65.3 The combined test command stalls entering the doc-tests @@ -7104,7 +7104,7 @@ new test files under `crates/lucisv_server/src/server/tests/`, a new ignored-by-default `crates/lucisv_server/tests/opentitan_references.rs`, `docs/features/references-fanout-pd-main/README.md`. -- [ ] §65.2's checklist above +- [x] §65.2's checklist above (closed by ruling: scope-relative by design) **Lane B — §65.3 gate script** (Opus dev → QA → lead), files: `tools/gates.sh` (new), `tools/guard.sh` (only if the cause is there), diff --git a/crates/lucisv_server/src/server/tests/mod.rs b/crates/lucisv_server/src/server/tests/mod.rs index 1a7d3cf..93653db 100644 --- a/crates/lucisv_server/src/server/tests/mod.rs +++ b/crates/lucisv_server/src/server/tests/mod.rs @@ -61,6 +61,7 @@ mod progress; mod pull_diagnostics; mod qa_generate_label; mod qa_rename_implicit; +mod references_scope; mod rename_generate_label; mod rename_implicit; mod requests; diff --git a/crates/lucisv_server/src/server/tests/references_scope.rs b/crates/lucisv_server/src/server/tests/references_scope.rs new file mode 100644 index 0000000..b438d04 --- /dev/null +++ b/crates/lucisv_server/src/server/tests/references_scope.rs @@ -0,0 +1,170 @@ +//! TODO §65.2 over the wire: `references` from a testbench answers within +//! the active index scope, and within an equal file set it answers exactly +//! what the whole-set engine (`vlog_refactor::find_references`) answers. +//! `docs/features/references-fanout-pd-main/README.md`. +//! +//! The fixture is opentitan's shape in miniature: an IP block with `rtl/` +//! and `dv/tb/`, and a generated top two directories away that instantiates +//! the block with a multi-line `blk #( … ) u_blk (`. + +use std::path::Path; + +use super::*; + +const BLK: &str = "module blk #(\n parameter int W = 1\n) (\n input logic clk_i,\n input logic rst_ni\n);\nendmodule\n"; +const TB: &str = "module tb;\n logic clk, rst_n;\n blk #(\n .W ( 2 )\n ) dut (\n .clk_i ( clk ),\n .rst_ni ( rst_n )\n );\nendmodule\n"; +const PD_MAIN: &str = "module top_pd_main (\n input logic clk_main_i,\n input logic rst_main_ni\n);\n blk #(\n .W ( 4 )\n ) u_blk (\n // Clock and reset connections\n .clk_i ( clk_main_i ),\n .rst_ni ( rst_main_ni )\n );\nendmodule\n"; + +/// The three files, at their opentitan-shaped paths. +fn fixture(tag: &str) -> Tree { + let tree = Tree::new(tag); + tree.write("ip/blk/rtl/blk.sv", BLK); + tree.write("ip/blk/dv/tb/tb.sv", TB); + tree.write("top/rtl/autogen/top_pd_main.sv", PD_MAIN); + tree +} + +/// `(path relative to the root, line)` of every location in an answer. +fn answered(root: &Path, found: &Value) -> Vec<(String, u64)> { + let mut out: Vec<(String, u64)> = found + .as_array() + .expect("an array") + .iter() + .map(|l| { + let uri = l["uri"].as_str().unwrap_or("?"); + let path = + crate::uri::uri_to_path(&Uri::from_str(uri).expect("a uri")).expect("a path"); + let rel = path.strip_prefix(root).unwrap_or(&path).display().to_string(); + (rel, l["range"]["start"]["line"].as_u64().unwrap_or(0)) + }) + .collect(); + out.sort(); + out +} + +/// What the whole-set engine answers over `files`, as [`answered`] spells it. +fn engine( + root: &Path, + files: &[(PathBuf, String)], + file: &Path, + offset: u32, +) -> Vec<(String, u64)> { + let found = + vlog_refactor::find_references(files, file, offset, true).expect("the engine answers"); + let mut out: Vec<(String, u64)> = found + .into_iter() + .map(|(path, range)| { + let text = &files.iter().find(|(p, _)| *p == path).expect("a read file").1; + let line = text[..range.start as usize].matches('\n').count() as u64; + let rel = path.strip_prefix(root).unwrap_or(&path).display().to_string(); + (rel, line) + }) + .collect(); + out.sort(); + out +} + +/// Every file under the tree — the set the MCP's `references` hands the engine. +fn every_file(tree: &Tree) -> Vec<(PathBuf, String)> { + ["ip/blk/rtl/blk.sv", "ip/blk/dv/tb/tb.sv", "top/rtl/autogen/top_pd_main.sv"] + .iter() + .map(|rel| { + let path = tree.path.join(rel); + let text = std::fs::read_to_string(&path).expect("read"); + (path, text) + }) + .collect() +} + +/// A references request at the first `needle` on line `line` of `text`, and +/// the byte offset the engine is asked at. +fn at(uri: &Uri, text: &str, line: usize, needle: &str) -> (Value, u32) { + let row = text.lines().nth(line).expect("the line"); + let character = row.find(needle).expect("the needle on that line"); + let before: usize = text.lines().take(line).map(|l| l.len() + 1).sum(); + let params = serde_json::json!({ + "textDocument": { "uri": uri }, + "position": { "line": line, "character": character }, + "context": { "includeDeclaration": true }, + }); + (params, (before + character) as u32) +} + +/// The four positions the §65.2 checklist names: the module name and one of +/// its ports, each from its declaration and from a use. +fn positions(tree: &Tree) -> [(PathBuf, &'static str, usize, &'static str); 4] { + let blk = tree.path.join("ip/blk/rtl/blk.sv"); + let tb = tree.path.join("ip/blk/dv/tb/tb.sv"); + [ + (blk.clone(), BLK, 0, "blk"), + (tb.clone(), TB, 2, "blk"), + (blk, BLK, 3, "clk_i"), + (tb, TB, 5, "clk_i"), + ] +} + +#[test] +fn over_the_whole_workspace_references_equal_the_whole_set_engine() { + let tree = fixture("refscope_wide"); + let mut session = Session::wide(vec![tree.path.clone()], false); + let all = every_file(&tree); + for (path, text, line, needle) in positions(&tree) { + let uri = session.open(&path, text); + let (params, offset) = at(&uri, text, line, needle); + let lsp = answered(&tree.path, &session.result(References::METHOD, params)); + let whole = engine(&tree.path, &all, &path, offset); + assert_eq!(lsp, whole, "{needle} at {}:{line}", path.display()); + assert!( + lsp.iter().any(|(file, _)| file.ends_with("top_pd_main.sv")), + "the generated top is listed: {lsp:?}" + ); + } +} + +/// The cause, pinned: under the shipped folder scope a testbench in +/// `ip/blk/dv/tb/` raises to `ip/blk/`, the generated top is not in the +/// index, and `references` answers what the engine answers over the scope — +/// not over every file. Opening the top widens the scope, and the answer +/// becomes the whole set's. +#[test] +fn under_the_folder_scope_references_equal_the_engine_over_the_scope() { + let tree = fixture("refscope_folder"); + let mut session = Session::new(vec![tree.path.clone()], false); + let top = tree.path.join("top/rtl/autogen/top_pd_main.sv"); + for (path, text, line, needle) in positions(&tree) { + let uri = session.open(&path, text); + let in_index = session.server.workspace.index().files().contains(&top); + assert!(!in_index, "the top is outside the folder scope"); + let (params, offset) = at(&uri, text, line, needle); + let lsp = answered(&tree.path, &session.result(References::METHOD, params)); + let scoped = engine(&tree.path, &session.server.workspace.sources(), &path, offset); + assert_eq!(lsp, scoped, "{needle} at {}:{line}", path.display()); + assert!(!lsp.iter().any(|(file, _)| file.ends_with("top_pd_main.sv")), "{lsp:?}"); + } + + let _ = session.open(&top, PD_MAIN); + let all = every_file(&tree); + for (path, text, line, needle) in positions(&tree) { + let uri = path_to_uri(&path).expect("uri"); + let (params, offset) = at(&uri, text, line, needle); + let lsp = answered(&tree.path, &session.result(References::METHOD, params)); + assert_eq!(lsp, engine(&tree.path, &all, &path, offset), "{needle}, widened"); + } +} + +/// `rename`'s fan-out has no gap of its own: over the whole workspace a +/// module rename from the testbench edits the generated top too. +#[test] +fn over_the_whole_workspace_a_module_rename_edits_the_generated_top() { + let tree = fixture("refscope_rename"); + let mut session = Session::wide(vec![tree.path.clone()], false); + let tb = tree.path.join("ip/blk/dv/tb/tb.sv"); + let uri = session.open(&tb, TB); + let (mut params, _) = at(&uri, TB, 2, "blk"); + params["newName"] = serde_json::json!("blk2"); + let answer = session.request(Rename::METHOD, params).response_result.expect("renames"); + let changes = answer["changes"].as_object().expect("changes"); + let top = path_to_uri(&tree.path.join("top/rtl/autogen/top_pd_main.sv")).expect("uri"); + assert_eq!(changes.get(top.as_str()).and_then(Value::as_array).map_or(0, Vec::len), 1); + assert_eq!(changes.len(), 3, "blk.sv, tb.sv and the top: {answer:#}"); +} diff --git a/crates/lucisv_server/tests/opentitan_references.rs b/crates/lucisv_server/tests/opentitan_references.rs new file mode 100644 index 0000000..8a196c8 --- /dev/null +++ b/crates/lucisv_server/tests/opentitan_references.rs @@ -0,0 +1,283 @@ +//! TODO §65.2 on a real checkout: `textDocument/references` at the `aes` +//! instantiation in `hw/ip/aes/dv/tb/tb.sv` and at its `.clk_i` connection. +//! +//! Over the whole workspace (`lucisv.index.scope: "workspace"`) the server +//! answers what the whole-set engine answers — 14 and 12, the three generated +//! `*_pd_main.sv` tops included. Under the shipped folder scope it answers 11 +//! and 9: the testbench's folder raises two levels to `hw/ip/aes`, and the +//! tops are not in the index. Both are pinned, because the difference *is* +//! the finding (`docs/features/references-fanout-pd-main/README.md`). +//! +//! `#[ignore]`: it needs the checkout, which it only reads. Run with +//! `LUCISV_OPENTITAN=/path/to/opentitan tools/guard.sh -- cargo test -p +//! lucisv_server --test opentitan_references -- --ignored --nocapture`; +//! without the variable it looks in `~/.cache/lucisv-eval/ot`, and it skips +//! (passing, with a line on stderr) when neither holds the testbench. + +use std::io::{BufRead, BufReader, Write}; +use std::path::{Path, PathBuf}; +use std::process::{Child, ChildStdin, Command, Stdio}; +use std::sync::mpsc::{self, Receiver}; +use std::time::{Duration, Instant}; + +use serde_json::{json, Value}; + +/// The testbench, relative to the checkout. +const TB: &str = "hw/ip/aes/dv/tb/tb.sv"; + +/// The three generated tops the folder scope does not reach. +const TOPS: [&str; 3] = [ + "hw/top_darjeeling/rtl/autogen/darjeeling_pd_main.sv", + "hw/top_earlgrey/rtl/autogen/earlgrey_pd_main.sv", + "hw/top_englishbreakfast/rtl/autogen/englishbreakfast_pd_main.sv", +]; + +/// The checkout: `LUCISV_OPENTITAN`, else the eval clone; `None` when the +/// testbench is not there. +fn checkout() -> Option { + let root = std::env::var_os("LUCISV_OPENTITAN").map(PathBuf::from).or_else(|| { + std::env::var_os("HOME").map(|home| PathBuf::from(home).join(".cache/lucisv-eval/ot")) + })?; + root.join(TB).is_file().then_some(root) +} + +/// One language server over `root/hw`, with `settings` as its `lucisv` +/// section. +struct Server { + child: Child, + stdin: ChildStdin, + inbox: Receiver, + settings: Value, + next_id: i64, +} + +impl Server { + fn over(hw: &Path, settings: Value) -> Server { + // The persistent cache falls back to the OS cache directory; point it + // somewhere a test may write, as `tests/e2e.rs` does. + let sandbox = + std::env::temp_dir().join(format!("lucisv_server_ot_refs_{}", std::process::id())); + let mut child = Command::new(env!("CARGO_BIN_EXE_lucisv-server")) + .env("HOME", &sandbox) + .env("XDG_CACHE_HOME", sandbox.join("cache")) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .spawn() + .expect("the server binary starts"); + let stdin = child.stdin.take().expect("stdin"); + let stdout = BufReader::new(child.stdout.take().expect("stdout")); + let (sender, inbox) = mpsc::channel(); + std::thread::spawn(move || { + let mut stdout = stdout; + while let Some(message) = read_message(&mut stdout) { + if sender.send(message).is_err() { + break; + } + } + }); + let mut server = Server { child, stdin, inbox, settings, next_id: 0 }; + let root = uri(hw); + server.request( + "initialize", + json!({ + "processId": null, "rootUri": root, + "workspaceFolders": [{ "uri": root, "name": "hw" }], + "capabilities": { + "window": { "workDoneProgress": true }, + "workspace": { "configuration": true }, + }, + }), + ); + server.notify("initialized", json!({})); + let lucisv = server.settings.clone(); + server.notify( + "workspace/didChangeConfiguration", + json!({ "settings": { "lucisv": lucisv } }), + ); + server + } + + fn send(&mut self, message: Value) { + let payload = message.to_string(); + write!(self.stdin, "Content-Length: {}\r\n\r\n{payload}", payload.len()).expect("write"); + self.stdin.flush().expect("flush"); + } + + fn notify(&mut self, method: &str, params: Value) { + self.send(json!({ "jsonrpc": "2.0", "method": method, "params": params })); + } + + /// The next message within `wait`, with every request the server makes + /// of us answered on the way (`workspace/configuration` with our + /// settings, everything else with `null`). + fn next(&mut self, wait: Duration) -> Option { + let message = self.inbox.recv_timeout(wait).ok()?; + if let (Some(id), Some(method)) = (message.get("id"), message["method"].as_str()) { + let result = if method == "workspace/configuration" { + let items = message["params"]["items"].as_array().map_or(1, Vec::len); + Value::Array(vec![self.settings.clone(); items]) + } else { + Value::Null + }; + let id = id.clone(); + self.send(json!({ "jsonrpc": "2.0", "id": id, "result": result })); + } + Some(message) + } + + fn request(&mut self, method: &str, params: Value) -> Value { + self.next_id += 1; + let id = self.next_id; + self.send(json!({ "jsonrpc": "2.0", "id": id, "method": method, "params": params })); + let deadline = Instant::now() + Duration::from_secs(600); + while Instant::now() < deadline { + let Some(message) = self.next(Duration::from_secs(1)) else { continue }; + if message["id"] == id && message.get("method").is_none() { + return message["result"].clone(); + } + } + panic!("{method} was not answered"); + } + + /// Open the testbench and wait until every scan has ended: at least one + /// progress `end` after the open, then five quiet seconds with no bar in + /// flight (the startup scan, the settings push and the open's widen may + /// each run one). + fn open_and_settle(&mut self, path: &Path) { + let text = std::fs::read_to_string(path).expect("read the testbench"); + self.notify( + "textDocument/didOpen", + json!({ "textDocument": { + "uri": uri(path), "languageId": "systemverilog", "version": 1, "text": text, + }}), + ); + let deadline = Instant::now() + Duration::from_secs(600); + let (mut ended, mut in_flight, mut quiet_since) = (false, 0i32, Instant::now()); + while Instant::now() < deadline { + if ended && in_flight <= 0 && quiet_since.elapsed() > Duration::from_secs(5) { + return; + } + let Some(message) = self.next(Duration::from_secs(1)) else { continue }; + if message["method"] != "$/progress" { + continue; + } + quiet_since = Instant::now(); + match message["params"]["value"]["kind"].as_str() { + Some("begin") => in_flight += 1, + Some("end") => { + in_flight -= 1; + ended = true; + } + _ => {} + } + } + panic!("the scan never settled"); + } + + /// `references` at the first `needle` on 1-based `line` of `path`, as + /// `file:line` relative to `root`, sorted. + fn references(&mut self, root: &Path, path: &Path, line: usize, needle: &str) -> Vec { + let text = std::fs::read_to_string(path).expect("read"); + let row = text.lines().nth(line - 1).expect("the line"); + let character = row.find(needle).expect("the needle on that line"); + let found = self.request( + "textDocument/references", + json!({ + "textDocument": { "uri": uri(path) }, + "position": { "line": line - 1, "character": character }, + "context": { "includeDeclaration": true }, + }), + ); + let prefix = format!("{}/", uri(root)); + let mut out: Vec = found + .as_array() + .expect("an array") + .iter() + .map(|l| { + let file = l["uri"].as_str().unwrap_or("?").replace(&prefix, ""); + format!("{file}:{}", l["range"]["start"]["line"].as_u64().unwrap_or(0) + 1) + }) + .collect(); + out.sort(); + out + } +} + +impl Drop for Server { + fn drop(&mut self) { + let _ = self.child.kill(); + let _ = self.child.wait(); + } +} + +fn uri(path: &Path) -> String { + format!("file://{}", path.display()) +} + +/// One framed message, or `None` when the stream ends. +fn read_message(input: &mut impl BufRead) -> Option { + let mut length = None; + loop { + let mut line = String::new(); + if input.read_line(&mut line).unwrap_or(0) == 0 { + return None; + } + let trimmed = line.trim_end_matches(['\r', '\n']); + if trimmed.is_empty() { + break; + } + if let Some(value) = trimmed.strip_prefix("Content-Length: ") { + length = value.parse::().ok(); + } + } + let mut body = vec![0u8; length?]; + input.read_exact(&mut body).ok()?; + serde_json::from_slice(&body).ok() +} + +/// The `aes` and `.clk_i` answers of one server over `root/hw`. +fn answers(root: &Path, settings: Value) -> (Vec, Vec) { + let hw = root.join("hw"); + let tb = root.join(TB); + let mut server = Server::over(&hw, settings); + server.open_and_settle(&tb); + let module = server.references(root, &tb, 45, "aes"); + let port = server.references(root, &tb, 50, "clk_i"); + println!("aes: {} {module:#?}\n.clk_i: {} {port:#?}", module.len(), port.len()); + (module, port) +} + +fn names_a_top(found: &[String], top: &str) -> bool { + found.iter().any(|hit| hit.starts_with(&format!("{top}:"))) +} + +#[test] +#[ignore = "needs an opentitan checkout (LUCISV_OPENTITAN or ~/.cache/lucisv-eval/ot)"] +fn over_the_whole_workspace_references_list_the_three_generated_tops() { + let Some(root) = checkout() else { + eprintln!("skipped: no opentitan checkout holding {TB}"); + return; + }; + let (module, port) = answers(&root, json!({ "index": { "scope": "workspace" } })); + assert_eq!(module.len(), 14, "aes: {module:#?}"); + assert_eq!(port.len(), 12, ".clk_i: {port:#?}"); + for top in TOPS { + assert!(names_a_top(&module, top), "aes misses {top}"); + assert!(names_a_top(&port, top), ".clk_i misses {top}"); + } +} + +#[test] +#[ignore = "needs an opentitan checkout (LUCISV_OPENTITAN or ~/.cache/lucisv-eval/ot)"] +fn under_the_folder_scope_references_stop_at_the_ip_block() { + let Some(root) = checkout() else { + eprintln!("skipped: no opentitan checkout holding {TB}"); + return; + }; + let (module, port) = answers(&root, json!({})); + assert_eq!(module.len(), 11, "aes: {module:#?}"); + assert_eq!(port.len(), 9, ".clk_i: {port:#?}"); + let in_block = |found: &[String]| found.iter().all(|hit| hit.starts_with("hw/ip/aes/")); + assert!(in_block(&module) && in_block(&port), "only hw/ip/aes is in scope"); +} diff --git a/docs/features/references-fanout-pd-main/README.md b/docs/features/references-fanout-pd-main/README.md new file mode 100644 index 0000000..4f1a8ca --- /dev/null +++ b/docs/features/references-fanout-pd-main/README.md @@ -0,0 +1,140 @@ +# references-fanout-pd-main + +## Goal + +TODO §65.2 (topo §2.9-36, MCP-6): on opentitan, `textDocument/references` at +the `aes` instantiation in `hw/ip/aes/dv/tb/tb.sv` and at its `.clk_i` +connection answered 11 and 9 locations, while the whole-set engine +(`vlog_refactor::find_references` over every file, as `lucisv-mcp`'s +`references` runs it) answered 14 and 12 — the same plus the three generated +tops `hw/top_{earlgrey,darjeeling,englishbreakfast}/rtl/autogen/*_pd_main.sv`. +Find the cause, fix it at the cause, and pin the answer. + +## Root cause + +**It is the index scope, not the fan-out.** The language server runs on the +shipped default `lucisv.index.scope: "folder"` with `scopeDepth: 2` +(`settings.rs` `DEFAULT_SCOPE_DEPTH`, ladder in `state/scope.rs`). Opening +`hw/ip/aes/dv/tb/tb.sv` raises its folder two levels to **`hw/ip/aes`**, and +that is the whole index: the three `*_pd_main.sv` tops are never walked, so +no index table (units, instantiations, reference postings, words) knows them. +`lucisv-mcp` hands the engine every file under the root, which is the +`"workspace"` rung's set. The two answers are over different file sets; over +the same set they are identical. + +This is the documented behaviour of `docs/features/index-scope` ("cross-file +answers are scope-relative … `find_references` and a workspace rename all +answer within the active scope"; migration line `"lucisv.index.scope": +"workspace"`), chosen 2026-08-27/28 for scan cost. + +Evidence (release `lucisv-server` built at ec492cd, LSP client driving it over +stdio, root `ot/hw`, `tb.sv` opened, positions `45:3` `aes` and `50:6` +`clk_i`, after the scan's progress end plus 5 s): + +| scope | `aes` | `.clk_i` | files listed | +|---|---|---|---| +| default (`folder`, depth 2) | 11 | 9 | all under `hw/ip/aes/` | +| `index.scope: "workspace"` | **14** | **12** | the 11/9 + `darjeeling_pd_main.sv:1521/1538`, `earlgrey_pd_main.sv:2069/2086`, `englishbreakfast_pd_main.sv:933/950` | + +The workspace-scope answer is exactly MCP-6's 14/12 list. Ruled out, as the +lead's pre-investigation suggested: the 1 MiB size cap (the tops are +62–141 kB and are indexed under the workspace scope), `.gitignore`/the walk +(`autogen` is walked under the workspace scope), and the multi-line +`aes #( … ) u_aes (` shape (indexed and answered under the workspace scope). +`state/sources.rs` (`module_sources`, `rename_sources_traced`, `fan_out_of`) +and `nav.rs`'s indexed-references path are correct: within the scope they +equal the engine over `Workspace::sources()`. + +**Rename has the same scope relation and no gap of its own.** Probe over the +same checkout: a rename of `aes` from `tb.sv:45` edits 14 sites in 9 files +under the workspace scope (the three tops included) and 11 sites in 6 files +under the folder scope. The latter is the sharper consequence: under the +default scope a module rename from the testbench would leave the three tops +instantiating a module that no longer exists. That is the index-scope +README's stated trade-off, but it is a correctness hazard for a write, not +only an incomplete read — flagged for the lead below. + +## Assumptions + +- "The whole-set engine" means `vlog_refactor::find_references` over every + file the client's root holds, as `lucisv-mcp` runs it; the server's answer + is compared to it over the same file set. +- The folder scope's documented behaviour stands until the lead rules + (Handshakes); nothing in this lane changes which files are indexed. + +## Handshakes + +- **Ruling request → lead (the fix is outside this lane's files).** The + cause is the shipped default scope, which lives in + `crates/lucisv_server/src/settings.rs` (`IndexScope::default`, + `DEFAULT_SCOPE_DEPTH`) and `state/scope.rs`, and is a product decision + recorded in `docs/features/index-scope`. Not edited. Options: + 1. **Keep the design; close §65.2 as scope-relative by design.** The tests + below pin both halves. Optionally document it where users meet it (the + VS Code setting's description, the README's LSP section). + 2. **Widen only for writes.** A cross-file rename (and port refactorings) + on a unit whose instantiations may exist outside the folder scope runs + against the workspace walk, or refuses with "outside the index scope — + set `lucisv.index.scope: workspace`". Closes the hazard above without + changing read latency. Touches `state/sources.rs` (`fan_out_of` / + `rename_sources_traced`) and the rename handler. + 3. **Change the default to `"workspace"` when the client has roots.** + Restores pre-2026-08-27 behaviour; costs the full scan the index-scope + round removed (opentitan: ~4 000 files; the persistent cache and the + interleaved scan now bound it). `settings.rs`, the index-scope README, + release notes. +- Consumed, unchanged: `Workspace::sources()`, `WorkspaceIndex::files()`, + `vlog_refactor::find_references`. No handshake changed. + +## Status / TODO + +- [x] Reproduce at the LSP level (11/9 default scope; 14/12 workspace scope) +- [x] Root cause named: the folder index scope (`hw/ip/aes`), not the fan-out +- [x] Rename's fan-out checked: same scope relation, no separate gap +- [x] Fixture regression tests (`server/tests/references_scope.rs`, 3 tests) +- [x] Ignored opentitan test (`tests/opentitan_references.rs`, 2 tests) +- [ ] Fix — pending the lead's ruling (Handshakes); no code fix was needed in + `sources.rs`/`nav.rs` +- [ ] QA + +## Work log + +- **2026-10-19 (dev).** Fast-forwarded the lane worktree from 75d2d37 to the + wave's base ec492cd (TODO-only commit). Built release `lucisv-server` and + drove it with a scratch stdio LSP client: default scope 11/9, all locations + under `hw/ip/aes/`; `index.scope: "workspace"` 14/12, exactly MCP-6's list. + So the gap is the scope, and the fan-out code is correct — nothing in + `sources.rs` or `nav.rs` changed. Rename probe: 9 files/14 edits (workspace) + vs 6 files/11 edits (folder) for `aes`; the `.clk_i` rename under the + workspace scope refuses over an unrelated implicit `.clk_i` binding in + `hw/ip/keymgr_dpe/dv/tb.sv` (the existing safety refusal), under the folder + scope it edits 16 sites in 6 files. + Tests: `server/tests/references_scope.rs` — opentitan's shape in miniature + (`ip/blk/rtl/blk.sv`, `ip/blk/dv/tb/tb.sv`, `top/rtl/autogen/top_pd_main.sv` + with a multi-line `blk #( … ) u_blk (`): (1) whole workspace: LSP == + engine over every file, for the module name and `clk_i`, each from its + declaration and from a use, and the top is listed; (2) folder scope: the top + is not in the index, LSP == engine over `Workspace::sources()` at the same + four positions, the top absent; opening the top widens the scope and the + answer becomes the whole set's; (3) whole workspace: a module rename from + the testbench edits the top. `tests/opentitan_references.rs` (ignored, skips + without the checkout): pins 14/12 with the three tops under the workspace + scope, and 11/9 all-in-`hw/ip/aes` under the default. Ran both ignored tests + against `~/.cache/lucisv-eval/ot`: pass (17.8 s, debug); with + `LUCISV_OPENTITAN=/nonexistent` both skip and pass. + +## QA log + +## Review + +**2026-10-19 — lead (owner's ruling).** The owner chose **keep as +designed**: cross-file answers stay relative to the index scope, and §65.2 +is closed as scope-relative by design rather than as a defect. The lane's +tests are merged as the pin of both halves (the workspace scope equals the +whole-set engine, the folder scope equals the engine over the scope, the +opentitan 14/12 vs 11/9). The rename consequence is now said in the +`lucisv.index.scope` setting's description (a rename of a module +instantiated outside the scope leaves those instantiations unchanged). No +production code changed, so no QA lane was run; the lead reviewed the +tests. + diff --git a/editors/vscode/package.json b/editors/vscode/package.json index f76372f..b9c8904 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -432,7 +432,7 @@ "Index every folder in the workspace, whatever is open." ], "default": "folder", - "markdownDescription": "How much of your project the workspace index scans. **`folder` (the default) indexes only the folders your open files live in** — plus everything under them — which is what keeps a huge project from costing minutes on every scan. Opening a file in another folder widens the index to that folder as well, so the scope grows as you work; it never shrinks while the editor is open. **Until it reaches a folder, symbols in that folder do not exist as far as the server is concerned**: go-to-definition, workspace symbol search, call and type hierarchy, find-references and rename all answer within the current scope only. Set to `workspace` to index every workspace folder up front, as lucisv always did before this setting existed — the right choice for a small project or a fast machine. A `#lucisv.filelist#` overrides this setting entirely: a project file defines the scope." + "markdownDescription": "How much of your project the workspace index scans. **`folder` (the default) indexes only the folders your open files live in** — plus everything under them — which is what keeps a huge project from costing minutes on every scan. Opening a file in another folder widens the index to that folder as well, so the scope grows as you work; it never shrinks while the editor is open. **Until it reaches a folder, symbols in that folder do not exist as far as the server is concerned**: go-to-definition, workspace symbol search, call and type hierarchy, find-references and rename all answer within the current scope only — so renaming a module that is also instantiated outside the scope (a top-level `*_top.sv` two blocks away) leaves those instantiations unchanged; open such a file first, or switch to `workspace`, before a rename across blocks. Set to `workspace` to index every workspace folder up front, as lucisv always did before this setting existed — the right choice for a small project or a fast machine. A `#lucisv.filelist#` overrides this setting entirely: a project file defines the scope." }, "lucisv.index.scopeDepth": { "type": "number",