Expand .*: a wildcard connection written out as the named connections it stands for
TODO §50 (docs/features/expand-wildcard), the first §8 refactoring. `vlog_refactor::expand_wildcard` (ports/expand.rs): at the cursor's instantiation, every port not explicitly connected becomes `.p(p)` when a same-named net, variable or port is declared in the instance's scope (generate block → parents → module; IEEE 1800 §23.3.2.4 read strictly — a parameter, genvar, type, instance or tf argument does not bind) and `.p()` plus a warning otherwise, in declaration order, replacing the `.*` element through the ports engine's splice and verifier. Refusals: no `.*`, two, a positional list, a `bind` directive, a multi-instance statement, a parse diagnostic in either file, compiler directives in either list, an unknown or twice-declared module, and a `.*` that binds nothing. Server: the lazy code action `lucisv: expand .* (N connections)` and the command `lucisv.expandWildcard`; a title-rewrite bug in the lazy offer path (`counted`) fixed on the way. Corpus: 11 of 21 sites expand (the rest refused honestly); opentitan `hw/`: 9 of 66 (50 are `bind`), each verified, two surfacing real FPV-wrapper drift. 0 of 854 corpus files differ. Dev-dependency vlog_refactor → vlog_formatter (tests). Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
1da0a303cc
commit
d9ed2c447a
30 files changed
+1827
-56
No files matched your search
Generated
+1
@@ -271,6 +271,7 @@ version = "0.45.0"
|
||||
name = "vlog_refactor"
|
||||
version = "0.45.0"
|
||||
dependencies = [
|
||||
"vlog_formatter",
|
||||
"vlog_parser",
|
||||
"vlog_semantic",
|
||||
]
|
||||
|
||||
@@ -710,8 +710,15 @@ section only tracks the milestones.
|
||||
- [x] **M14 `macro-expansion`** — single-step macro expansion on hover
|
||||
(the define-table README's promised follow-up); version 0.5.0 with a
|
||||
CHANGELOG entry covering M7–M14.
|
||||
- [ ] Backlog (extract module, inline, `.*` expansion, ANSI conversion,
|
||||
- [ ] Backlog (extract module, inline, ~~`.*` expansion~~, ANSI conversion,
|
||||
organize imports, …) — triaged in the umbrella README after M5.
|
||||
**`.*` expansion shipped 2026-09-05 (§50,
|
||||
`docs/features/expand-wildcard/README.md`)**: the wildcard written out as
|
||||
the named connections it stands for, per IEEE 1800 §23.3.2.4, with a code
|
||||
action and `lucisv.expandWildcard`. It leaves one thing behind, added to
|
||||
this backlog: **a `.*` written in a `bind` directive**, which binds in the
|
||||
target's scope rather than the one it is written in — elaboration, not
|
||||
lexical lookup, and 57 of OpenTitan's 66 wildcard sites.
|
||||
|
||||
## 9. LSP 3.18 protocol audit (2026-08-26)
|
||||
|
||||
@@ -4985,12 +4992,12 @@ declines a wildcard site).
|
||||
under `hw/ip` and expand ten of them into scratch copies, each result
|
||||
formatting cleanly and parsing with the same instance count.
|
||||
|
||||
- [ ] 50.1 `expand_wildcard` engine + refusals
|
||||
- [ ] 50.2 code action (lazy) + command
|
||||
- [ ] docs: feature README; README/site rows (lead applies); §8 line
|
||||
- [x] 50.1 `expand_wildcard` engine + refusals
|
||||
- [x] 50.2 code action (lazy) + command
|
||||
- [x] docs: feature README; README/site rows (lead applies); §8 line
|
||||
annotated
|
||||
- [ ] Gates (guarded); byte-identity vs 0.45.0
|
||||
- [ ] QA: the LRM rule attacked (kinds, scopes, generate, parameters);
|
||||
- [x] Gates (guarded); byte-identity vs 0.45.0
|
||||
- [x] QA: the LRM rule attacked (kinds, scopes, generate, parameters);
|
||||
refusals; ten opentitan sites in scratch copies
|
||||
|
||||
## 51. Non-ANSI → ANSI port conversion (planned 2026-09-05) — the second §8 refactoring
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The port refactorings on the wire: `textDocument/codeAction` for the two
|
||||
//! that need no typing, and `workspace/executeCommand` for all three.
|
||||
//! The port refactorings on the wire: `textDocument/codeAction` for the three
|
||||
//! that need no typing, and `workspace/executeCommand` for all four.
|
||||
//!
|
||||
//! Protocol only. Every edit is computed by `vlog_refactor` over the same file
|
||||
//! set the workspace index was built from; this module turns the result into a
|
||||
@@ -8,9 +8,10 @@
|
||||
//!
|
||||
//! **Why commands as well as code actions.** Adding a port needs a
|
||||
//! declaration typed by the user, and a code action carries no input — so
|
||||
//! `lucisv.addPort` is the API a UI calls once it has asked. `lucisv.removePort`
|
||||
//! and `lucisv.propagatePorts` take a position and exist for the same reason a
|
||||
//! Vim user has no lightbulb: a command works everywhere a keybinding does.
|
||||
//! `lucisv.addPort` is the API a UI calls once it has asked. `lucisv.removePort`,
|
||||
//! `lucisv.propagatePorts` and `lucisv.expandWildcard` take a position and
|
||||
//! exist for the same reason a Vim user has no lightbulb: a command works
|
||||
//! everywhere a keybinding does.
|
||||
//! See `docs/features/refactor-ports/README.md`.
|
||||
//!
|
||||
//! **Two shapes of code action.** A client that can resolve is *offered*
|
||||
@@ -48,10 +49,17 @@ pub const ADD_PORT: &str = "lucisv.addPort";
|
||||
pub const REMOVE_PORT: &str = "lucisv.removePort";
|
||||
/// Connect an instantiation's missing ports: `[uri, position]`.
|
||||
pub const PROPAGATE_PORTS: &str = "lucisv.propagatePorts";
|
||||
/// Write out the `.*` at a position: `[uri, position]`.
|
||||
pub const EXPAND_WILDCARD: &str = "lucisv.expandWildcard";
|
||||
|
||||
/// Every command this server executes.
|
||||
pub fn commands() -> Vec<String> {
|
||||
vec![ADD_PORT.to_string(), REMOVE_PORT.to_string(), PROPAGATE_PORTS.to_string()]
|
||||
vec![
|
||||
ADD_PORT.to_string(),
|
||||
REMOVE_PORT.to_string(),
|
||||
PROPAGATE_PORTS.to_string(),
|
||||
EXPAND_WILDCARD.to_string(),
|
||||
]
|
||||
}
|
||||
|
||||
/// The port actions available at a position, each carrying its own computed
|
||||
@@ -243,12 +251,21 @@ fn key(title: &str) -> &str {
|
||||
|
||||
/// An offered title with the workspace's own instantiation count in it,
|
||||
/// replacing the one the offer's one or two files could see.
|
||||
///
|
||||
/// Only a title whose count *is* an instantiation census is recounted:
|
||||
/// `lucisv: expand .* (3 connections)` counts the connections one wildcard
|
||||
/// becomes, which the offer's own two files already know exactly and no index
|
||||
/// lookup could improve (`vlog_refactor::is_sites_phrase`).
|
||||
fn counted(ws: &Workspace, title: String, modules: &[String]) -> String {
|
||||
let Some(head) = title.strip_suffix(')').and_then(|head| head.rsplit_once(" (")) else {
|
||||
let Some((head, phrase)) = title.strip_suffix(')').and_then(|head| head.rsplit_once(" ("))
|
||||
else {
|
||||
return title;
|
||||
};
|
||||
if !vlog_refactor::is_sites_phrase(phrase) {
|
||||
return title;
|
||||
}
|
||||
let sites = modules.iter().map(|name| instances_of(ws, name)).sum();
|
||||
format!("{} ({})", head.0, vlog_refactor::sites_phrase(sites))
|
||||
format!("{head} ({})", vlog_refactor::sites_phrase(sites))
|
||||
}
|
||||
|
||||
/// Every instance of `name` the index has seen. An edge is one written
|
||||
@@ -267,7 +284,7 @@ fn declared_twice(ws: &Workspace, name: &str) -> bool {
|
||||
ws.index().units(name).iter().filter(|def| def.kind.is_instantiable()).count() > 1
|
||||
}
|
||||
|
||||
/// Run one of the three commands, or say why it cannot run.
|
||||
/// Run one of the four commands, or say why it cannot run.
|
||||
///
|
||||
/// The answer is the `WorkspaceEdit` to apply plus the engine's warnings. How
|
||||
/// it reaches the editor is `server.rs`'s business: it is pushed as a
|
||||
@@ -313,6 +330,12 @@ pub fn execute(
|
||||
let sources = sources_at(ws, &path, offset);
|
||||
vlog_refactor::propagate_ports(&sources, &path, offset)?
|
||||
}
|
||||
EXPAND_WILDCARD => {
|
||||
let (_, path) = target(ws, arguments.first())?;
|
||||
let offset = position_argument(ws, arguments, EXPAND_WILDCARD)?;
|
||||
let sources = sources_at(ws, &path, offset);
|
||||
vlog_refactor::expand_wildcard(&sources, &path, offset)?
|
||||
}
|
||||
// The instantiation skeleton is not a port refactoring and computes
|
||||
// its own `WorkspaceEdit`, but `server.rs` routes every non-lens
|
||||
// `workspace/executeCommand` through here — this is the one place an
|
||||
@@ -1336,8 +1359,75 @@ mod tests {
|
||||
assert!(message.contains("position"), "{message}");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// the `.*` expansion (TODO §50)
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
/// A workspace whose `top.sv` instantiates `sub` with a wildcard.
|
||||
fn wildcard(tree: &Tree) -> (Workspace, Uri, &'static str) {
|
||||
const TEXT: &str =
|
||||
"module top;\n logic clk, rst;\n sub u_sub (.clk(clk), .*);\nendmodule\n";
|
||||
tree.write("sub.sv", SUB);
|
||||
let top = tree.write("top.sv", TEXT);
|
||||
let mut ws = Workspace::default();
|
||||
ws.open_whole_workspace(vec![tree.path.clone()]);
|
||||
let uri = path_to_uri(&top).expect("uri");
|
||||
ws.set_document(uri.clone(), TEXT.to_string());
|
||||
(ws, uri, TEXT)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_wildcard_takes_a_position() {
|
||||
let tree = Tree::new("expand");
|
||||
let (ws, uri, text) = wildcard(&tree);
|
||||
let arguments = vec![
|
||||
serde_json::to_value(&uri).expect("uri"),
|
||||
serde_json::to_value(Position { line: 2, character: 24 }).expect("position"),
|
||||
];
|
||||
let (edit, warnings) = execute(&ws, EXPAND_WILDCARD, &arguments).expect("expands");
|
||||
assert!(warnings.is_empty(), "{warnings:?}");
|
||||
let edits = edits_for(&edit, &uri);
|
||||
assert_eq!(edits.len(), 1, "{edits:#?}");
|
||||
assert_eq!(edits[0].new_text, ".rst(rst)");
|
||||
// The range is the `.*` itself, in the client's own coordinates.
|
||||
assert_eq!(edits[0].range.start.character, 24);
|
||||
assert_eq!(edits[0].range.end.character, 26);
|
||||
assert_eq!(&text[text.find(".*").expect("the wildcard")..][..2], ".*");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_wildcard_refuses_where_there_is_no_wildcard() {
|
||||
let tree = Tree::new("expand_none");
|
||||
let (ws, top_uri, _) = opened(&tree);
|
||||
let arguments = vec![
|
||||
serde_json::to_value(&top_uri).expect("uri"),
|
||||
serde_json::to_value(Position { line: 2, character: 6 }).expect("position"),
|
||||
];
|
||||
let message = execute(&ws, EXPAND_WILDCARD, &arguments).expect_err("no wildcard");
|
||||
assert!(message.contains("writes no `.*` to expand"), "{message}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_wildcard_action_is_offered_lazily_and_resolves_to_the_eager_edit() {
|
||||
let tree = Tree::new("expand_action");
|
||||
let (ws, uri, text) = wildcard(&tree);
|
||||
let offset = text.find(".*").expect("the wildcard") as u32;
|
||||
|
||||
let lazy = offered(&ws, &uri, offset);
|
||||
assert_eq!(menu(&lazy), menu(&code_actions(&ws, &uri, offset)));
|
||||
// The count is the connections the wildcard becomes, and the index's
|
||||
// instantiation census must not overwrite it.
|
||||
assert_eq!(menu(&lazy)[0].0, "lucisv: expand .* (1 connection)");
|
||||
assert!(only(&lazy).edit.is_none(), "an offer carries no edit");
|
||||
|
||||
let resolved = resolve(&ws, only(&lazy).clone()).expect("edit");
|
||||
assert_eq!(resolved.title, "lucisv: expand .* (1 connection)");
|
||||
assert_eq!(resolved.edit, only(&code_actions(&ws, &uri, offset)).edit);
|
||||
assert_eq!(edits_for(resolved.edit.as_ref().expect("edit"), &uri)[0].new_text, ".rst(rst)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_command_list_is_what_the_server_advertises() {
|
||||
assert_eq!(commands(), vec![ADD_PORT, REMOVE_PORT, PROPAGATE_PORTS]);
|
||||
assert_eq!(commands(), vec![ADD_PORT, REMOVE_PORT, PROPAGATE_PORTS, EXPAND_WILDCARD]);
|
||||
}
|
||||
}
|
||||
@@ -1587,6 +1587,117 @@ fn a_client_that_resolves_is_offered_the_port_action_without_its_edit() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A top whose instantiation of `sub` connects one port and wildcards the
|
||||
/// rest. Line 2, character 24 is the `.*`.
|
||||
const WILDCARD_TOP: &str =
|
||||
"module top;\n logic clk, rst;\n sub u_sub (.clk(clk), .*);\nendmodule\n";
|
||||
|
||||
#[test]
|
||||
fn the_wildcard_expansion_is_offered_resolved_and_commanded_over_the_wire() {
|
||||
// TODO §50 on the wire: the action is offered lazily at the `.*` with the
|
||||
// count of connections it becomes (not the instantiation census the other
|
||||
// port titles carry), the resolve hands back the edit, and the command
|
||||
// answers with the same edit for a client with no lightbulb.
|
||||
let dir = temp_dir("wildcard");
|
||||
let sub = dir.join("sub.sv");
|
||||
std::fs::write(&sub, PORTS_SUB).expect("write");
|
||||
let top = dir.join("top.sv");
|
||||
std::fs::write(&top, WILDCARD_TOP).expect("write");
|
||||
let root = format!("file://{}", dir.display());
|
||||
let top_uri = format!("file://{}", top.display());
|
||||
|
||||
let boot = |id: u32| {
|
||||
[
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":{id},"method":"initialize","params":{{"processId":null,"rootUri":"{root}","capabilities":{{"textDocument":{{"codeAction":{{"resolveSupport":{{"properties":["edit"]}}}}}}}}}}}}"#
|
||||
)),
|
||||
frame(r#"{"jsonrpc":"2.0","method":"initialized","params":{}}"#),
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{{"textDocument":{{"uri":"{top_uri}","languageId":"systemverilog","version":1,"text":{}}}}}}}"#,
|
||||
serde_json::to_string(WILDCARD_TOP).expect("json")
|
||||
)),
|
||||
]
|
||||
.concat()
|
||||
};
|
||||
|
||||
let session = [
|
||||
boot(1),
|
||||
// The cursor on the `.*` itself.
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{{"textDocument":{{"uri":"{top_uri}"}},"range":{{"start":{{"line":2,"character":24}},"end":{{"line":2,"character":24}}}},"context":{{"diagnostics":[]}}}}}}"#
|
||||
)),
|
||||
// ...and the command, which needs no lightbulb at all.
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":3,"method":"workspace/executeCommand","params":{{"command":"lucisv.expandWildcard","arguments":["{top_uri}",{{"line":2,"character":24}}]}}}}"#
|
||||
)),
|
||||
// ...and a position with no `.*` is refused with the engine's sentence.
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":4,"method":"workspace/executeCommand","params":{{"command":"lucisv.expandWildcard","arguments":["{top_uri}",{{"line":1,"character":4}}]}}}}"#
|
||||
)),
|
||||
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);
|
||||
|
||||
// 1. The command is advertised beside the other three.
|
||||
let initialize = messages.iter().find(|m| m["id"] == 1).expect("initialize response");
|
||||
let commands = initialize["result"]["capabilities"]["executeCommandProvider"]["commands"]
|
||||
.as_array()
|
||||
.expect("the commands are listed");
|
||||
assert!(commands.iter().any(|c| c == "lucisv.expandWildcard"), "{commands:#?}");
|
||||
|
||||
// 2. The offer names the wildcard and its connection count, with no edit.
|
||||
let actions = messages.iter().find(|m| m["id"] == 2).expect("codeAction response");
|
||||
let offered = actions["result"].as_array().expect("an array of actions");
|
||||
let action = offered
|
||||
.iter()
|
||||
.find(|a| a["kind"] == "refactor.rewrite.lucisv.ports")
|
||||
.unwrap_or_else(|| panic!("no port action in {offered:#?}"));
|
||||
assert_eq!(action["title"], "lucisv: expand .* (1 connection)");
|
||||
assert!(action["edit"].is_null(), "an offer carries no edit: {action:#?}");
|
||||
|
||||
// 3. The command answers with the edit that replaces the `.*`.
|
||||
let expanded = messages.iter().find(|m| m["id"] == 3).expect("executeCommand response");
|
||||
let edits = expanded["result"]["changes"][&top_uri].as_array().expect("edits");
|
||||
assert_eq!(edits.len(), 1, "{edits:#?}");
|
||||
assert_eq!(edits[0]["newText"], ".rst(rst)");
|
||||
assert_eq!(edits[0]["range"]["start"]["line"], 2);
|
||||
assert_eq!(edits[0]["range"]["start"]["character"], 24, "the `.*` itself is replaced");
|
||||
assert_eq!(edits[0]["range"]["end"]["character"], 26);
|
||||
|
||||
// 4. ...and a refusal is `RequestFailed` with the engine's own sentence.
|
||||
let refused = messages.iter().find(|m| m["id"] == 4).expect("refusal response");
|
||||
assert_eq!(refused["error"]["code"], -32803, "LSP's RequestFailed");
|
||||
assert!(
|
||||
refused["error"]["message"]
|
||||
.as_str()
|
||||
.is_some_and(|m| m.contains("no module instantiation at this position")),
|
||||
"{refused:#?}"
|
||||
);
|
||||
|
||||
// 5. Handing the offered action back resolves it to that same edit.
|
||||
let resolve = [
|
||||
boot(1),
|
||||
frame(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":3,"method":"codeAction/resolve","params":{}}}"#,
|
||||
serde_json::to_string(action).expect("json")
|
||||
)),
|
||||
frame(r#"{"jsonrpc":"2.0","id":9,"method":"shutdown","params":null}"#),
|
||||
frame(r#"{"jsonrpc":"2.0","method":"exit","params":null}"#),
|
||||
]
|
||||
.concat();
|
||||
let messages = talk(&resolve);
|
||||
let resolved = messages.iter().find(|m| m["id"] == 3).expect("resolve response");
|
||||
let edits = resolved["result"]["edit"]["changes"][&top_uri]
|
||||
.as_array()
|
||||
.unwrap_or_else(|| panic!("no edit in {resolved:#?}"));
|
||||
assert_eq!(edits[0]["newText"], ".rst(rst)");
|
||||
assert_eq!(resolved["result"]["title"], "lucisv: expand .* (1 connection)");
|
||||
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// The module hinting pair: a definition worth a skeleton, and a top that is
|
||||
/// half-way through instantiating it.
|
||||
const HINT_SUB: &str = "module hint_sub #(\n parameter int WIDTH = 8\n) (\n input logic clk,\n input logic [WIDTH-1:0] data,\n output logic ready\n);\nendmodule\n";
|
||||
|
||||
@@ -8,3 +8,11 @@ description = "Refactorings for Verilog/SystemVerilog, computed from resolved re
|
||||
[dependencies]
|
||||
vlog_parser = { path = "../vlog_parser" }
|
||||
vlog_semantic = { path = "../vlog_semantic" }
|
||||
|
||||
[dev-dependencies]
|
||||
# Tests only, the same arrangement `vlog_linter` uses: the `.*` expansion's
|
||||
# acceptance test asserts that what the refactoring writes is something the
|
||||
# formatter accepts and leaves alone the second time. The library still
|
||||
# depends on vlog_parser + vlog_semantic alone
|
||||
# (`cargo tree -p vlog_refactor -e normal`).
|
||||
vlog_formatter = { path = "../vlog_formatter" }
|
||||
@@ -315,7 +315,7 @@ fn terminate(out: &mut String, text: &str) {
|
||||
/// the question is exactly whether a `\` survives in the run of characters
|
||||
/// after the last whitespace. Conservative by construction: a false positive
|
||||
/// writes one harmless extra space.
|
||||
fn ends_escaped(text: &str) -> bool {
|
||||
pub(crate) fn ends_escaped(text: &str) -> bool {
|
||||
text.rsplit(char::is_whitespace).next().unwrap_or(text).contains('\\')
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,9 @@ pub use instantiate::{
|
||||
PlanPort, Site,
|
||||
};
|
||||
pub use ports::{
|
||||
add_port, enclosing_module, may_have_port_action, port_action_modules, port_actions,
|
||||
propagate_ports, remove_port, sites_phrase, ModuleRef, PortAction,
|
||||
add_port, enclosing_module, expand_wildcard, is_sites_phrase, may_have_port_action,
|
||||
port_action_modules, port_actions, propagate_ports, remove_port, sites_phrase, ModuleRef,
|
||||
PortAction,
|
||||
};
|
||||
pub use rename::{
|
||||
contains_word, prepare_rename, prepare_rename_here, rename, rename_name_at, RenameTarget,
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
//! Expanding `.*`: the wildcard connection written out as the named
|
||||
//! connections it stands for.
|
||||
//!
|
||||
//! **The rule, as implemented.** IEEE 1800 §23.3.2.4: a `.*` binds every port
|
||||
//! the instance does not connect explicitly to the *same-named* declaration
|
||||
//! visible in the scope the instantiation is written in. lucisv reads "a
|
||||
//! signal" strictly — a net, a variable, or a port of the enclosing module —
|
||||
//! because those are the only declarations a port connection may bind to; a
|
||||
//! parameter, a localparam, a genvar or a type of that name is not a signal
|
||||
//! and the wildcard does not bind it. A port with nothing to bind to is one
|
||||
//! the compiler would have rejected, so it is written `.name()` and named in a
|
||||
//! warning: saying so is the point of the expansion.
|
||||
//!
|
||||
//! Everything else is `propagate.rs`'s shape — the same `Scope`, the same
|
||||
//! declared-port reader, the same `Plan` verified by `finish` — with one
|
||||
//! difference: this refactoring *replaces* a token rather than appending after
|
||||
//! one, so the `.*`'s own span is the edit's range and the comment written
|
||||
//! after it is stepped over the way `append_to_list` steps over one.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use vlog_parser::ast::{Connection, Connections, Instance, Instantiation, Item, ListElem};
|
||||
use vlog_parser::span::TextRange;
|
||||
use vlog_parser::{parse_source_tolerant, LineIndex, ParseDiagnostic};
|
||||
use vlog_semantic::SymbolKind;
|
||||
|
||||
use crate::rename::{display, Scope};
|
||||
use crate::TextEdit;
|
||||
|
||||
use super::add::not_indexed;
|
||||
use super::find::{
|
||||
declared_ports, find_module, kind_visible_in, locate_module, not_in_scope, walk_instantiations,
|
||||
ModuleSite,
|
||||
};
|
||||
use super::list::{after_same_line_comments, conn_list_open, elem_spans, insert, line_indent};
|
||||
use super::{shape, ModuleRef, Plan};
|
||||
|
||||
/// One planned expansion: what to edit, and what the title will promise.
|
||||
pub(super) struct Expansion {
|
||||
pub(super) site: ModuleSite,
|
||||
pub(super) plan: Plan,
|
||||
/// How many connections the `.*` becomes.
|
||||
pub(super) count: usize,
|
||||
/// The instance the wildcard belongs to, for the verifier's sentence.
|
||||
pub(super) instance: String,
|
||||
}
|
||||
|
||||
pub(super) fn plan_expand(
|
||||
scope: &mut Scope,
|
||||
file: &Path,
|
||||
offset: u32,
|
||||
) -> Result<Expansion, String> {
|
||||
let Some(i) = scope.index_of(file) else { return Err(not_in_scope(file)) };
|
||||
let Some(text) = scope.text(i) else { return Err(not_in_scope(file)) };
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
unparsed(file, &diagnostics)?;
|
||||
let Wildcard { instantiation, instance, conns, wildcard } = wildcard_at(&tree.items, offset)?;
|
||||
if !instance.conn_directives.is_empty() {
|
||||
return Err(directives(&instance.name, "connection list"));
|
||||
}
|
||||
let site = locate_module(scope, ModuleRef::Name(&instantiation.module))?;
|
||||
|
||||
let missing = unconnected(scope, &site, conns)?;
|
||||
if missing.is_empty() {
|
||||
return Err(format!(
|
||||
"`{}` already connects every port `{}` declares, so its `.*` binds nothing.",
|
||||
instance.name, site.name
|
||||
));
|
||||
}
|
||||
|
||||
let (connections, unbound) = written(scope, i, instance, &missing);
|
||||
let spans: Vec<TextRange> = elem_spans(conns, |c| c.span);
|
||||
let Some(open) = conn_list_open(text, instance, spans.first().copied()) else {
|
||||
return Err(format!(
|
||||
"lucisv cannot find the parentheses of `{}`'s connection list.",
|
||||
instance.name
|
||||
));
|
||||
};
|
||||
let previous = wildcard.checked_sub(1).and_then(|n| spans.get(n)).map_or(open + 1, |e| e.end);
|
||||
let Some(&at) = spans.get(wildcard) else {
|
||||
return Err("lucisv lost track of the `.*` it was expanding.".to_string());
|
||||
};
|
||||
|
||||
let mut plan = Plan { sites: 1, ..Plan::default() };
|
||||
plan.add(i, replacement(text, previous, at, &connections));
|
||||
if !unbound.is_empty() {
|
||||
plan.warnings.push(unbound_warning(text, file, instance, &unbound));
|
||||
}
|
||||
plan.expected.push((i, expected(text, &site.name, instance, conns, wildcard, &missing)));
|
||||
Ok(Expansion { site, plan, count: connections.len(), instance: instance.name.clone() })
|
||||
}
|
||||
|
||||
/// The refusal a file that does not parse earns. A connection list lucisv
|
||||
/// misread is a list whose ports it would connect twice, so — unlike the
|
||||
/// verifier's "no *new* diagnostic" rule — this one asks for none at all.
|
||||
fn unparsed(file: &Path, diagnostics: &[ParseDiagnostic]) -> Result<(), String> {
|
||||
match diagnostics.first() {
|
||||
None => Ok(()),
|
||||
Some(problem) => Err(format!(
|
||||
"{} does not parse ({} at line {}), so lucisv will not expand a `.*` in it.",
|
||||
display(file),
|
||||
problem.message,
|
||||
problem.line
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn directives(what: &str, list: &str) -> String {
|
||||
format!(
|
||||
"`{what}`'s {list} carries compiler directives, so which ports `.*` binds depends on the configuration; lucisv does not preprocess, so it made no edits."
|
||||
)
|
||||
}
|
||||
|
||||
/// What the cursor found: an instance, its named connection list, and which
|
||||
/// element of it is the `.*`.
|
||||
struct Wildcard<'t> {
|
||||
instantiation: &'t Instantiation,
|
||||
instance: &'t Instance,
|
||||
conns: &'t [ListElem<Connection>],
|
||||
wildcard: usize,
|
||||
}
|
||||
|
||||
/// The instantiation the cursor names and the `.*` inside it, or the sentence
|
||||
/// saying why there is none to expand.
|
||||
fn wildcard_at(items: &[Item], offset: u32) -> Result<Wildcard<'_>, String> {
|
||||
let (instantiation, instance, bound) = instance_at(items, offset)?;
|
||||
if bound {
|
||||
return Err(format!(
|
||||
"`{}` is instantiated by a `bind` directive, where `.*` binds in the target's scope rather than in this one; lucisv does not expand it there.",
|
||||
instance.name
|
||||
));
|
||||
}
|
||||
let conns = match &instance.conns {
|
||||
Connections::Ordered(_) => {
|
||||
return Err(format!(
|
||||
"`{}` connects `{}`'s ports by position; there is no `.*` to expand.",
|
||||
instance.name, instantiation.module
|
||||
))
|
||||
}
|
||||
Connections::Named(conns) => conns.as_slice(),
|
||||
};
|
||||
let wildcards: Vec<usize> = conns
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, c)| c.ok().is_some_and(|c| c.name == "*"))
|
||||
.map(|(n, _)| n)
|
||||
.collect();
|
||||
match wildcards.as_slice() {
|
||||
[only] => Ok(Wildcard { instantiation, instance, conns, wildcard: *only }),
|
||||
[] => Err(format!("`{}` writes no `.*` to expand.", instance.name)),
|
||||
_ => Err(format!(
|
||||
"`{}` writes `.*` {} times, which is illegal; lucisv will not guess what it means.",
|
||||
instance.name,
|
||||
wildcards.len()
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The instance under the cursor, or the only one of the statement the
|
||||
/// cursor's module name belongs to — `propagate`'s rule, plus whether the
|
||||
/// instantiation is a `bind` directive's.
|
||||
fn instance_at(items: &[Item], offset: u32) -> Result<(&Instantiation, &Instance, bool), String> {
|
||||
let mut all: Vec<(&Instantiation, bool)> = Vec::new();
|
||||
walk_instantiations(items, &mut |instantiation, bound| all.push((instantiation, bound)));
|
||||
let mut found = None;
|
||||
for (instantiation, bound) in all {
|
||||
for instance in &instantiation.instances {
|
||||
if instance.span.contains(offset) {
|
||||
found = Some((instantiation, instance, bound));
|
||||
}
|
||||
}
|
||||
if found.is_none() && instantiation.module_span.contains(offset) {
|
||||
let [only] = instantiation.instances.as_slice() else {
|
||||
return Err(format!(
|
||||
"this statement declares {} instances of `{}`; put the cursor on the one to expand.",
|
||||
instantiation.instances.len(),
|
||||
instantiation.module
|
||||
));
|
||||
};
|
||||
found = Some((instantiation, only, bound));
|
||||
}
|
||||
}
|
||||
found.ok_or_else(|| "there is no module instantiation at this position.".to_string())
|
||||
}
|
||||
|
||||
/// The declared ports the instance does not connect explicitly, in declaration
|
||||
/// order — exactly what the wildcard stands for.
|
||||
fn unconnected(
|
||||
scope: &mut Scope,
|
||||
site: &ModuleSite,
|
||||
conns: &[ListElem<Connection>],
|
||||
) -> Result<Vec<String>, String> {
|
||||
let Some(text) = scope.text(site.file) else { return Err(not_indexed(&site.name)) };
|
||||
let Some(path) = scope.path(site.file) else { return Err(not_indexed(&site.name)) };
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
unparsed(path, &diagnostics)?;
|
||||
let Some((module, _)) = find_module(&tree, &site.name) else {
|
||||
return Err(not_indexed(&site.name));
|
||||
};
|
||||
if !module.port_directives.is_empty() {
|
||||
return Err(directives(&site.name, "port list"));
|
||||
}
|
||||
Ok(declared_ports(module)
|
||||
.into_iter()
|
||||
.map(|port| port.name)
|
||||
.filter(|name| conns.iter().filter_map(ListElem::ok).all(|c| &c.name != name))
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Each missing port as the connection lucisv writes for it, plus the ports
|
||||
/// nothing in scope binds.
|
||||
fn written(
|
||||
scope: &mut Scope,
|
||||
file: usize,
|
||||
instance: &Instance,
|
||||
missing: &[String],
|
||||
) -> (Vec<String>, Vec<String>) {
|
||||
let at = instance.name_span.start;
|
||||
let mut connections = Vec::new();
|
||||
let mut unbound = Vec::new();
|
||||
for name in missing {
|
||||
let bound = signal_visible(scope, file, at, name);
|
||||
if !bound {
|
||||
unbound.push(name.clone());
|
||||
}
|
||||
connections.push(connection(name, bound));
|
||||
}
|
||||
(connections, unbound)
|
||||
}
|
||||
|
||||
/// `.name(name)`, or `.name()` for a port nothing binds — with the space an
|
||||
/// **escaped identifier** needs after it.
|
||||
///
|
||||
/// An escaped identifier runs from its `\` to the next whitespace and to
|
||||
/// nothing else (IEEE 1800 §5.6.1), so `.\my-port(\my-port)` is one enormous
|
||||
/// token that swallows the parens, the comma and the rest of the line. The
|
||||
/// instantiation skeleton learned this from QA (`instantiate::terminate`);
|
||||
/// the test for "does this end inside an escape" is shared rather than
|
||||
/// spelled twice.
|
||||
fn connection(name: &str, bound: bool) -> String {
|
||||
let mut out = String::from(".");
|
||||
terminate(&mut out, name);
|
||||
out.push('(');
|
||||
if bound {
|
||||
terminate(&mut out, name);
|
||||
}
|
||||
out.push(')');
|
||||
out
|
||||
}
|
||||
|
||||
fn terminate(out: &mut String, name: &str) {
|
||||
out.push_str(name);
|
||||
if crate::instantiate::ends_escaped(name) {
|
||||
out.push(' ');
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `.*` would bind `name` here: a net, a variable or a port of that
|
||||
/// name, declared in the instantiating scope or one enclosing it.
|
||||
///
|
||||
/// A parameter is deliberately not one. `parameter int clk = 0;` beside an
|
||||
/// instance leaves the module's `clk` port unbound, and writing `.clk(clk)`
|
||||
/// for it would connect a port to a constant — a legal, silent, wrong
|
||||
/// expansion. The kinds are the LRM's, not the ones a connection lucisv
|
||||
/// *writes* may name (`find::visible_in`).
|
||||
fn signal_visible(scope: &mut Scope, file: usize, offset: u32, name: &str) -> bool {
|
||||
let Some(analysis) = scope.analysis(file) else { return false };
|
||||
kind_visible_in(&analysis.semantics, offset, name)
|
||||
.is_some_and(|kind| matches!(kind, SymbolKind::Net | SymbolKind::Var | SymbolKind::Port))
|
||||
}
|
||||
|
||||
/// The edits that put the connections where the `.*` was.
|
||||
///
|
||||
/// The layout is the list's own, read the way `append_to_list` reads it: the
|
||||
/// gap before the wildcard tells one-element-per-line from inline, and the
|
||||
/// indentation is the wildcard's own line's. A comment written after the `.*`
|
||||
/// on its own line stays with the **first** connection — the comma goes before
|
||||
/// it and the rest after it — because a `,` written after `//` is a `,` inside
|
||||
/// a comment, and because the comment was about the wildcard, whose first
|
||||
/// connection is what replaces it.
|
||||
fn replacement(text: &str, previous: u32, at: TextRange, connections: &[String]) -> Vec<TextEdit> {
|
||||
let one_per_line =
|
||||
text.get(previous as usize..at.start as usize).is_some_and(|gap| gap.contains('\n'));
|
||||
let indent = line_indent(text, at.start);
|
||||
let br = match one_per_line {
|
||||
true => format!("\n{indent}"),
|
||||
false => " ".to_string(),
|
||||
};
|
||||
let separator = format!(",{br}");
|
||||
let replace = |text: String| TextEdit { range: at, new_text: text };
|
||||
|
||||
let after = after_same_line_comments(text, at.end);
|
||||
let [first, rest @ ..] = connections else { return Vec::new() };
|
||||
if after.at == at.end || rest.is_empty() {
|
||||
return vec![replace(connections.join(&separator))];
|
||||
}
|
||||
vec![replace(format!("{first},")), insert(after.at, format!("{br}{}", rest.join(&separator)))]
|
||||
}
|
||||
|
||||
fn unbound_warning(text: &str, file: &Path, instance: &Instance, unbound: &[String]) -> String {
|
||||
let lines = LineIndex::new(text);
|
||||
format!(
|
||||
"no net, variable or port named {} is declared where `{}` is instantiated ({}:{}), so `.*` never bound {} — lucisv wrote {} unconnected.",
|
||||
unbound.iter().map(|n| format!("`{n}`")).collect::<Vec<_>>().join(", "),
|
||||
instance.name,
|
||||
display(file),
|
||||
lines.line_col(instance.name_span.start).0,
|
||||
if unbound.len() == 1 { "it" } else { "them" },
|
||||
if unbound.len() == 1 { "it" } else { "them" },
|
||||
)
|
||||
}
|
||||
|
||||
/// What the file must say afterwards: this instance's connection names with
|
||||
/// the `*` replaced, in place, by the ports it stood for.
|
||||
fn expected(
|
||||
text: &str,
|
||||
module: &str,
|
||||
instance: &Instance,
|
||||
conns: &[ListElem<Connection>],
|
||||
wildcard: usize,
|
||||
missing: &[String],
|
||||
) -> super::Shape {
|
||||
let mut names: Vec<String> =
|
||||
conns.iter().map(|c| c.ok().map(|c| c.name.clone()).unwrap_or_default()).collect();
|
||||
names.splice(wildcard..wildcard + 1, missing.iter().cloned());
|
||||
let mut shape = shape(text, module);
|
||||
for (name, conns) in &mut shape.instances {
|
||||
if name == &instance.name {
|
||||
*conns = names.clone();
|
||||
}
|
||||
}
|
||||
shape
|
||||
}
|
||||
@@ -143,34 +143,45 @@ pub(super) fn declared_ports(module: &Module) -> Vec<DeclaredPort> {
|
||||
/// Every instantiation written in a file, generate blocks and `bind`
|
||||
/// directives included.
|
||||
pub(super) fn collect_instantiations<'t>(items: &'t [Item], out: &mut Vec<&'t Instantiation>) {
|
||||
walk_instantiations(items, &mut |instantiation, _| out.push(instantiation));
|
||||
}
|
||||
|
||||
/// [`collect_instantiations`]'s walk, saying of each instantiation whether it
|
||||
/// is a `bind` directive's own — which is where a `.*` binds in the *target's*
|
||||
/// scope rather than in the one it is written in, and therefore the one site
|
||||
/// the wildcard expansion declines.
|
||||
pub(super) fn walk_instantiations<'t>(
|
||||
items: &'t [Item],
|
||||
visit: &mut dyn FnMut(&'t Instantiation, bool),
|
||||
) {
|
||||
for item in items {
|
||||
match &item.kind {
|
||||
ItemKind::Instantiation(inst) => out.push(inst),
|
||||
ItemKind::Bind(bind) => out.push(&bind.inst),
|
||||
ItemKind::Module(module) => collect_instantiations(&module.items, out),
|
||||
ItemKind::Package { items, .. } => collect_instantiations(items, out),
|
||||
ItemKind::GenerateRegion { items, .. } => collect_instantiations(items, out),
|
||||
ItemKind::GenBlock(b) => collect_instantiations(&b.items, out),
|
||||
ItemKind::Instantiation(inst) => visit(inst, false),
|
||||
ItemKind::Bind(bind) => visit(&bind.inst, true),
|
||||
ItemKind::Module(module) => walk_instantiations(&module.items, visit),
|
||||
ItemKind::Package { items, .. } => walk_instantiations(items, visit),
|
||||
ItemKind::GenerateRegion { items, .. } => walk_instantiations(items, visit),
|
||||
ItemKind::GenBlock(b) => walk_instantiations(&b.items, visit),
|
||||
ItemKind::GenIf(gen) => {
|
||||
collect_gen_block(&gen.then, out);
|
||||
walk_gen_block(&gen.then, visit);
|
||||
let mut els = gen.els.as_deref();
|
||||
while let Some(next) = els {
|
||||
match next {
|
||||
GenElse::If(_, gen) => {
|
||||
collect_gen_block(&gen.then, out);
|
||||
walk_gen_block(&gen.then, visit);
|
||||
els = gen.els.as_deref();
|
||||
}
|
||||
GenElse::Block(block) => {
|
||||
collect_gen_block(block, out);
|
||||
walk_gen_block(block, visit);
|
||||
els = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemKind::GenFor(gen) => collect_gen_block(&gen.body, out),
|
||||
ItemKind::GenFor(gen) => walk_gen_block(&gen.body, visit),
|
||||
ItemKind::GenCase(gen) => {
|
||||
for arm in &gen.items {
|
||||
collect_gen_block(&arm.body, out);
|
||||
walk_gen_block(&arm.body, visit);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -178,8 +189,8 @@ pub(super) fn collect_instantiations<'t>(items: &'t [Item], out: &mut Vec<&'t In
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_gen_block<'t>(block: &'t GenBlock, out: &mut Vec<&'t Instantiation>) {
|
||||
collect_instantiations(&block.items, out);
|
||||
fn walk_gen_block<'t>(block: &'t GenBlock, visit: &mut dyn FnMut(&'t Instantiation, bool)) {
|
||||
walk_instantiations(&block.items, visit);
|
||||
}
|
||||
|
||||
/// Whether a signal called `name` is visible at `offset` in a file — the test
|
||||
@@ -190,6 +201,32 @@ pub(super) fn name_visible(scope: &mut Scope, file: usize, offset: u32, name: &s
|
||||
}
|
||||
|
||||
pub(crate) fn visible_in(semantics: &Semantics, offset: u32, name: &str) -> bool {
|
||||
kind_visible_in(semantics, offset, name).is_some_and(|kind| {
|
||||
matches!(
|
||||
kind,
|
||||
SymbolKind::Net
|
||||
| SymbolKind::Var
|
||||
| SymbolKind::Port
|
||||
| SymbolKind::Param
|
||||
| SymbolKind::LocalParam
|
||||
| SymbolKind::Genvar
|
||||
| SymbolKind::TfArg
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// What a lookup of `name` from the innermost scope covering `offset` finds —
|
||||
/// the scope walk itself, without the judgement about which kinds count.
|
||||
///
|
||||
/// Two callers want different answers from the same walk: a connection lucisv
|
||||
/// *writes* may name anything a reader could have written there, while `.*`
|
||||
/// binds only a net, a variable or a port (IEEE 1800 §23.3.2.4), so the
|
||||
/// wildcard expansion asks the same question and reads the kind itself.
|
||||
pub(crate) fn kind_visible_in(
|
||||
semantics: &Semantics,
|
||||
offset: u32,
|
||||
name: &str,
|
||||
) -> Option<SymbolKind> {
|
||||
let scopes = semantics.scopes();
|
||||
// The innermost scope covering the offset: the smallest span that holds it.
|
||||
let mut best: Option<usize> = None;
|
||||
@@ -206,24 +243,13 @@ pub(crate) fn visible_in(semantics: &Semantics, offset: u32, name: &str) -> bool
|
||||
}
|
||||
let mut at = best;
|
||||
while let Some(i) = at {
|
||||
let Some(current) = scopes.get(i) else { return false };
|
||||
let current = scopes.get(i)?;
|
||||
if let Some(symbol) = current.lookup_local(name) {
|
||||
return semantics.symbol(symbol).is_some_and(|s| {
|
||||
matches!(
|
||||
s.kind,
|
||||
SymbolKind::Net
|
||||
| SymbolKind::Var
|
||||
| SymbolKind::Port
|
||||
| SymbolKind::Param
|
||||
| SymbolKind::LocalParam
|
||||
| SymbolKind::Genvar
|
||||
| SymbolKind::TfArg
|
||||
)
|
||||
});
|
||||
return semantics.symbol(symbol).map(|s| s.kind);
|
||||
}
|
||||
at = current.parent.map(|p| p.0 as usize);
|
||||
}
|
||||
false
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
//! parenthesis finding they share.
|
||||
|
||||
mod add;
|
||||
mod expand;
|
||||
mod find;
|
||||
mod list;
|
||||
mod propagate;
|
||||
@@ -38,6 +39,7 @@ use crate::rename::{display, Scope};
|
||||
use crate::{check, RefactorEdit, TextEdit};
|
||||
|
||||
use add::{parse_port_decl, plan_add};
|
||||
use expand::plan_expand;
|
||||
use find::{collect_instantiations, declared_ports, locate_module, module_at};
|
||||
use propagate::plan_propagate;
|
||||
use remove::{locate_port, plan_remove};
|
||||
@@ -125,6 +127,35 @@ pub fn propagate_ports(
|
||||
Ok(finish(&mut scope, plan, &site.name, &what)?.0)
|
||||
}
|
||||
|
||||
/// Write out the `.*` at `offset`: every port the instantiation does not
|
||||
/// connect explicitly, bound to the same-named signal in the instantiating
|
||||
/// scope (IEEE 1800 §23.3.2.4), in the module's declaration order.
|
||||
///
|
||||
/// A port with no such signal is one the wildcard never bound — a compiler
|
||||
/// would have rejected the instantiation — so it is written `.name()` and
|
||||
/// named in a warning. Nothing outside the cursor's own file is edited.
|
||||
pub fn expand_wildcard(
|
||||
files: &[(PathBuf, String)],
|
||||
file: &Path,
|
||||
offset: u32,
|
||||
) -> Result<RefactorEdit, String> {
|
||||
Ok(expansion(files, file, offset)?.0)
|
||||
}
|
||||
|
||||
/// The expansion and how many connections it writes — what a code action's
|
||||
/// title promises.
|
||||
fn expansion(
|
||||
files: &[(PathBuf, String)],
|
||||
file: &Path,
|
||||
offset: u32,
|
||||
) -> Result<(RefactorEdit, usize), String> {
|
||||
let mut scope = Scope::build(files);
|
||||
let expansion = plan_expand(&mut scope, file, offset)?;
|
||||
let what = format!("expanding the `.*` of `{}`", expansion.instance);
|
||||
let edit = finish(&mut scope, expansion.plan, &expansion.site.name, &what)?.0;
|
||||
Ok((edit, expansion.count))
|
||||
}
|
||||
|
||||
/// Every port refactoring available at a position, each with its edit already
|
||||
/// computed and verified — which is what lets a code action carry its own
|
||||
/// `WorkspaceEdit` instead of a command the editor has to resolve.
|
||||
@@ -153,6 +184,15 @@ pub fn port_actions(files: &[(PathBuf, String)], file: &Path, offset: u32) -> Ve
|
||||
edit,
|
||||
});
|
||||
}
|
||||
if let Ok((edit, count)) = expansion(files, file, offset) {
|
||||
out.push(PortAction {
|
||||
title: format!(
|
||||
"lucisv: expand .* ({count} connection{})",
|
||||
if count == 1 { "" } else { "s" }
|
||||
),
|
||||
edit,
|
||||
});
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -249,6 +289,17 @@ pub fn sites_phrase(sites: usize) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a title's parenthesized tail is one [`sites_phrase`] wrote.
|
||||
///
|
||||
/// A server that recounts an offered title's instantiations from its index
|
||||
/// must not recount a title counting something else: `lucisv: expand .* (3
|
||||
/// connections)` says how many connections one `.*` becomes, which no
|
||||
/// instantiation census can answer. One spelling of the phrase, and one
|
||||
/// reader of it, both here.
|
||||
pub fn is_sites_phrase(phrase: &str) -> bool {
|
||||
phrase == sites_phrase(0) || phrase.starts_with("updates ")
|
||||
}
|
||||
|
||||
/// Everything a port refactoring wants done, before it is verified.
|
||||
#[derive(Default)]
|
||||
struct Plan {
|
||||
|
||||
@@ -11,8 +11,8 @@ use std::path::{Path, PathBuf};
|
||||
use std::time::Instant;
|
||||
|
||||
use vlog_refactor::{
|
||||
add_port, instantiation_plan, module_definition, port_actions, prepare_rename, rename, Layout,
|
||||
ModuleRef,
|
||||
add_port, expand_wildcard, instantiation_plan, module_definition, port_actions, prepare_rename,
|
||||
rename, Layout, ModuleRef,
|
||||
};
|
||||
use vlog_semantic::WorkspaceIndex;
|
||||
|
||||
@@ -260,3 +260,74 @@ fn module_names_in(text: &str) -> Vec<String> {
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wildcard_expanded_in_the_corpus_is_something_the_formatter_accepts() {
|
||||
// The `.*` sites in the corpus are real ones — testbenches and formal
|
||||
// wrappers, where the wildcard is written most — and the property that
|
||||
// matters is the same one the whole formatter lives by: what the
|
||||
// refactoring writes must format, and formatting it twice must not move
|
||||
// it. The edit is applied to a *copy* of the text; nothing is written back
|
||||
// to `corpus/`.
|
||||
let Some(files) = corpus() else { return };
|
||||
let sources = read(&files);
|
||||
assert!(!sources.is_empty(), "corpus/ exists but holds no Verilog");
|
||||
let config = vlog_formatter::Config::default();
|
||||
|
||||
let mut expanded: Vec<String> = Vec::new();
|
||||
let mut refused: Vec<String> = Vec::new();
|
||||
for (path, text) in &sources {
|
||||
if expanded.len() >= 3 {
|
||||
break;
|
||||
}
|
||||
let Some(offset) = wildcard_offset(text) else { continue };
|
||||
let started = Instant::now();
|
||||
match expand_wildcard(&sources, path, offset) {
|
||||
Err(said) => refused.push(format!("{}: {said}", path.display())),
|
||||
Ok(edit) => {
|
||||
let edits = edit.edits_for(path);
|
||||
assert!(!edits.is_empty(), "{} was expanded with no edit", path.display());
|
||||
let mut copy = text.clone();
|
||||
for change in edits.iter().rev() {
|
||||
copy.replace_range(
|
||||
change.range.start as usize..change.range.end as usize,
|
||||
&change.new_text,
|
||||
);
|
||||
}
|
||||
assert_ne!(©, text, "the expansion changed nothing in {}", path.display());
|
||||
let once = vlog_formatter::format_source(©, &config).unwrap_or_else(|e| {
|
||||
panic!("the formatter refuses the expansion of {}: {e}\n{copy}", path.display())
|
||||
});
|
||||
let twice =
|
||||
vlog_formatter::format_source(&once, &config).expect("formats a second time");
|
||||
assert_eq!(once, twice, "formatting {}'s expansion diverges", path.display());
|
||||
expanded.push(format!(
|
||||
"{} in {:.2}s ({} edits)",
|
||||
path.display(),
|
||||
started.elapsed().as_secs_f64(),
|
||||
edits.len()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("corpus `.*` expansions:\n {}", expanded.join("\n "));
|
||||
if !refused.is_empty() {
|
||||
println!("refused:\n {}", refused.join("\n "));
|
||||
}
|
||||
assert!(expanded.len() >= 3, "three real expansions, got {expanded:?}; refused: {refused:?}");
|
||||
}
|
||||
|
||||
/// The offset of the first `.*` connection a file writes, found the way the
|
||||
/// plan's census counts them: a `.*` followed by a `,` or a `)`.
|
||||
fn wildcard_offset(text: &str) -> Option<u32> {
|
||||
let mut at = 0usize;
|
||||
while let Some(found) = text.get(at..)?.find(".*") {
|
||||
let start = at + found;
|
||||
let rest = text.get(start + 2..)?.trim_start();
|
||||
if rest.starts_with(',') || rest.starts_with(')') {
|
||||
return Some(start as u32);
|
||||
}
|
||||
at = start + 2;
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -0,0 +1,414 @@
|
||||
//! Behavior tests for `expand_wildcard`: what the `.*` expansion writes, what
|
||||
//! it refuses, and what the formatter says about the result.
|
||||
//!
|
||||
//! Every test states the whole workspace and asserts on the *applied* text,
|
||||
//! because that is what the user ends up with. A refusal is asserted on its
|
||||
//! sentence, since that sentence is the entire answer the editor shows.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use vlog_refactor::{expand_wildcard, port_actions, RefactorEdit};
|
||||
|
||||
/// A workspace: `(path, text)` pairs, the shape the engine takes.
|
||||
fn files(pairs: &[(&str, &str)]) -> Vec<(PathBuf, String)> {
|
||||
pairs.iter().map(|(path, text)| (PathBuf::from(*path), text.to_string())).collect()
|
||||
}
|
||||
|
||||
fn at(text: &str, needle: &str) -> u32 {
|
||||
text.find(needle).expect("needle present") as u32
|
||||
}
|
||||
|
||||
/// One file's text with the refactoring applied, the way a client applies a
|
||||
/// `WorkspaceEdit`: back to front, so every range still means what it said.
|
||||
fn applied(files: &[(PathBuf, String)], edit: &RefactorEdit, path: &str) -> String {
|
||||
let path = PathBuf::from(path);
|
||||
let mut text = files
|
||||
.iter()
|
||||
.find(|(p, _)| *p == path)
|
||||
.map(|(_, text)| text.clone())
|
||||
.expect("a file in the workspace");
|
||||
for change in edit.edits_for(&path).iter().rev() {
|
||||
text.replace_range(
|
||||
change.range.start as usize..change.range.end as usize,
|
||||
&change.new_text,
|
||||
);
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
/// The three-port module every test instantiates.
|
||||
const SUB: &str =
|
||||
"module sub (\n input logic clk,\n input logic rst,\n output logic done\n);\nendmodule\n";
|
||||
|
||||
/// The workspace, the expansion, and the cursor's file afterwards.
|
||||
fn expand(top: &str, needle: &str) -> Result<(RefactorEdit, String), String> {
|
||||
let workspace = files(&[("/rtl/sub.sv", SUB), ("/rtl/top.sv", top)]);
|
||||
let edit = expand_wildcard(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, needle))?;
|
||||
let text = applied(&workspace, &edit, "/rtl/top.sv");
|
||||
Ok((edit, text))
|
||||
}
|
||||
|
||||
/// What the refusal at this cursor says.
|
||||
fn refusal(top: &str, needle: &str) -> String {
|
||||
expand(top, needle).expect_err("a refusal").to_string()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// what it writes
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn the_wildcard_becomes_every_port_the_instance_does_not_name() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n .*\n );\nendmodule\n";
|
||||
let (edit, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n .rst(rst),\n .done(done)\n );\nendmodule\n"
|
||||
);
|
||||
assert_eq!(edit.file_count(), 1, "nothing outside the cursor's file is touched");
|
||||
assert!(edit.warnings.is_empty(), "{:?}", edit.warnings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_inline_list_stays_inline() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk), .*);\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk), .rst(rst), .done(done));\nendmodule\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wildcard_alone_on_its_line_writes_one_connection_per_line() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (\n .*\n );\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n .rst(rst),\n .done(done)\n );\nendmodule\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wildcard_alone_inline_writes_one_line() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.*);\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk), .rst(rst), .done(done));\nendmodule\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_port_with_no_signal_in_scope_is_written_unconnected_and_said_out_loud() {
|
||||
let top = "module top;\n logic clk, rst;\n sub u_sub (.*);\nendmodule\n";
|
||||
let (edit, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst;\n sub u_sub (.clk(clk), .rst(rst), .done());\nendmodule\n"
|
||||
);
|
||||
let warning = edit.warnings.join("\n");
|
||||
assert!(warning.contains("`done`"), "{warning}");
|
||||
assert!(warning.contains("no net, variable or port named"), "{warning}");
|
||||
assert!(warning.contains("top.sv:3"), "the site is named: {warning}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_same_named_parameter_is_not_a_signal_the_wildcard_binds() {
|
||||
// IEEE 1800 §23.3.2.4: `.*` binds a port to a net or variable of the same
|
||||
// name. `done` here is a constant, and `.done(done)` would connect an
|
||||
// output port to it — legal-looking, silent, and wrong.
|
||||
let top = "module top;\n logic clk, rst;\n localparam int done = 1;\n sub u_sub (.*);\nendmodule\n";
|
||||
let (edit, text) = expand(top, ".*").expect("expands");
|
||||
assert!(text.contains(".done()"), "{text}");
|
||||
assert!(!text.contains(".done(done)"), "the parameter is not bound: {text}");
|
||||
assert!(edit.warnings.join("\n").contains("`done`"), "{:?}", edit.warnings);
|
||||
|
||||
// ...and the same for a `parameter` in the header.
|
||||
let top = "module top #(parameter int done = 1) ();\n logic clk, rst;\n sub u_sub (.*);\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert!(text.contains(".done()"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_genvar_of_the_same_name_is_not_bound_either() {
|
||||
let sub = "module sub (\n input logic clk,\n input logic i\n);\nendmodule\n";
|
||||
let top = "module top;\n logic clk;\n for (genvar i = 0; i < 2; i++) begin : g\n sub u_sub (.*);\n end\nendmodule\n";
|
||||
let workspace = files(&[("/rtl/sub.sv", sub), ("/rtl/top.sv", top)]);
|
||||
let edit =
|
||||
expand_wildcard(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, ".*")).expect("expands");
|
||||
let text = applied(&workspace, &edit, "/rtl/top.sv");
|
||||
assert!(text.contains(".clk(clk), .i()"), "a genvar is not a net or a variable: {text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_generate_blocks_own_declaration_is_in_scope_and_so_is_the_modules() {
|
||||
let top = "module top;\n logic clk, rst;\n if (1) begin : g\n logic done;\n sub u_sub (.*);\n end\nendmodule\n";
|
||||
let (edit, text) = expand(top, ".*").expect("expands");
|
||||
assert!(
|
||||
text.contains("sub u_sub (.clk(clk), .rst(rst), .done(done));"),
|
||||
"the block's `done` and the module's `clk`/`rst`: {text}"
|
||||
);
|
||||
assert!(edit.warnings.is_empty(), "{:?}", edit.warnings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ports_are_written_in_the_modules_declaration_order() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.done(done), .*);\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert!(text.contains(".done(done), .clk(clk), .rst(rst)"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wildcard_written_before_an_explicit_connection_expands_in_place() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.*, .done(done));\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert!(text.contains("(.clk(clk), .rst(rst), .done(done))"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_implicit_or_empty_connection_counts_as_explicit() {
|
||||
// `.clk` and `.rst()` are connections the source wrote, so `.*` never
|
||||
// bound those ports and the expansion must not write them a second time.
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.clk, .rst(), .*);\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (.clk, .rst(), .done(done));\nendmodule\n"
|
||||
);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// comments
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn the_comment_after_the_wildcard_stays_with_the_first_connection() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n .* // and the rest\n );\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n .rst(rst), // and the rest\n .done(done)\n );\nendmodule\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_comment_before_the_wildcard_stays_before_the_first_connection() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n // bind the rest\n .*\n );\nendmodule\n";
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
assert_eq!(
|
||||
text,
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n // bind the rest\n .rst(rst),\n .done(done)\n );\nendmodule\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_block_comment_written_inside_the_wildcard_refuses_rather_than_dropping_it() {
|
||||
// The comment sits between the `.` and the `*`, inside the element the
|
||||
// expansion replaces. Comments are never dropped (invariant 3), and lucisv
|
||||
// will not decide where this one should move.
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (. /* here */ *);\nendmodule\n";
|
||||
let said = refusal(top, ". /* here */ *");
|
||||
assert!(said.contains("comments are never dropped"), "{said}");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// refusals
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn an_instantiation_without_a_wildcard_is_refused() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk));\nendmodule\n";
|
||||
assert!(refusal(top, "u_sub").contains("writes no `.*` to expand"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_position_that_is_not_an_instantiation_is_refused() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.*);\nendmodule\n";
|
||||
assert!(refusal(top, "logic clk").contains("no module instantiation at this position"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_positional_connection_list_is_refused() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (clk, rst, done);\nendmodule\n";
|
||||
let said = refusal(top, "u_sub");
|
||||
assert!(said.contains("by position"), "{said}");
|
||||
assert!(said.contains("no `.*` to expand"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_wildcards_in_one_instance_are_refused() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.*, .*);\nendmodule\n";
|
||||
let said = refusal(top, ".*");
|
||||
assert!(said.contains("writes `.*` 2 times"), "{said}");
|
||||
assert!(said.contains("illegal"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wildcard_inside_a_bind_directive_is_refused() {
|
||||
let top = "module top;\n logic clk, rst, done;\nendmodule\nbind top sub u_sub (.*);\n";
|
||||
let said = refusal(top, ".*");
|
||||
assert!(said.contains("`bind` directive"), "{said}");
|
||||
assert!(said.contains("target's scope"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_module_the_workspace_does_not_declare_is_refused() {
|
||||
let top = "module top;\n logic clk;\n nowhere u_x (.*);\nendmodule\n";
|
||||
assert!(refusal(top, ".*").contains("indexes no module named `nowhere`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_module_declared_twice_is_refused() {
|
||||
let workspace = files(&[
|
||||
("/rtl/sub.sv", SUB),
|
||||
("/rtl/other.sv", SUB),
|
||||
("/rtl/top.sv", "module top;\n logic clk, rst, done;\n sub u_sub (.*);\nendmodule\n"),
|
||||
]);
|
||||
let top = &workspace[2].1.clone();
|
||||
let said = expand_wildcard(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, ".*"))
|
||||
.expect_err("a refusal");
|
||||
assert!(said.contains("declared in more than one indexed file"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_that_does_not_parse_is_refused_on_either_side() {
|
||||
// The cursor's own file.
|
||||
let top = "module top;\n logic clk;\n sub u_sub (.*);\n always @(begin\nendmodule\n";
|
||||
let said = refusal(top, ".*");
|
||||
assert!(said.contains("does not parse"), "{said}");
|
||||
assert!(said.contains("top.sv"), "{said}");
|
||||
|
||||
// ...and the module's.
|
||||
let workspace = files(&[
|
||||
("/rtl/sub.sv", "module sub (input logic clk);\n always @(begin\nendmodule\n"),
|
||||
("/rtl/top.sv", "module top;\n logic clk;\n sub u_sub (.*);\nendmodule\n"),
|
||||
]);
|
||||
let top = workspace[1].1.clone();
|
||||
let said = expand_wildcard(&workspace, &PathBuf::from("/rtl/top.sv"), at(&top, ".*"))
|
||||
.expect_err("a refusal");
|
||||
assert!(said.contains("sub.sv"), "{said}");
|
||||
assert!(said.contains("does not parse"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_port_list_carrying_compiler_directives_is_refused() {
|
||||
let workspace = files(&[
|
||||
(
|
||||
"/rtl/sub.sv",
|
||||
"module sub (\n input logic clk\n`ifdef HAS_RST\n , input logic rst\n`endif\n);\nendmodule\n",
|
||||
),
|
||||
("/rtl/top.sv", "module top;\n logic clk, rst;\n sub u_sub (.*);\nendmodule\n"),
|
||||
]);
|
||||
let top = workspace[1].1.clone();
|
||||
let said = expand_wildcard(&workspace, &PathBuf::from("/rtl/top.sv"), at(&top, ".*"))
|
||||
.expect_err("a refusal");
|
||||
assert!(said.contains("carries compiler directives"), "{said}");
|
||||
assert!(said.contains("depends on the configuration"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_connection_list_carrying_compiler_directives_is_refused() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (\n .clk(clk),\n`ifdef X\n .rst(rst),\n`endif\n .*\n );\nendmodule\n";
|
||||
let said = refusal(top, ".*\n )");
|
||||
assert!(said.contains("connection list carries compiler directives"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wildcard_that_binds_nothing_is_refused_rather_than_deleted() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk), .rst(rst), .done(done), .*);\nendmodule\n";
|
||||
let said = refusal(top, ".*");
|
||||
assert!(said.contains("already connects every port"), "{said}");
|
||||
assert!(said.contains("binds nothing"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_statement_declaring_several_instances_asks_for_a_cursor_on_one() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_a (.*), u_b (.*);\nendmodule\n";
|
||||
let said = refusal(top, "sub u_a");
|
||||
assert!(said.contains("declares 2 instances"), "{said}");
|
||||
assert!(said.contains("put the cursor on the one to expand"), "{said}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_outside_the_workspace_is_refused() {
|
||||
let workspace = files(&[("/rtl/sub.sv", SUB)]);
|
||||
let said =
|
||||
expand_wildcard(&workspace, &PathBuf::from("/rtl/elsewhere.sv"), 0).expect_err("a refusal");
|
||||
assert!(said.contains("is not one of the files lucisv indexes"), "{said}");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// the code action, and what the formatter says
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn the_action_is_offered_at_the_wildcard_with_its_count_in_the_title() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk), .*);\nendmodule\n";
|
||||
let workspace = files(&[("/rtl/sub.sv", SUB), ("/rtl/top.sv", top)]);
|
||||
let actions = port_actions(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, ".*"));
|
||||
let titles: Vec<&str> = actions.iter().map(|a| a.title.as_str()).collect();
|
||||
assert!(titles.contains(&"lucisv: expand .* (2 connections)"), "{titles:?}");
|
||||
// The wildcard is why `propagate` declines here, so it is the only offer.
|
||||
assert_eq!(titles.len(), 1, "{titles:?}");
|
||||
|
||||
// One connection is one connection, not "1 connections".
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk), .rst(rst), .*);\nendmodule\n";
|
||||
let workspace = files(&[("/rtl/sub.sv", SUB), ("/rtl/top.sv", top)]);
|
||||
let actions = port_actions(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, ".*"));
|
||||
assert_eq!(actions[0].title, "lucisv: expand .* (1 connection)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_is_offered_where_the_expansion_would_be_refused() {
|
||||
let top = "module top;\n logic clk, rst, done;\n sub u_sub (.*, .*);\nendmodule\n";
|
||||
let workspace = files(&[("/rtl/sub.sv", SUB), ("/rtl/top.sv", top)]);
|
||||
let actions = port_actions(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, ".*"));
|
||||
assert!(actions.is_empty(), "{:?}", actions.iter().map(|a| &a.title).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_expanded_file_formats_and_formatting_it_again_changes_nothing() {
|
||||
let config = vlog_formatter::Config::default();
|
||||
for top in [
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (.clk(clk), .*);\nendmodule\n",
|
||||
"module top;\n logic clk, rst;\n sub u_sub (\n .clk(clk),\n .* // the rest\n );\nendmodule\n",
|
||||
"module top;\n logic clk, rst, done;\n sub u_sub (\n .*\n );\nendmodule\n",
|
||||
] {
|
||||
let (_, text) = expand(top, ".*").expect("expands");
|
||||
let once = vlog_formatter::format_source(&text, &config)
|
||||
.unwrap_or_else(|e| panic!("the formatter refuses the expansion: {e}\n{text}"));
|
||||
let twice = vlog_formatter::format_source(&once, &config).expect("formats again");
|
||||
assert_eq!(once, twice, "formatting the expansion does not converge");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_escaped_port_name_is_terminated_on_both_sides_of_the_parens() {
|
||||
// An escaped identifier runs to the next whitespace and to nothing else
|
||||
// (IEEE 1800 §5.6.1), so `.\my-port(\my-port)` is one token that swallows
|
||||
// the parens and the rest of the line. The instantiation skeleton learned
|
||||
// this from QA; the expansion writes the same shape.
|
||||
let sub = "module sub (\n input logic \\my-port ,\n input logic clk\n);\nendmodule\n";
|
||||
let top = "module top;\n logic clk;\n logic \\my-port ;\n sub u_sub (.*);\nendmodule\n";
|
||||
let workspace = files(&[("/rtl/sub.sv", sub), ("/rtl/top.sv", top)]);
|
||||
let edit =
|
||||
expand_wildcard(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, ".*")).expect("expands");
|
||||
let text = applied(&workspace, &edit, "/rtl/top.sv");
|
||||
assert!(text.contains("(.\\my-port (\\my-port ), .clk(clk))"), "{text}");
|
||||
let (_, diagnostics) = vlog_parser::parse_source_tolerant(&text);
|
||||
assert!(diagnostics.is_empty(), "{diagnostics:?}\n{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unbound_escaped_port_is_terminated_too() {
|
||||
let sub = "module sub (\n input logic \\my-port ,\n input logic clk\n);\nendmodule\n";
|
||||
let top = "module top;\n logic clk;\n sub u_sub (.*);\nendmodule\n";
|
||||
let workspace = files(&[("/rtl/sub.sv", sub), ("/rtl/top.sv", top)]);
|
||||
let edit =
|
||||
expand_wildcard(&workspace, &PathBuf::from("/rtl/top.sv"), at(top, ".*")).expect("expands");
|
||||
let text = applied(&workspace, &edit, "/rtl/top.sv");
|
||||
assert!(text.contains("(.\\my-port (), .clk(clk))"), "{text}");
|
||||
let (_, diagnostics) = vlog_parser::parse_source_tolerant(&text);
|
||||
assert!(diagnostics.is_empty(), "{diagnostics:?}\n{text}");
|
||||
}
|
||||
@@ -0,0 +1,657 @@
|
||||
# expand-wildcard
|
||||
|
||||
TODO §50 — the first of the §8 refactoring backlog to ship. One engine
|
||||
function, one code action, one command.
|
||||
|
||||
## Goal
|
||||
|
||||
`sub u_x (.clk(clk), .*);` binds every remaining port of `sub` to the
|
||||
same-named signal in the scope the instantiation is written in (IEEE 1800
|
||||
§23.3.2.4). **Expanding** the wildcard writes those bindings out: the
|
||||
refactoring an RTL engineer reaches for the moment a port list is about to
|
||||
diverge from the wrapper around it, and the one the ports engine already
|
||||
refuses to edit around — `add_port` and `remove_port` warn and leave a `.*`
|
||||
site alone, and `propagate_ports` declines a wildcard outright, because none of
|
||||
them can rewrite a connection nobody wrote. After this round the user can turn
|
||||
the wildcard into text first and then use all three.
|
||||
|
||||
The engine is `vlog_refactor::expand_wildcard`, so Vim, VS Code and any future
|
||||
CLI get identical behavior; `lucisv_server` maps the protocol and decides
|
||||
nothing. Whole-edit-or-nothing, through the ports engine's lexical splice and
|
||||
its "the file still parses" verifier: an `Ok` is safe to apply, an `Err` is a
|
||||
sentence for the user and no edits at all.
|
||||
|
||||
## API as built
|
||||
|
||||
```rust
|
||||
// crates/vlog_refactor/src/lib.rs
|
||||
pub fn expand_wildcard(files: &[(PathBuf, String)], file: &Path, offset: u32)
|
||||
-> Result<RefactorEdit, String>;
|
||||
// new beside `sites_phrase`, for the server's title arithmetic:
|
||||
pub fn is_sites_phrase(phrase: &str) -> bool;
|
||||
```
|
||||
|
||||
`files`, `RefactorEdit`, `TextEdit` and the `Err(String)`-is-a-sentence
|
||||
convention are M2's, unchanged. `port_actions` gained a third offer, so the
|
||||
code-action path needed no new entry point at all.
|
||||
|
||||
## The rule, exactly as implemented
|
||||
|
||||
At the cursor's instantiation — the instance whose span covers the offset, or
|
||||
the only instance of the statement whose module name it covers, which is
|
||||
`propagate_ports`'s own rule:
|
||||
|
||||
1. The connection list must be **named** and hold exactly **one** `.*`.
|
||||
2. Every port the instantiated module declares that the list does **not**
|
||||
name explicitly is what the wildcard stands for, in the module's
|
||||
**declaration order**. `.clk`, `.clk()` and `.clk(x)` all count as
|
||||
explicit — they are connections the source wrote, so `.*` never bound
|
||||
those ports.
|
||||
3. For each of them, lucisv asks `vlog_semantic` what the name means in the
|
||||
scope the *instance name* sits in — the generate block's, then its
|
||||
parents', up to the module's:
|
||||
- **a net, a variable, or a port** of that name → `.name(name)`;
|
||||
- **anything else, or nothing** → `.name()`, and a warning naming every
|
||||
port left that way.
|
||||
|
||||
"A signal" is read strictly, and that is the whole of the LRM rule that
|
||||
matters here: a **parameter**, a **localparam**, a **genvar**, a **type**,
|
||||
an **instance** or a **task/function argument** of the same name is *not* a
|
||||
net or a variable, so `.*` does not bind it. This is a narrower set than
|
||||
the one `add_port`/`propagate_ports` use when they *write* a connection
|
||||
(`find::visible_in`, which happily writes `.p(p)` for a parameter, because
|
||||
there the user asked for a connection and a parameter is a legal
|
||||
expression). Here the question is not "what could be connected" but "what
|
||||
*was* connected", and connecting an output port to a constant because a
|
||||
`localparam` happened to share its name would be a legal-looking, silent,
|
||||
wrong expansion. The two readers share one scope walk
|
||||
(`find::kind_visible_in`) so they cannot come to disagree about *which*
|
||||
declaration a name means, only about whether that kind counts.
|
||||
4. A port with nothing to bind to is one the wildcard never bound either —
|
||||
the compiler would have rejected the instantiation — so `.name()` plus the
|
||||
warning is the honest answer, and saying it out loud is half the point of
|
||||
the expansion. (It found two real ones in OpenTitan; see Acceptance.)
|
||||
|
||||
### Escaped identifiers
|
||||
|
||||
A port named `\my-port` is written `.\my-port (\my-port )`, with the space an
|
||||
escaped identifier needs after it: an escaped identifier runs from its `\` to
|
||||
the next **whitespace** and to nothing else (IEEE 1800 §5.6.1), so
|
||||
`.\my-port(\my-port)` would be one enormous token swallowing the parens, the
|
||||
comma and the rest of the line. `instantiate.rs` learned this from a QA
|
||||
finding on the skeleton renderer; `ends_escaped` is now `pub(crate)` and the
|
||||
expansion asks the same question rather than spelling the rule a second time.
|
||||
Two behavior tests pin it, bound and unbound.
|
||||
|
||||
### Layout
|
||||
|
||||
The `.*` element is **replaced**, in place, by the generated connections. The
|
||||
list's own layout is copied the way `append_to_list` copies it: the gap before
|
||||
the wildcard (from the previous element, or from the list's `(`) decides
|
||||
**one connection per line** — at the wildcard's own indentation — from
|
||||
**inline**, `, `-separated. Refactored output is *edited source*, not
|
||||
reformatted source (umbrella Handshakes); the user runs the formatter
|
||||
afterwards if they want more, and the acceptance tests below prove the
|
||||
formatter is happy with what is written.
|
||||
|
||||
### Comments
|
||||
|
||||
- A comment written **before** the `.*` is outside the replaced span and stays
|
||||
exactly where it is, which puts it before the first generated connection.
|
||||
- A comment written **after** it on the same line (`.* // and the rest`) gets
|
||||
the `append_to_list` treatment, for the same reason: the comma is written
|
||||
*before* the comment and the remaining connections after it, so the comment
|
||||
stays with the **first** generated connection instead of drifting onto the
|
||||
last, and no `,` is ever written inside a `//`.
|
||||
- A comment written **inside** the element (`. /* here */ *`) is inside the
|
||||
span the expansion replaces, so the verifier's comment rule refuses the
|
||||
whole refactoring. Comments are never dropped (invariant 3), and lucisv will
|
||||
not decide where that one should move.
|
||||
|
||||
## The refusal list — exact
|
||||
|
||||
`expand_wildcard` refuses when:
|
||||
|
||||
1. **The position is not an instantiation** — *"there is no module
|
||||
instantiation at this position."*
|
||||
2. **The statement declares several instances** — *"this statement declares 2
|
||||
instances of `sub`; put the cursor on the one to expand."*
|
||||
3. **The instance is a `bind` directive's** — *"`u_x` is instantiated by a
|
||||
`bind` directive, where `.*` binds in the target's scope rather than in
|
||||
this one; lucisv does not expand it there."* §23.3.2.4 resolves a bound
|
||||
instance's wildcard in the *target's* scope, which lucisv would have to
|
||||
elaborate a hierarchy to know. Out of scope for this round, and said so.
|
||||
(This is the majority of real `.*` sites in OpenTitan — see Acceptance.)
|
||||
4. **The list connects positionally** — *"`u_x` connects `sub`'s ports by
|
||||
position; there is no `.*` to expand."*
|
||||
5. **There is no `.*`** — *"`u_x` writes no `.*` to expand."*
|
||||
6. **There is more than one** — *"`u_x` writes `.*` 2 times, which is illegal;
|
||||
lucisv will not guess what it means."*
|
||||
7. **Either file carries a parse diagnostic** — *"top.sv does not parse (… at
|
||||
line N), so lucisv will not expand a `.*` in it."* Stricter than the
|
||||
verifier's "no *new* diagnostic" rule on purpose: a connection list lucisv
|
||||
misread is a list whose ports it would connect a second time, and a
|
||||
duplicate connection is not a refactoring, it is corruption.
|
||||
8. **The instantiated module's port list carries compiler directives** —
|
||||
*"`sub`'s port list carries compiler directives, so which ports `.*` binds
|
||||
depends on the configuration; lucisv does not preprocess, so it made no
|
||||
edits."* Writing every arm's ports out produces a connection list no
|
||||
configuration ever had. The same sentence guards the **connection list's**
|
||||
own directives, where lucisv equally cannot tell which connections are
|
||||
explicit in which arm.
|
||||
9. **The module is unknown or declared twice** — `locate_module`'s two
|
||||
existing sentences, unchanged.
|
||||
10. **Nothing is left to bind** — *"`u_x` already connects every port `sub`
|
||||
declares, so its `.*` binds nothing."* Not in the plan's list; derived
|
||||
from `propagate_ports`'s refusal 16 (*"a 'did nothing' success is a worse
|
||||
answer than a sentence"*). Deleting the `.*` instead would be a different
|
||||
refactoring — a removal, with a removal's comma and comment problems —
|
||||
and nobody asked for it.
|
||||
11. **The file is outside the in-scope set**, and **verification fails**
|
||||
(the five checks in `docs/features/refactor-ports/README.md`), the ports
|
||||
engine's own rules unchanged.
|
||||
|
||||
Refusals 3–8 and 10 are pinned by a behavior test each; 1, 2, 4, 5, 6, 9 and
|
||||
the outside-the-scope one too. Nothing is offered as a code action where the
|
||||
refactoring would be refused, so the lightbulb never appears to explain itself.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **The `.*` is the only thing the edit touches.** Nothing outside the
|
||||
cursor's own file is read for the edit itself (the module's declaration is
|
||||
read, not edited), so `RefactorEdit` names one file. That is what makes the
|
||||
lazy code action exact rather than optimistic: the offer's two files —
|
||||
buffer plus declaration — are already everything the resolve will read.
|
||||
- **A third offer costs a third attempt.** `port_actions` tries three
|
||||
refactorings where it tried two, and each one builds its own `Scope` (the
|
||||
index over the files it was handed) before it can refuse. So an offered
|
||||
menu is now three index builds over that file set rather than two — but the
|
||||
file set is the thing §37.1 already shrank: on the lazy path it is the
|
||||
buffer plus one declaration, and the gate (`may_have_port_action`, one parse
|
||||
of one file, no workspace, no I/O) still answers "nothing here" for almost
|
||||
every cursor before any of the three runs. Nothing in this round re-reads
|
||||
the fan-out that §37.1 took off the cursor path. A `Scope` shared by all
|
||||
three attempts is the obvious next economy and is deliberately not taken
|
||||
here: it changes the signatures of three shipped refactorings for a saving
|
||||
only the eager path sees.
|
||||
- **lucisv does not elaborate.** "Is a signal called `p` in scope here?" is a
|
||||
lexical-scope question `vlog_semantic` answers. A name that would come from
|
||||
a wildcard package import lucisv cannot resolve reads as *not in scope*, so
|
||||
the port is written `.p()` — visibly, in the warning, never `.p(p)` on a
|
||||
guess. This is the ports engine's standing assumption; the difference is
|
||||
that here a wrong "not in scope" writes an unconnected port rather than a
|
||||
`/* TODO */`, which is why the warning names every one of them.
|
||||
- **lucisv does not preprocess**, so a port list or a connection list split
|
||||
across `` `ifdef`` arms is refused rather than read straight through (the
|
||||
refusals above). This is stricter than `add_port`, which warns and appends
|
||||
outside every arm; appending one element is configuration-independent,
|
||||
while enumerating a whole port set is not.
|
||||
- **A module name is unique in scope**, and the index is the server's
|
||||
authority on where it is declared — the ports engine's assumptions,
|
||||
unchanged.
|
||||
|
||||
## Handshakes
|
||||
|
||||
**Consumed from `vlog_parser`** (no change required): `parse_source_tolerant`
|
||||
and its `ParseDiagnostic` (refusal 7), `LineIndex`, `TextRange`, and
|
||||
`ast::{Connection, Connections, Instance, Instantiation, Item, ListElem}` —
|
||||
`Connection::name == "*"` is how the wildcard is recognized, and
|
||||
`Connection::span` (the element's *code* extent, comments outside it) is what
|
||||
makes the replacement exact. `Instance::conn_directives` is what makes refusal
|
||||
8's second half possible.
|
||||
|
||||
**Consumed from `vlog_semantic`** (no change required, nothing patched):
|
||||
`Semantics::{scopes, symbols, symbol}`, `Scope::{span, parent, lookup_local}`,
|
||||
and `SymbolKind` — the kind is now *read* rather than only matched against a
|
||||
fixed set (below).
|
||||
|
||||
**Changed inside `vlog_refactor`** — four edits to existing files, all of them
|
||||
pure factorings with no behavior change:
|
||||
|
||||
- `ports/find.rs`: `collect_instantiations` is now a wrapper over
|
||||
`walk_instantiations`, which reports of each instantiation whether it is a
|
||||
`bind` directive's own. Same walk, same order, one extra bit; every existing
|
||||
caller ignores the bit.
|
||||
- `ports/find.rs`: `visible_in`'s scope walk moved into `kind_visible_in`,
|
||||
which returns the `SymbolKind` it found; `visible_in` is that function plus
|
||||
the kind set it always had, so `add_port`, `propagate_ports` and
|
||||
`instantiate.rs` answer byte-for-byte as before.
|
||||
- `ports/mod.rs`: `expand_wildcard`, `expansion` (the edit plus its connection
|
||||
count) and the third `port_actions` offer; plus `is_sites_phrase` beside
|
||||
`sites_phrase`.
|
||||
- `instantiate.rs`: `ends_escaped` is `pub(crate)` instead of private. One
|
||||
word; no call site changed.
|
||||
|
||||
**Promised to `lucisv_server`**: everything the other port refactorings
|
||||
promise. `expand_wildcard` does not panic, returns no partial edit, sorts and
|
||||
de-overlaps its edits, and its warnings are informational.
|
||||
`PortAction.title` is user-facing text the server does not rewrite — with one
|
||||
new obligation, which is why `is_sites_phrase` exists: the server *does*
|
||||
rewrite the count in an offered title from its index, and the expansion's
|
||||
count is not an instantiation census. The server now asks before recounting.
|
||||
|
||||
**Changed in `lucisv_server`** (protocol layer only): `EXPAND_WILDCARD`
|
||||
(`lucisv.expandWildcard`) added to `ports::commands()` and to
|
||||
`ports::execute`; `ports::counted` gated on `vlog_refactor::is_sites_phrase`.
|
||||
The dispatch arm, the capability advertisement and the code-action path needed
|
||||
no change — commands are advertised from `commands()` and every
|
||||
`workspace/executeCommand` already routes through `ports::execute`. **The VS
|
||||
Code extension needed nothing**: `editors/vscode/package.json` contributes only
|
||||
its own webview commands, and server commands are discovered over LSP.
|
||||
|
||||
**Requested of nobody.** No change was needed in `vlog_parser`,
|
||||
`vlog_semantic`, `vlog_formatter` or `lucisv_core`.
|
||||
|
||||
**One new dev-dependency**: `vlog_formatter` on `vlog_refactor`, **tests
|
||||
only**, the arrangement `vlog_linter` already uses and with the same
|
||||
justification written into `Cargo.toml`: the acceptance tests assert that what
|
||||
the expansion writes is something the formatter accepts and leaves alone the
|
||||
second time, and that cross-tool guarantee cannot be asserted from either
|
||||
crate alone. The library still depends on `vlog_parser` + `vlog_semantic`
|
||||
alone (`cargo tree -p vlog_refactor -e normal`), and no cycle is possible:
|
||||
`vlog_formatter` depends on `vlog_parser` and nothing else.
|
||||
|
||||
## The LSP surface
|
||||
|
||||
| Surface | What it says |
|
||||
|---|---|
|
||||
| Code action, kind `refactor.rewrite.lucisv.ports` | *"lucisv: expand .* (3 connections)"* — offered at a `.*` under the cursor, lazily (`offers` → `resolve`, §37.1) or eagerly (`code_actions`), whichever the client supports. |
|
||||
| `lucisv.expandWildcard [uri, Position]` | The same edit for a client with no lightbulb — a Vim user's keybinding. |
|
||||
|
||||
The count is the connections the wildcard becomes, and it is exact in the
|
||||
offer already: the offer's file set (buffer + declaring file) is everything
|
||||
the expansion reads. It is written `1 connection` for one, which is why the
|
||||
plan's *"(N connections)"* is a shape rather than a literal.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] 50.1 `expand_wildcard` engine (`ports/expand.rs`, 308 lines, 233 of
|
||||
them code) + every refusal above
|
||||
- [x] 50.1 the LRM kind rule, sharing one scope walk with `visible_in`
|
||||
- [x] 50.1 layout (multi-line vs inline) and the three comment positions
|
||||
- [x] 50.2 code action through the lazy offer path, with `is_sites_phrase`
|
||||
keeping the index from recounting its title — pinned at the level that
|
||||
matters rather than as a predicate unit test: the server test
|
||||
`the_wildcard_action_is_offered_lazily_and_resolves_to_the_eager_edit`
|
||||
asserts the offered title is `lucisv: expand .* (1 connection)` in a
|
||||
workspace whose instantiation census would have said something else,
|
||||
and the e2e session asserts the same string over the wire
|
||||
- [x] 50.2 `lucisv.expandWildcard` in `commands()` / `execute`
|
||||
- [x] 50.1 escaped identifiers terminated on both sides of the parens
|
||||
- [x] Tests: 32 behavior tests in `vlog_refactor/tests/expand.rs`, 1 corpus
|
||||
acceptance test in `tests/corpus.rs`, 3 in `lucisv_server`'s `ports.rs`,
|
||||
1 e2e session over the wire
|
||||
- [x] Gates: `cargo fmt` per crate, clippy `--all-targets` clean, the
|
||||
workspace suite, the corpus gate, byte-identity vs 0.45.0, the VS Code
|
||||
smoke test
|
||||
- [x] OpenTitan read-only census and ten scratch expansions
|
||||
- [ ] Deferred, deliberately: a `.*` inside a `bind` directive (refusal 3) —
|
||||
it needs the target's scope, which is elaboration, not lexical lookup.
|
||||
It is the *majority* of real wildcard sites in OpenTitan, so it is worth
|
||||
a backlog line of its own.
|
||||
- [ ] Deferred: the inverse refactoring (named connections → `.*`), which is
|
||||
§8's list, not this round's.
|
||||
|
||||
## Docs to apply at merge (lead)
|
||||
|
||||
`README.md`, `docs/topo.md`, `docs/repository-analysis.md` and `docs/site/`
|
||||
are the lead's; the text for them is here rather than edited in place.
|
||||
|
||||
**`README.md` — the refactoring list** gains a row beside
|
||||
"connect missing ports":
|
||||
|
||||
> | **expand `.*`** | Writes a wildcard connection out as the named
|
||||
> connections it stands for, in the module's declaration order — a port with
|
||||
> no same-named signal in scope becomes `.p()` and is named in a warning.
|
||||
> Code action at the `.*`, or `lucisv.expandWildcard`. |
|
||||
|
||||
**`docs/site/` (editors / language-tools page)** — the same sentence in the
|
||||
code-action list: *"expand `.*` — the wildcard connection written out as the
|
||||
`.p(p)` connections it stands for, so the port list can then diverge from the
|
||||
wrapper around it."*
|
||||
|
||||
**TODO.md §8** (the refactoring backlog): the `.*`-expansion line gains
|
||||
*"— shipped in 0.46.0, `docs/features/expand-wildcard/README.md`"*, and the
|
||||
list gains a new backlog entry: *"expand a `.*` written in a `bind` directive
|
||||
(needs the target's scope — elaboration, not lexical lookup)."*
|
||||
|
||||
**`docs/topo.md`**: one new edge to record — `vlog_refactor ──▶
|
||||
vlog_formatter` **(dev-dependency, tests only)**, the same shape §2's
|
||||
`vlog_linter ──▶ vlog_formatter` dev edge already has. No production edge
|
||||
changed.
|
||||
|
||||
## Work log
|
||||
|
||||
**2026-09-05 — dev agent.** Built `ports/expand.rs`, the third `port_actions`
|
||||
offer, and the fourth command. The decisions worth recording:
|
||||
|
||||
- **A replacement, not an append plus a deletion.** `propagate_ports` was the
|
||||
obvious template, and it appends — but the `.*` has to *go*, and the
|
||||
cleanest expression of that is one `TextEdit` whose range is the element's
|
||||
own span. `check::pieces_match` already handles a replacement exactly (it
|
||||
skips old pieces overlapping a non-empty edit range and splices the edit's
|
||||
own pieces in at its start); `Shift::map` already handles the length change
|
||||
(`a_longer_replacement_shifts_forward` was written for it in M2). So the
|
||||
verifier needed nothing new, which is the outcome hard invariant 4 wants:
|
||||
no widening of anybody's forgiveness, no new attack surface to test.
|
||||
- **The comment rule fell out.** Because the edit's range is the element's
|
||||
*code* span, a comment before or after the `.*` is not inside it and is
|
||||
simply not touched; a comment *inside* it is, and the splice verifier's
|
||||
comment rule refuses the whole thing. Two of the three comment cases are
|
||||
therefore properties of the span choice rather than code, and the third is
|
||||
a refusal rather than a guess. The one piece of code is the
|
||||
comma-before-the-line-comment split, lifted verbatim from
|
||||
`append_to_list`'s reasoning.
|
||||
- **Parameters are the crux, and they get their own kind reader.** The LRM
|
||||
binds `.*` to a net or a variable. `find::visible_in` — the "may lucisv
|
||||
write `.p(p)` here" test the other two refactorings use — says yes to
|
||||
parameters, localparams, genvars and task arguments as well, and that is
|
||||
right *for them*: the user asked for a connection and a parameter is a legal
|
||||
expression. It is wrong here, where the question is what the wildcard
|
||||
already bound. Rather than adding a flag to `visible_in`, the scope walk was
|
||||
factored into `kind_visible_in` (which returns the kind) and each caller
|
||||
states its own set. Both readers therefore agree about which declaration a
|
||||
name means — the thing that must never diverge — and disagree only where
|
||||
they should.
|
||||
- **Two refusals stricter than `add_port`'s.** A file with a parse diagnostic,
|
||||
and a list carrying compiler directives, are *warnings* or read-throughs
|
||||
elsewhere in the ports engine. Here they are refusals, because this
|
||||
refactoring enumerates a whole port set rather than appending one element:
|
||||
a misread list connects a port twice, and an `` `ifdef``-split port list
|
||||
expands into a connection list no configuration ever had. Both are cheap to
|
||||
detect and impossible for the verifier to catch (the result parses, resolves
|
||||
and matches its shape — it is simply not what the source meant).
|
||||
- **`is_sites_phrase` was the one real surprise.** `ports::counted` in the
|
||||
server rewrites *any* offered title ending in `(…)` with the index's
|
||||
instantiation count, which would have turned "expand .* (3 connections)"
|
||||
into "expand .* (updates 5 instantiations)" — a wrong sentence produced by
|
||||
a function that had never been wrong before, because until now every title
|
||||
with a count carried the same count. The predicate lives next to
|
||||
`sites_phrase` in the engine so the phrase has one spelling and one reader.
|
||||
- **The bind refusal is not a corner case.** 24 of the 31 `.*` sites under
|
||||
OpenTitan's `hw/ip` are inside a `bind` directive. Refusing them is correct
|
||||
(§23.3.2.4 resolves those in the target's scope), and it is the reason the
|
||||
acceptance sample had to be drawn from a wider tree than `hw/ip` to reach
|
||||
ten — recorded in Acceptance and as a backlog line above.
|
||||
|
||||
Checks at the end are in Acceptance and in the gate list. No
|
||||
`unwrap`/`expect`/`panic!` and no `unsafe` in any library path (test modules
|
||||
only); `expand.rs` is 308 lines with no function over 45, and every file it
|
||||
touches stayed inside the size rule — `ports/mod.rs` 433, `ports/find.rs` 283,
|
||||
`lucisv_server/src/ports.rs` 1 430 of which 981 are its `#[cfg(test)]` module.
|
||||
|
||||
## Gates
|
||||
|
||||
All guarded (`tools/guard.sh`, 8 GB / 30 min defaults); no guard kill.
|
||||
|
||||
- **fmt**: `cargo fmt -p vlog_refactor`, `cargo fmt -p lucisv_server`;
|
||||
`cargo fmt --all -- --check` clean.
|
||||
- **clippy**: `cargo clippy --all-targets`, **0 warnings**, and no new
|
||||
`#[allow]` anywhere in the diff.
|
||||
- **suite**: `cargo test --workspace` — **3 876 passed, 0 failed, 44 ignored**
|
||||
across 50 test binaries (baseline 3 839, +37: 32 behavior, 1 corpus, 3
|
||||
server unit, 1 e2e).
|
||||
- **corpus gate**: `tools/corpus_check.sh` — **814/820 (99.3%)**, the same six
|
||||
known parse errors (`ibex` compare_helper / riscv_core_setting.tpl /
|
||||
latch_map.v / riscv_instr_cover_group, `picorv32` romload testbench /
|
||||
smtbmc mulcmp), **0 verification errors, 0 crashes**.
|
||||
- **formatter byte-identity**: `lucisv format --stdout` over all corpus files,
|
||||
this build vs `~/.cache/lucisv-baselines/lucisv-0.45.0` — **854 checked, 0
|
||||
differing**, 6 refused by both. `git diff` over `vlog_formatter`,
|
||||
`vlog_parser` and `verify.rs` is empty; this round touched neither.
|
||||
- **vsix smoke**: `node editors/vscode/smoke.js target/release/lucisv-server`
|
||||
— OK, 20 messages.
|
||||
- **opentitan after the round**: `git -C ~/repo/opentitan status --porcelain`
|
||||
shows only the three pre-existing modifications. Every run over it was
|
||||
read-only, and every edited copy went to the session scratchpad.
|
||||
|
||||
## Acceptance
|
||||
|
||||
### The corpus
|
||||
|
||||
`cargo test -p vlog_refactor --test corpus` gained
|
||||
`a_wildcard_expanded_in_the_corpus_is_something_the_formatter_accepts`: the
|
||||
first three corpus files with a `.*` are expanded into an in-memory copy and
|
||||
the copy must format, and formatting it twice must not move it. It expands
|
||||
`common_cells`' `cdc_2phase_clearable_tb.sv`, `cdc_2phase_synth.sv` and
|
||||
`cdc_2phase_tb.sv` (~2.4 s each in debug, the index build over 860 files) and
|
||||
refuses the three `formal/*_properties.sv` sites — every one of them a `bind`.
|
||||
|
||||
### OpenTitan (read-only)
|
||||
|
||||
Counted with the plan's grep and with the engine's own scan, which also sees a
|
||||
`.*` whose `,`/`)` is on the next line:
|
||||
|
||||
| Tree | Files | `.*` sites | Expanded | Refused |
|
||||
|---|---|---|---|---|
|
||||
| `hw/ip` | 1 807 | **31** (29 by line-based grep) | 7 | 24, every one a `bind` |
|
||||
| `hw` (all of OpenTitan's Verilog) | 3 979 | **66** | **9** | 57: **50** `bind`, **6** `pinmux` declared in three tops, **1** `ibex_top`'s `` `ifdef``-split port list |
|
||||
|
||||
**Deviation from the plan, stated plainly: ten expandable sites do not
|
||||
exist.** The plan asked for ten scratch expansions; OpenTitan holds nine.
|
||||
Every `.sv`/`.svh`/`.v` file in the repository is under `hw/` (checked), and
|
||||
of its 66 wildcard sites, 57 are refused — 50 of them by the `bind` rule,
|
||||
which is correct and is the backlog line above. So the sample is **all nine**
|
||||
of them rather than a chosen ten, plus the three corpus expansions in the test
|
||||
suite: twelve real-world expansions, all verified the same way. Each of the
|
||||
seven refusal categories that fired did so for a reason on the list, including
|
||||
two the synthetic tests could only fake: `pinmux` really is declared three
|
||||
times in OpenTitan (one per top), and `ibex_top`'s port list really is split
|
||||
across `` `ifdef`` arms.
|
||||
|
||||
Every expansion was written to a **copy** under the session scratchpad;
|
||||
nothing was written into `/Users/guoliangchen/repo/opentitan`, and
|
||||
`git -C … status --porcelain` shows the same three pre-existing modifications
|
||||
before and after (`hw/ip/aes/dv/tb/tb.sv`,
|
||||
`hw/top_darjeeling/ip/ast/rtl/ast.sv`, `hw/top_earlgrey/ip/ast/rtl/ast.sv`).
|
||||
|
||||
Each of the nine: the copy parses with **zero** diagnostics, formats, formats
|
||||
again to the same bytes, and holds the **same instance count** as the
|
||||
original. Two of them carry a warning, and both are real findings rather than
|
||||
lucisv guessing:
|
||||
|
||||
- `kmac/fpv/tb/sha3_fpv.sv` — `u_sha3`'s `.*` covers nine ports of `sha3`
|
||||
(`rand_update_o`, `squeezing_o`, `block_processed_o`, `run_req_o`,
|
||||
`run_ack_i`, `lc_escalate_en_i`, `sparse_fsm_error_o`, `count_error_o`,
|
||||
`keccak_storage_rst_error_o`) that the FPV wrapper's own header does not
|
||||
declare. The wrapper has drifted behind the module it wraps; the wildcard
|
||||
was hiding it, and the expansion says so.
|
||||
- `kmac/fpv/tb/sha3pad_fpv.sv` — the same story for `u_keccak`, five ports.
|
||||
|
||||
The five `aes/dv/err_injection_if/fi_*_wrapper.sv` expansions are the
|
||||
textbook case: `fi_core_if fi_if (.*)` becomes
|
||||
`fi_core_if fi_if (.clk_i(clk_i), .rst_ni(rst_ni), .aes_ctrl_cs(aes_ctrl_cs))`.
|
||||
The last two are `vendor/lowrisc_ibex`'s icache agent interfaces.
|
||||
|
||||
Reproduced by a throwaway probe binary in the session scratchpad
|
||||
(`otprobe`), which depends on `vlog_refactor` + `vlog_formatter` +
|
||||
`vlog_parser` by path, walks a tree read-only, and writes every edited copy
|
||||
into the scratchpad. Nothing of it is checked in.
|
||||
|
||||
## QA log
|
||||
|
||||
**2026-09-05 — QA agent.** Attacked the engine directly
|
||||
(`vlog_refactor::expand_wildcard`, temporary `#[test]`s added and removed —
|
||||
`tests/zz_qa_expand_attack.rs`, `tests/zz_qa_corpus_sweep.rs`, never
|
||||
committed) plus the shipped suites, the two full-workspace gates, a
|
||||
full-`hw/` opentitan census (not just the plan's ten), and a diff of every
|
||||
opentitan scratch expansion against its original. Verdict: **PASS**.
|
||||
|
||||
### LRM-rule matrix (18 scratch tests, all against a fresh build)
|
||||
|
||||
| # | Case | Result |
|
||||
|---|---|---|
|
||||
| enclosing module's own port | binds (`.clk(clk)`) | as specified |
|
||||
| typedef of the same name | not bound, `.done()` + warning | as specified |
|
||||
| instance name of the same name | not bound, `.done()` + warning | as specified |
|
||||
| instantiation lexically inside a function body | no panic (refusal or edit, either is fine — the plan only asks for no crash) | no crash |
|
||||
| sibling generate block's declaration | not visible, `.done()` + warning | as specified |
|
||||
| declared *after* the instantiation, module scope | still visible and bound | as specified — declaration order does not matter |
|
||||
| `import pkg::*` bringing a same-named package variable into scope | **not bound** — `.name()` + warning, exactly as an unrelated name would be | matches the README's stated assumption, see below |
|
||||
| port name shared by both the instantiated and enclosing module | binds (the common case) | as specified |
|
||||
| width/type mismatch (`input logic [7:0] clk` vs a 1-bit `clk` in scope) | still binds by name, no warning | as specified — lucisv cannot check types, README says so |
|
||||
| interface port (`bus_if.master b`, interface instance `bus_if b()` of the same name) | **not bound** — `.b()` + warning | see finding QA-1 below |
|
||||
| escaped port name `\my-port` | bound and terminated on both sides of the parens (`.\my-port (\my-port )`), and unbound the same way | dev's own tests, re-verified |
|
||||
| port with an unpacked dimension (`input logic [7:0] data [4]`) | binds (`.data(data)`) | as specified |
|
||||
|
||||
None of the eighteen attack tests found a mis-binding (an output silently
|
||||
tied to a parameter, a genvar, a typedef, an instance, or anything else the
|
||||
LRM does not call a signal) or a crash. Two are worth recording explicitly:
|
||||
|
||||
- **The package-import choice, pinned.** A name reaching the instantiating
|
||||
scope only through `import pkg::*;` is read as **not in scope**: `.*`
|
||||
writes `.name()` and warns, exactly as if the name did not exist anywhere.
|
||||
Traced to source: `kind_visible_in`
|
||||
(`crates/vlog_refactor/src/ports/find.rs:214-253`) walks
|
||||
`Scope::lookup_local` up the `parent` chain only, and never reads
|
||||
`Scope.imports` — the second, separate lookup
|
||||
`vlog_semantic::resolve::{lexical, unit}` perform to make a wildcard
|
||||
import's names resolvable for *reference* resolution
|
||||
(`crates/vlog_semantic/src/resolve.rs:607-684`). So `vlog_semantic`'s own
|
||||
full resolver *can* see a wildcard-imported name; `kind_visible_in`
|
||||
deliberately (per the README's Assumptions section) does not re-implement
|
||||
that half of it. This matches the feature's stated assumption
|
||||
word-for-word ("a name that would come from a wildcard package import
|
||||
lucisv cannot resolve reads as *not in scope*") — **not a defect**, a
|
||||
documented, safe-by-construction limitation: it under-expands (leaves a
|
||||
port unconnected and says so) rather than mis-expands. Filing it here
|
||||
because the plan asked to "pin it and report the choice."
|
||||
- **QA-1 (LOW, pre-existing, not introduced by this round): interface
|
||||
instances are never a `.*` target.** `bus_if b(); sub u_sub(.*)` where
|
||||
`sub` declares `bus_if.master b` leaves `.b()` unconnected with a warning,
|
||||
even though the interface instance `b` is exactly the identifier IEEE 1800
|
||||
§23.3.2.4 means to bind an interface port to. Root cause: an interface
|
||||
instantiation gets `SymbolKind::Instance`
|
||||
(`crates/vlog_semantic/src/bind/item.rs:306`, the same kind a module
|
||||
instantiation gets — interfaces are modeled as `Module`s with a different
|
||||
keyword), and `signal_visible`'s allowed set
|
||||
(`crates/vlog_refactor/src/ports/expand.rs:266-270`) is `Net | Var | Port`
|
||||
only. This is not new: `find::visible_in`, which `add_port` and
|
||||
`propagate_ports` already share, excludes `Instance` from its own allowed
|
||||
set too (`crates/vlog_refactor/src/ports/find.rs:203-217`), so no port
|
||||
refactoring in the engine today treats an interface instance as a
|
||||
connectable signal by name. Nothing in this round narrowed that — it is
|
||||
inherited, and it fails safe (unconnected + warned, never mis-bound) — but
|
||||
it means every interface-port wildcard site in a design is likely to
|
||||
surface a spurious warning rather than a clean bind. Worth a backlog line
|
||||
for the ports engine generally, not a blocker for §50.
|
||||
|
||||
### Text/layout and refusals
|
||||
|
||||
Re-verified against source and by test: trailing-comma legality (no result
|
||||
ever ends `,)` or has a dangling comma before a line comment), idempotency
|
||||
(expanding the result a second time refuses with the exact "writes no `.*`
|
||||
to expand" sentence; formatting twice converges; re-expanding the *formatted*
|
||||
result also correctly refuses), comment-count preservation, `#(...)`
|
||||
parameterized instantiations, and a cursor placed inside one instance of a
|
||||
two-instance statement (`sub u_a (.*), u_b (.*);`) expanding only that
|
||||
instance rather than tripping the "declares 2 instances" refusal — confirmed
|
||||
this refusal fires only when the cursor is on the shared module name/keyword,
|
||||
matching `propagate_ports`'s documented rule. All eleven refusal sentences
|
||||
in the README's list were exercised (by the dev's own 32-test suite, which
|
||||
this session re-ran clean) and match character-for-character.
|
||||
|
||||
**Server, cursor away from the `.*`:** a cursor placed on `.clk(clk)` inside
|
||||
the *same* instantiation as a `.*` still offers `lucisv: expand .* (2
|
||||
connections)` — the cursor rule is instance-level (any offset inside the
|
||||
instance's span), not token-level, matching `propagate_ports`'s and
|
||||
`remove_port`'s own precedent. This is not a bug: the plan's "only the port
|
||||
actions that apply" is satisfied — every offered action is one that would
|
||||
actually succeed at that instance, and none is limited to the exact `.*`
|
||||
token by design elsewhere in the engine either.
|
||||
|
||||
### Corpus (full sweep, not a sample)
|
||||
|
||||
Independently re-implemented the dev's own `.*` census (a `.*` followed by
|
||||
`,`/`)`, matching the engine's own scan rather than a naïve line grep) and
|
||||
ran it over every corpus file, not just the first three the dev's acceptance
|
||||
test samples: **21 sites, 11 expanded, 10 refused** — 6 `bind` directives, 2
|
||||
"declared in more than one indexed file" (`formal_tb`, genuinely declared
|
||||
twice under `corpus/ibex/formal/`), 1 compiler-directives-in-the-port-list
|
||||
(`ibex_top`), 1 "no module instantiation at this position" (a `.*` mentioned
|
||||
inside a *comment* in `formal_tb_frag.svh`, correctly refused rather than
|
||||
corrupting anything). Every one of the 11 expansions: same instance count
|
||||
before/after, zero parse diagnostics afterward, formats, and converges on a
|
||||
second format. No panics anywhere in the sweep (38.7 s under
|
||||
`tools/guard.sh`, no kill).
|
||||
|
||||
### OpenTitan (read-only, full `hw/`, not a ten-site sample)
|
||||
|
||||
Reproduced independently with a throwaway probe (`otqa`, path-dependent on
|
||||
`vlog_refactor`/`vlog_formatter`/`vlog_parser`, built and run under
|
||||
`tools/guard.sh -m 8 -t 600`, nothing checked in): **66 sites, 9 expanded, 57
|
||||
refused (50 bind, 6 declared-twice/pinmux, 1 compiler-directives/`ibex_top`)
|
||||
— exactly the dev's table.** `git -C ~/repo/opentitan status --porcelain`
|
||||
showed only the three pre-existing modifications both before and after.
|
||||
|
||||
Diffed each of the nine scratch expansions against its opentitan original:
|
||||
**every diff touches only the `.*` element** — one line replaced for the
|
||||
seven simple sites (the five `fi_*_wrapper.sv` interfaces plus the two
|
||||
`ibex_icache_*_if.sv` checkers), a multi-line replacement confined to the
|
||||
`u_sha3`/`u_keccak` instantiation block for the two FPV files. Nothing else
|
||||
in any of the nine files changed.
|
||||
|
||||
Verified the two FPV warnings are real, not lucisv guessing: grepped
|
||||
`hw/ip/kmac/rtl/sha3.sv`'s port list and confirmed all nine names in
|
||||
`sha3_fpv.sv`'s warning (`rand_update_o`, `squeezing_o`, `block_processed_o`,
|
||||
`run_req_o`, `run_ack_i`, `lc_escalate_en_i`, `sparse_fsm_error_o`,
|
||||
`count_error_o`, `keccak_storage_rst_error_o`) are genuine output/input ports
|
||||
of `sha3` absent from `sha3_fpv`'s own header; same check against
|
||||
`hw/ip/kmac/rtl/keccak_round.sv` for `sha3pad_fpv.sv`'s five
|
||||
(`rand_update_o`, `lc_escalate_en_i`, `sparse_fsm_error_o`,
|
||||
`round_count_error_o`, `rst_storage_error_o`). Both wrappers have genuinely
|
||||
drifted behind the modules they wrap.
|
||||
|
||||
### Gates (guarded, re-run independently)
|
||||
|
||||
- `cargo clippy -p vlog_refactor -p lucisv_server --all-targets` — **0
|
||||
warnings**; `cargo clippy --all-targets` over the whole workspace also
|
||||
clean.
|
||||
- `cargo fmt -p vlog_refactor -p lucisv_server -- --check` and
|
||||
`cargo fmt --all -- --check` — clean.
|
||||
- `tools/guard.sh -t 1800 -- cargo test --workspace` — **3 876 passed, 0
|
||||
failed, 44 ignored**, 50 test binaries — matches the dev's number exactly.
|
||||
No guard kill.
|
||||
- `tools/guard.sh -t 900 -- tools/corpus_check.sh` — **814/820 (99.3%)
|
||||
parsed & formattable, 0 verification errors, 0 crashes**, same six known
|
||||
parse errors — matches exactly.
|
||||
- Byte-identity: `lucisv format --stdout` over every corpus file, this build
|
||||
vs `~/.cache/lucisv-baselines/lucisv-0.45.0` — **860 total, 854 checked
|
||||
identical, 0 differing, 6 refused by both** — matches exactly.
|
||||
- `node editors/vscode/smoke.js target/release/lucisv-server` — OK, 20
|
||||
messages.
|
||||
|
||||
### Findings
|
||||
|
||||
- **QA-1 (LOW, informational, not a blocker):** interface instances are
|
||||
never bound by `.*` (nor writable by `add_port`/`propagate_ports`) because
|
||||
`SymbolKind::Instance` is outside every port refactoring's allowed-kind
|
||||
set. Pre-existing across the ports engine, not introduced by §50; fails
|
||||
safe (unconnected + warned). Suggest a backlog line for the ports engine
|
||||
generally: "an interface instance of the same name as an interface port
|
||||
should bind, per IEEE 1800 §23.3.2.4."
|
||||
- **Package-import scope choice — verified as documented, not a defect.**
|
||||
See the matrix above; matches the README's Assumptions section exactly.
|
||||
- No corruption, no dropped comments, no panics, no idempotency break, no
|
||||
byte-identity regression found in any of the above. All temporary test
|
||||
files and scratch copies were removed after verification; the repository
|
||||
tree touched by this QA pass is unchanged apart from this log entry and
|
||||
the §50 QA checkbox in `TODO.md`.
|
||||
|
||||
**Verdict: PASS.**
|
||||
|
||||
## Review
|
||||
|
||||
**2026-09-05 — lead.** Accepted; ships in 0.46.0 with §51. The engine is
|
||||
one replacement edit through the ports engine's existing splice and
|
||||
verifier, which is exactly the shape a lexical refactoring should have,
|
||||
and the LRM rule is read strictly — a parameter or genvar of the same name
|
||||
does not bind, which is what the compiler would say. The refusal list is
|
||||
complete and each refusal is a sentence. The dev found and fixed a real
|
||||
title-rewrite bug in the lazy offer path on the way (`counted` rewrote
|
||||
any parenthesised title). Ten expandable opentitan sites do not exist —
|
||||
57 of the 66 `.*` sites are inside `bind` directives, which need the
|
||||
target's scope and are filed as a backlog entry — so the nine that do
|
||||
exist were all expanded and verified, and two of them surfaced real
|
||||
drift between an FPV wrapper and the module it wraps. The vlog_formatter
|
||||
dev-dependency mirrors the linter's and is recorded in topo.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
||||
{"version":"1.5.2","languages":{"en":{"hash":"en_8310bcd6c3","wasm":"en","page_count":12}},"include_characters":["_","‿","⁀","⁔","︳","︴","﹍","﹎","﹏","_"]}
|
||||
{"version":"1.5.2","languages":{"en":{"hash":"en_f74701efcf","wasm":"en","page_count":12}},"include_characters":["_","‿","⁀","⁔","︳","︴","﹍","﹎","﹏","_"]}
|
||||
Binary file not shown.
Binary file not shown.
+1
-1
@@ -188,4 +188,4 @@ surface for instance paths; it is still under QA and is not a released API.</p>
|
||||
</ul>
|
||||
<div class="sl-heading-wrapper level-h2"><h2 id="release-surface">Release surface</h2><a class="sl-anchor-link" href="#release-surface"><span aria-hidden="true" class="sl-anchor-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 1 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 0 0-1.42-1.42m8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 1 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l3.88-3.89a4.49 4.49 0 0 0 0-6.33M8.83 15.17a1 1 0 0 0 .71.29 1 1 0 0 0 .71-.29l4.92-4.92a1 1 0 1 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42"></path></svg></span><span class="sr-only" data-pagefind-ignore>Section titled “Release surface”</span></a></div>
|
||||
<p>The supported publication surface is seven VS Code <code dir="auto">.vsix</code> packages plus checksums: five platform packages (Apple Silicon/Intel macOS, x86-64/ARM64 static-musl Linux, Windows), one all-platform package, and one universal package requiring binaries on <code dir="auto">PATH</code>. Both <code dir="auto">lucisv</code> and <code dir="auto">lucisv-server</code> are bundled in platform packages. Standalone binaries are built by the tooling but are not published as release assets. The release tooling audits file type, dynamic linkage, and the glibc ceiling for cross-built artifacts.</p>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/architecture.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T04:37:55.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/reference/rust-api/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Rust API index</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/architecture.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T18:35:57.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/reference/rust-api/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Rust API index</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
+1
-1
@@ -277,4 +277,4 @@ remains an error.</p>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>An error outranks “would change.” Every file involved in an error is left untouched.</p>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/cli.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T05:03:07.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/guides/syntax/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Supported syntax</span></span></a><a href="/reference/rules/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Lint rules</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/cli.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T18:35:57.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/guides/syntax/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Supported syntax</span></span></a><a href="/reference/rules/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Lint rules</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
+1
-1
@@ -289,7 +289,7 @@ index scope when the defining module lives outside the default folder scope.</p>
|
||||
<tr>
|
||||
<td>Port actions</td>
|
||||
<td>code actions / commands</td>
|
||||
<td>Adds, removes, and propagates module ports</td>
|
||||
<td>Adds, removes, and propagates module ports; expands a <code dir="auto">.*</code> wildcard into the named connections it stands for (a port with no same-named signal in scope becomes <code dir="auto">.p()</code> and is named in a warning) — <code dir="auto">lucisv.expandWildcard</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Instantiate module</td>
|
||||
|
||||
+1
-1
@@ -748,4 +748,4 @@
|
||||
<p>Reports a <code dir="auto">;</code> written after a <code dir="auto">`uvm_*</code> macro invocation. The macros expand to a <code dir="auto">begin … end</code>, so the <code dir="auto">;</code> is a null statement — usually inert, and not after <code dir="auto">if (x) </code>uvm_info(…); else …<code dir="auto">, where the </code>else<code dir="auto">then belongs to nothing. Off by default in both, because the semicolon is written everywhere in existing UVM code. No fix: deleting it is exactly the edit that is unsafe in the shape the rule exists for. Verible's</code>uvm-macro-semicolon`, same default.</p>
|
||||
<div class="sl-heading-wrapper level-h2"><h2 id="v2001-generate-begin">v2001-generate-begin</h2><a class="sl-anchor-link" href="#v2001-generate-begin"><span aria-hidden="true" class="sl-anchor-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 1 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 0 0-1.42-1.42m8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 1 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l3.88-3.89a4.49 4.49 0 0 0 0-6.33M8.83 15.17a1 1 0 0 0 .71.29 1 1 0 0 0 .71-.29l4.92-4.92a1 1 0 1 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42"></path></svg></span><span class="sr-only" data-pagefind-ignore>Section titled “v2001-generate-begin”</span></a></div>
|
||||
<p>Reports a bare <code dir="auto">begin … end</code> written directly inside a <code dir="auto">generate … endgenerate</code> with no <code dir="auto">if</code>, <code dir="auto">for</code> or <code dir="auto">case</code> around it. It opens an unnamed generate block — an invented path segment that renumbers when a block is added above it — and buys nothing, because the region is already a scope. Read from the same recovered block <code dir="auto">module-begin-block</code> reads, one scope in. Verible’s <code dir="auto">v2001-generate-begin</code>, same default.</p>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/rules.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T04:37:55.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/reference/cli/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">CLI</span></span></a><a href="/reference/language-tools/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Language tools</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/rules.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T18:35:57.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/reference/cli/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">CLI</span></span></a><a href="/reference/language-tools/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Language tools</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
+1
-1
@@ -654,4 +654,4 @@ a codec-version decision so stale caches cannot silently omit answers.</p>
|
||||
</tbody>
|
||||
</table>
|
||||
<aside aria-label="Types" class="starlight-aside starlight-aside--note"><p class="starlight-aside__title" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" class="starlight-aside__icon"><path d="M12 11a1 1 0 0 0-1 1v4a1 1 0 0 0 2 0v-4a1 1 0 0 0-1-1Zm.38-3.92a1 1 0 0 0-.76 0 1 1 0 0 0-.33.21 1.15 1.15 0 0 0-.21.33 1 1 0 0 0 .21 1.09c.097.088.209.16.33.21A1 1 0 0 0 13 8a1.05 1.05 0 0 0-.29-.71 1 1 0 0 0-.33-.21ZM12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm0 18a8 8 0 1 1 0-16.001A8 8 0 0 1 12 20Z"/></svg>Types</p><div class="starlight-aside__content"><p>The crates also expose their data models—AST nodes, diagnostics, rule traits, workspace identifiers, edits, plans, and formatter document nodes. This page intentionally indexes callable behavior; generated Rust API docs remain the right place for field-level type details.</p></div></aside>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/rust-api.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T04:37:55.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/reference/language-tools/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Language tools</span></span></a><a href="/reference/architecture/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Architecture</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/reference/rust-api.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T18:35:57.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/reference/language-tools/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Language tools</span></span></a><a href="/reference/architecture/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Architecture</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
+1
-1
@@ -303,4 +303,4 @@ re-arms logging for newly introduced mistakes. An empty editor selection is
|
||||
the fallback sentinel, so it does not clear a non-empty project selection.</p>
|
||||
<div class="sl-heading-wrapper level-h2"><h2 id="cache">Cache</h2><a class="sl-anchor-link" href="#cache"><span aria-hidden="true" class="sl-anchor-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 1 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 0 0-1.42-1.42m8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 1 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l3.88-3.89a4.49 4.49 0 0 0 0-6.33M8.83 15.17a1 1 0 0 0 .71.29 1 1 0 0 0 .71-.29l4.92-4.92a1 1 0 1 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42"></path></svg></span><span class="sr-only" data-pagefind-ignore>Section titled “Cache”</span></a></div>
|
||||
<p>Successful “already formatted” verdicts are cached under <code dir="auto">.lucisv_cache/</code>. Entries are keyed by file, content hash, line length, indentation, and lucisv version. Files that would change or fail are never cached. Use <code dir="auto">--no-cache</code> to disable reads and writes or <code dir="auto">--cache-dir</code> to relocate the store.</p>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/start/configuration.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T06:45:48.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/start/quick-start/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Quick start</span></span></a><a href="/guides/formatter/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Formatter</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
</div><footer class="sl-flex astro-xhxjzfa7"><div class="meta sl-flex astro-xhxjzfa7"><a href="https://git.luci.ooo/lucio/verilogrustformatter/src/branch/master/docs/site/src/content/docs/start/configuration.md" class="sl-flex print:hidden astro-xk5gmzsg"><svg aria-hidden="true" class="astro-xk5gmzsg astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg>Edit page</a><p>Last updated: <time datetime="2026-09-05T18:35:57.000Z">Sep 5, 2026</time></p></div><div class="pagination-links print:hidden astro-jgq3vlii" dir="ltr"><a href="/start/quick-start/" rel="prev" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg><span class="astro-jgq3vlii">Previous<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Quick start</span></span></a><a href="/guides/formatter/" rel="next" class="astro-jgq3vlii"><svg aria-hidden="true" class="astro-jgq3vlii astro-n5k4ipy7" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg><span class="astro-jgq3vlii">Next<br class="astro-jgq3vlii"><span class="link-title astro-jgq3vlii">Formatter</span></span></a></div></footer></div></div></main></div></div></div></div></body></html>
|
||||
@@ -68,7 +68,7 @@ index scope when the defining module lives outside the default folder scope.
|
||||
|---|---|---|
|
||||
| Prepare rename | `textDocument/prepareRename` | Verifies the target and returns its editable range |
|
||||
| Rename | `textDocument/rename` | Renames local or workspace-resolved symbols |
|
||||
| Port actions | code actions / commands | Adds, removes, and propagates module ports |
|
||||
| Port actions | code actions / commands | Adds, removes, and propagates module ports; expands a `.*` wildcard into the named connections it stands for (a port with no same-named signal in scope becomes `.p()` and is named in a warning) — `lucisv.expandWildcard` |
|
||||
| Instantiate module | inline completion / `lucisv.instantiate` | Builds an instance from an indexed module interface, including in clients without ghost text |
|
||||
| Apply workspace edit | `workspace/applyEdit` | Delivers multi-file refactor changes to the client |
|
||||
| Show definition | `window/showDocument` | Opens a generated or resolved target after an action |
|
||||
|
||||
@@ -121,6 +121,7 @@ what a change on the pointed-to side must not silently break.
|
||||
| `vlog_linter ──▶ vlog_semantic` | depends | `analyze`, `Semantics::{symbols, references, references_of}` for semantic rules, including signal usage and duplicate-declaration checks. `Semantics::duplicates()` was added by linter-expansion-1 without changing persisted facts. `LintContext::semantics()` computes analysis lazily when a rule asks for it. Justified in `vlog_linter/Cargo.toml`; adds no external code (`vlog_semantic` is `vlog_parser` + std). |
|
||||
| `vlog_linter ──▶ lucisv_core` | depends | `walk::is_excluded`, the `--exclude` matcher, reused for a waiver file's `--location` so one pattern language serves the whole tool (waiver-files, §39, 2026-09-04). `lucisv_core` still depends on nothing, so no cycle. |
|
||||
| `vlog_linter ──▶ vlog_formatter` **(dev-only)** | depends (tests) | The `.lint` fix harness asserts a lint fix never produces text `format_source` refuses. **The library dependency list is still `vlog_parser` + `vlog_semantic` + std** — `cargo tree -p vlog_linter -e normal` is the pinned check. Do not promote this to a normal dep; the fence filter deliberately lives in the front ends instead (see shared-fence-filter, §2.4). |
|
||||
| `vlog_refactor ──▶ vlog_formatter` **(dev-only)** | depends (tests) | expand-wildcard (§50, 2026-09-05): the acceptance tests format and converge what an expansion writes. No production edge. |
|
||||
| `vlog_refactor ──▶ vlog_parser` | depends | `tokenize`, `parse_source_tolerant` + diagnostics, `LineIndex`, `TextRange`, the port/instantiation/module AST shapes, `token::is_keyword` (new-name validity), `defines` via the index. Every edit span originates in a parsed node — no textual search-and-replace. |
|
||||
| `vlog_refactor ──▶ vlog_semantic` | depends | `Semantics` queries (`symbol_at`, `references_of`, `reference_id_at`, …), `Resolution` variants (three of them are refusal rules), `WorkspaceIndex` + `resolve_external` + `ExternalTarget`, and the exactness promise on `name_span` (re-checked before each edit is emitted). One historical exception: refactor-rename added `Target::Declaration` + end-label uses *into* `vlog_semantic` (lead-authorized, additive — see §2.6). |
|
||||
| `lucisv ──▶ lucisv_core` | depends | `config::{FileConfig, Discovery}` (lucisv.toml discovery — `config::parse` is reached through `Discovery`, not called directly), `walk::{collect_files, EXTENSIONS}` (the `.gitignore`/`--exclude` walk), `filelist::read` (`-f`), `cache` (the format cache), `atomic::write_atomic` (formatter and lint-fix replacement). (`walk::is_excluded` is `pub` but currently has no consumer outside the crate.) |
|
||||
|
||||
Reference in new issue
Block a user