Round 11: Windows UNC file URIs and editor polish
uri.rs: pure-string Posix/Windows flavours; UNC shares read and written as file://server/share/..., verbatim paths seen through, device and unspellable hosts refused; Posix identical to trunk except backslash (%5C) and query/fragment stripping. Windows is compile- and link-checked only. Editors: mcp.js finds a directory-qualified path without .exe on Windows; hierarchyView.js reports failed actions and disposes its listeners; README and scopeDepth description corrections. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
This commit is contained in:
1 parent
36733e2c7c
commit
a479faf029
15 files changed
+1438
-64
No files matched your search
@@ -62,7 +62,9 @@ fn the_whole_workspace() -> Value {
|
||||
/// [`the_whole_workspace`] with the folder scope's raise turned off, so the
|
||||
/// folder a split leads with is the open buffer's own directory — the
|
||||
/// settings `docs/performance_052_review.md` F1 reproduces with, and what
|
||||
/// every alias fixture below needs to reach the split at all.
|
||||
/// every alias fixture below needs to reach the split at all. Those fixtures
|
||||
/// are symlinks, so this is as `unix`-only as they are.
|
||||
#[cfg(unix)]
|
||||
fn the_whole_workspace_flat() -> Value {
|
||||
serde_json::json!({
|
||||
"index": { "scope": "workspace", "scopeDepth": 0, "logFiles": true }
|
||||
|
||||
@@ -59,8 +59,9 @@ pub const DEFAULT_LARGE_FILE_THRESHOLD: u64 = 4 * 1024 * 1024;
|
||||
/// and signature help all answered *nothing* until some later jump widened the
|
||||
/// scope. A user's first experience of the server was silence.
|
||||
///
|
||||
/// Two levels is the smallest raise that turns a `dv/tb` or an `rtl` file into
|
||||
/// the IP block it belongs to — `hw/ip/aes`, a few hundred files — which is
|
||||
/// Two levels is the smallest raise that turns a `dv/tb` file into the IP
|
||||
/// block it belongs to — `hw/ip/aes`, a few hundred files (an `rtl` file, one
|
||||
/// folder shallower, climbs the same two levels to `hw/ip`) — which is
|
||||
/// the unit an engineer actually works in. What keeps the cost bounded is
|
||||
/// everything the scope ladder already has: the size cap, the persistent
|
||||
/// cache, the interleaved scan and the incremental widen. See
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
//! after the fix round (identities read in one pass in `Walking::finish`);
|
||||
//! see the QA log of `docs/features/server-scaling-r10/README.md`.
|
||||
|
||||
// Both tests build symlinks, so the import is as `unix`-only as they are.
|
||||
#[cfg(unix)]
|
||||
use super::*;
|
||||
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -5,62 +5,89 @@
|
||||
//! `lsp-types` 0.97 models a URI as a `fluent_uri::Uri`, which parses and
|
||||
//! validates but does not know about file paths. The alternative was an
|
||||
//! `lsp-types` old enough to use `url::Url` (five more packages, see the
|
||||
//! feature README), so the ~40 lines live here instead.
|
||||
//! feature README), so the conversion lives here instead.
|
||||
//!
|
||||
//! The conversion is pure string code over a [`Flavor`], so the Windows path
|
||||
//! shapes (drive letters, UNC shares, verbatim `\\?\` paths — RFC 8089
|
||||
//! Appendix E) are tested on every platform; only the choice of flavour for
|
||||
//! [`path_to_uri`] and [`uri_to_path`] follows the build target
|
||||
//! (`docs/features/windows-uri-editors-r11/README.md`).
|
||||
|
||||
mod windows;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
|
||||
use lsp_types::Uri;
|
||||
|
||||
/// Which path grammar a `file:` URI is read into and written from.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Flavor {
|
||||
/// `/`-rooted paths; a URI's authority is dropped.
|
||||
Posix,
|
||||
/// Drive letters and UNC shares; a non-local authority is the UNC host.
|
||||
Windows,
|
||||
}
|
||||
|
||||
/// The flavour of the platform this binary was built for.
|
||||
const NATIVE: Flavor = if cfg!(windows) { Flavor::Windows } else { Flavor::Posix };
|
||||
|
||||
/// The `file:` URI naming an absolute path, or `None` if the path is not
|
||||
/// valid UTF-8 or does not parse back as a URI.
|
||||
pub fn path_to_uri(path: &Path) -> Option<Uri> {
|
||||
let path = path.to_str()?;
|
||||
let mut out = String::from("file://");
|
||||
// A Windows path starts at a drive letter; a POSIX one already starts
|
||||
// with the `/` that separates the (empty) authority from the path.
|
||||
if !path.starts_with('/') {
|
||||
out.push('/');
|
||||
}
|
||||
for byte in path.bytes() {
|
||||
match byte {
|
||||
b'/' | b'-' | b'.' | b'_' | b'~' => out.push(byte as char),
|
||||
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' => out.push(byte as char),
|
||||
// Windows separators become the URI's own.
|
||||
b'\\' => out.push('/'),
|
||||
_ => out.push_str(&format!("%{byte:02X}")),
|
||||
}
|
||||
}
|
||||
Uri::from_str(&out).ok()
|
||||
Uri::from_str(&encode_path(path.to_str()?, NATIVE)?).ok()
|
||||
}
|
||||
|
||||
/// The path a `file:` URI names, or `None` for any other scheme.
|
||||
pub fn uri_to_path(uri: &Uri) -> Option<PathBuf> {
|
||||
let rest = uri.as_str().strip_prefix("file://")?;
|
||||
// An authority (`file://host/path`) is skipped; the path starts at the
|
||||
// first `/`. `file:///path` leaves `rest` already starting with one.
|
||||
let path = match rest.strip_prefix('/') {
|
||||
Some(_) => rest,
|
||||
None => &rest[rest.find('/')?..],
|
||||
};
|
||||
let decoded = String::from_utf8(percent_decode(path)).ok()?;
|
||||
// `file:///C:/x` names `C:/x`, not `/C:/x`. Guarded, because `/C:` is a
|
||||
// legal POSIX directory name.
|
||||
if cfg!(windows) {
|
||||
if let Some(tail) = drive_letter_tail(&decoded) {
|
||||
return Some(PathBuf::from(tail));
|
||||
}
|
||||
}
|
||||
Some(PathBuf::from(decoded))
|
||||
decode_uri(uri.as_str(), NATIVE).map(PathBuf::from)
|
||||
}
|
||||
|
||||
/// `/C:/x` → `C:/x`, when the leading `/` is a URI artifact and not a root.
|
||||
fn drive_letter_tail(path: &str) -> Option<&str> {
|
||||
let tail = path.strip_prefix('/')?;
|
||||
let mut chars = tail.chars();
|
||||
match (chars.next(), chars.next()) {
|
||||
(Some(c), Some(':')) if c.is_ascii_alphabetic() => Some(tail),
|
||||
_ => None,
|
||||
/// The `file:` URI text for `path`, before it is validated as a [`Uri`].
|
||||
fn encode_path(path: &str, flavor: Flavor) -> Option<String> {
|
||||
match flavor {
|
||||
Flavor::Posix => Some(local_uri(path)),
|
||||
Flavor::Windows => windows::path_to_uri(path),
|
||||
}
|
||||
}
|
||||
|
||||
/// `file://` plus `path` with an empty authority. A path that does not start
|
||||
/// at a `/` (a Windows drive letter) gets the `/` that separates the two.
|
||||
fn local_uri(path: &str) -> String {
|
||||
let mut out = String::from("file://");
|
||||
if !path.starts_with('/') {
|
||||
out.push('/');
|
||||
}
|
||||
push_encoded(&mut out, path);
|
||||
out
|
||||
}
|
||||
|
||||
/// Append `text` percent-encoded: `/` and the unreserved bytes stay, every
|
||||
/// other byte — `\`, `:`, `%`, `#`, `?`, space, each byte of a multi-byte
|
||||
/// character — becomes `%XX`.
|
||||
fn push_encoded(out: &mut String, text: &str) {
|
||||
for byte in text.bytes() {
|
||||
match byte {
|
||||
b'/' | b'-' | b'.' | b'_' | b'~' => out.push(byte as char),
|
||||
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' => out.push(byte as char),
|
||||
_ => out.push_str(&format!("%{byte:02X}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The path text a `file:` URI names, or `None` for another scheme, a URI
|
||||
/// with no path, or one that does not decode to UTF-8.
|
||||
fn decode_uri(uri: &str, flavor: Flavor) -> Option<String> {
|
||||
let rest = uri.strip_prefix("file://")?;
|
||||
// A query or fragment is not part of the path (RFC 3986 §3.3); a `?` or
|
||||
// `#` in a file name is always written `%3F`/`%23`.
|
||||
let rest = &rest[..rest.find(['?', '#']).unwrap_or(rest.len())];
|
||||
// The authority runs to the first `/`; `file:///path` leaves it empty.
|
||||
let (authority, path) = rest.split_at(rest.find('/')?);
|
||||
let path = String::from_utf8(percent_decode(path)).ok()?;
|
||||
match flavor {
|
||||
Flavor::Posix => Some(path),
|
||||
Flavor::Windows => windows::path_from_parts(authority, &path),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +127,9 @@ fn hex(byte: u8) -> Option<u8> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod flavor_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -0,0 +1,374 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Both flavours of the `file:` URI conversion, on every platform: the
|
||||
//! Windows shape table (paths → URIs → paths, URIs → canonical URIs), the
|
||||
//! POSIX flavour diffed against trunk's implementation, and malformed input.
|
||||
//! See `docs/features/windows-uri-editors-r11/README.md`.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// `path` → URI text under `flavor`, validated as an LSP [`Uri`] the way
|
||||
/// [`path_to_uri`] validates it.
|
||||
fn to_uri(path: &str, flavor: Flavor) -> Option<String> {
|
||||
let text = encode_path(path, flavor)?;
|
||||
Uri::from_str(&text).ok().map(|uri| uri.as_str().to_string())
|
||||
}
|
||||
|
||||
/// URI text → path under `flavor`, after the same [`Uri`] parse a client's
|
||||
/// URI goes through.
|
||||
fn to_path(uri: &str, flavor: Flavor) -> Option<String> {
|
||||
let uri = Uri::from_str(uri).ok()?;
|
||||
decode_uri(uri.as_str(), flavor)
|
||||
}
|
||||
|
||||
const W: Flavor = Flavor::Windows;
|
||||
const P: Flavor = Flavor::Posix;
|
||||
|
||||
/// Windows path → the URI written for it. Every row also reads back to
|
||||
/// `path` itself (verbatim rows aside, see [`verbatim_paths_write_their_plain_spelling`]).
|
||||
const WINDOWS_PATHS: &[(&str, &str)] = &[
|
||||
(r"C:\x.sv", "file:///C%3A/x.sv"),
|
||||
(r"c:\x.sv", "file:///c%3A/x.sv"),
|
||||
(r"C:\rtl\dir\", "file:///C%3A/rtl/dir/"),
|
||||
(r"C:\", "file:///C%3A/"),
|
||||
(r"C:\a b\c#d%e\f?.sv", "file:///C%3A/a%20b/c%23d%25e/f%3F.sv"),
|
||||
(r"C:\rtl\münchen\✓.sv", "file:///C%3A/rtl/m%C3%BCnchen/%E2%9C%93.sv"),
|
||||
(r"\\server\share\dir\a.sv", "file://server/share/dir/a.sv"),
|
||||
(r"\\server\share", "file://server/share"),
|
||||
(r"\\server\share\", "file://server/share/"),
|
||||
(r"\\Server.corp\Share$\a b#%.sv", "file://Server.corp/Share%24/a%20b%23%25.sv"),
|
||||
(r"\\server\share\é\x.sv", "file://server/share/%C3%A9/x.sv"),
|
||||
(r"\rtl\a.sv", "file:///rtl/a.sv"),
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn every_windows_path_shape_writes_the_canonical_uri_and_reads_back() {
|
||||
for &(path, uri) in WINDOWS_PATHS {
|
||||
assert_eq!(to_uri(path, W).as_deref(), Some(uri), "path → URI for {path}");
|
||||
assert_eq!(to_path(uri, W).as_deref(), Some(path), "URI → path for {uri}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forward_slashed_windows_paths_write_the_same_uri() {
|
||||
assert_eq!(to_uri("C:/x/y.sv", W).as_deref(), Some("file:///C%3A/x/y.sv"));
|
||||
assert_eq!(to_uri("//server/share/a.sv", W).as_deref(), Some("file://server/share/a.sv"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verbatim_paths_write_their_plain_spelling() {
|
||||
// A verbatim path names the same file as its plain spelling, and the URI
|
||||
// has only the one form; it reads back as the plain path.
|
||||
let cases = [
|
||||
(r"\\?\C:\rtl\a.sv", "file:///C%3A/rtl/a.sv", r"C:\rtl\a.sv"),
|
||||
(r"\\?\UNC\server\share\a.sv", "file://server/share/a.sv", r"\\server\share\a.sv"),
|
||||
];
|
||||
for (verbatim, uri, plain) in cases {
|
||||
assert_eq!(to_uri(verbatim, W).as_deref(), Some(uri), "{verbatim}");
|
||||
assert_eq!(to_path(uri, W).as_deref(), Some(plain), "{uri}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paths_with_no_file_uri_are_refused() {
|
||||
for path in [r"\\server", r"\\", r"\\\x", r"\\.\COM1", r"\\?\Volume{0}\x", r"\\?\"] {
|
||||
assert_eq!(encode_path(path, W), None, "{path}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A URI a client may send → the Windows path it names → the URI the server
|
||||
/// writes back for that path.
|
||||
const WINDOWS_URIS: &[(&str, &str, &str)] = &[
|
||||
("file:///C:/x.sv", r"C:\x.sv", "file:///C%3A/x.sv"),
|
||||
("file:///c%3A/x.sv", r"c:\x.sv", "file:///c%3A/x.sv"),
|
||||
("file:///c%3a/x.sv", r"c:\x.sv", "file:///c%3A/x.sv"),
|
||||
("file://localhost/C:/x.sv", r"C:\x.sv", "file:///C%3A/x.sv"),
|
||||
("file://LocalHost/c%3A/x.sv", r"c:\x.sv", "file:///c%3A/x.sv"),
|
||||
("file://server/share/dir/a.sv", r"\\server\share\dir\a.sv", "file://server/share/dir/a.sv"),
|
||||
("file:////server/share/a.sv", r"\\server\share\a.sv", "file://server/share/a.sv"),
|
||||
(
|
||||
"file://server/share/a%20b%23%25.sv",
|
||||
r"\\server\share\a b#%.sv",
|
||||
"file://server/share/a%20b%23%25.sv",
|
||||
),
|
||||
("file://server/share/%C3%A9.sv", r"\\server\share\é.sv", "file://server/share/%C3%A9.sv"),
|
||||
("file://server/share/dir/", r"\\server\share\dir\", "file://server/share/dir/"),
|
||||
("file:///C:/dir/", r"C:\dir\", "file:///C%3A/dir/"),
|
||||
("file:///C:/x.sv?query#frag", r"C:\x.sv", "file:///C%3A/x.sv"),
|
||||
("file://server/share/x.sv#frag", r"\\server\share\x.sv", "file://server/share/x.sv"),
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn every_client_uri_shape_reads_to_its_path_and_writes_back_canonical() {
|
||||
for &(uri, path, canonical) in WINDOWS_URIS {
|
||||
assert_eq!(to_path(uri, W).as_deref(), Some(path), "URI → path for {uri}");
|
||||
assert_eq!(to_uri(path, W).as_deref(), Some(canonical), "path → URI for {path}");
|
||||
// Canonical is a fixed point: reading and writing it changes nothing.
|
||||
let again = to_path(canonical, W).and_then(|path| to_uri(&path, W));
|
||||
assert_eq!(again.as_deref(), Some(canonical), "fixed point {canonical}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_uris_are_refused_without_panicking() {
|
||||
for flavor in [W, P] {
|
||||
for uri in ["untitled:Untitled-1", "file:/x.sv", "file:x.sv", "file://server", "http://x/y"]
|
||||
{
|
||||
assert_eq!(to_path(uri, flavor), None, "{uri} ({flavor:?})");
|
||||
}
|
||||
// Invalid UTF-8 once decoded, in the path or in a UNC host.
|
||||
assert_eq!(decode_uri("file:///a%FF.sv", flavor), None, "{flavor:?}");
|
||||
// A stray `%` is kept, as it always has been.
|
||||
assert!(decode_uri("file:///100%.sv", flavor).is_some_and(|p| p.ends_with("100%.sv")));
|
||||
}
|
||||
assert_eq!(decode_uri("file://h%FF/x.sv", W), None);
|
||||
}
|
||||
|
||||
/// A deterministic byte soup through both directions and both flavours: no
|
||||
/// input panics, and every URI written parses as an LSP [`Uri`].
|
||||
#[test]
|
||||
fn arbitrary_text_never_panics() {
|
||||
let alphabet: Vec<char> = r"\/:?#%.aZ é✓ $@[]".chars().collect();
|
||||
let mut seed: u64 = 0x2545_f491_4f6c_dd1d;
|
||||
for _ in 0..4000 {
|
||||
let mut text = String::new();
|
||||
for _ in 0..(seed % 13) {
|
||||
seed ^= seed << 13;
|
||||
seed ^= seed >> 7;
|
||||
seed ^= seed << 17;
|
||||
text.push(alphabet[(seed % alphabet.len() as u64) as usize]);
|
||||
}
|
||||
for flavor in [W, P] {
|
||||
if let Some(uri) = encode_path(&text, flavor) {
|
||||
assert!(Uri::from_str(&uri).is_ok(), "{text:?} wrote {uri}");
|
||||
}
|
||||
let _ = decode_uri(&format!("file://{text}"), flavor);
|
||||
let _ = decode_uri(&format!("file:///{text}"), flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Hosts a UNC path cannot spell back, and namespaces, are refused on read
|
||||
/// (lead's rulings 2–3): userinfo, a port, an IP literal, an encoded
|
||||
/// separator or NUL, `.` and `?` — and a share-less `\\x` from four slashes.
|
||||
#[test]
|
||||
fn unspellable_hosts_and_shapes_are_refused_on_read() {
|
||||
for uri in [
|
||||
"file://user@srv/share/a.sv",
|
||||
"file://srv:445/share/a.sv",
|
||||
"file://[::1]/share/a.sv",
|
||||
"file://srv%5Cshare/x.sv",
|
||||
"file://srv%2Fshare/x.sv",
|
||||
"file://srv%00/share/x.sv",
|
||||
"file://./pipe/x",
|
||||
"file://%2E/pipe/x",
|
||||
"file://%3F/GLOBALROOT/x",
|
||||
"file:////x",
|
||||
"file://///srv/share/a.sv",
|
||||
"file:////./pipe/x",
|
||||
"file:////%3F/C:/x",
|
||||
] {
|
||||
assert_eq!(decode_uri(uri, W), None, "{uri}");
|
||||
}
|
||||
// Encoded, a WebDAV-style `@` is a host character like any other.
|
||||
let dav = r"\\srv@SSL\DavWWWRoot\a.sv";
|
||||
assert_eq!(to_uri(dav, W).as_deref(), Some("file://srv%40SSL/DavWWWRoot/a.sv"));
|
||||
assert_eq!(to_path("file://srv%40SSL/DavWWWRoot/a.sv", W).as_deref(), Some(dav));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn localhost_is_local_only_before_a_drive_letter() {
|
||||
let cases = [
|
||||
("file://localhost/C:/x.sv", r"C:\x.sv"),
|
||||
("file://LOCALHOST/c%3A/x.sv", r"c:\x.sv"),
|
||||
("file://%6Cocalhost/C:/x.sv", r"C:\x.sv"),
|
||||
("file://localhost/c%24/a.sv", r"\\localhost\c$\a.sv"),
|
||||
("file://LocalHost/share/a.sv", r"\\LocalHost\share\a.sv"),
|
||||
];
|
||||
for (uri, path) in cases {
|
||||
assert_eq!(to_path(uri, W).as_deref(), Some(path), "{uri}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The property QA measured over 400 000 inputs, on a deterministic soup of
|
||||
/// URI pieces: every URI that reads to a path reads to one the writer writes,
|
||||
/// and one step later nothing moves — path → URI → path → URI is fixed.
|
||||
#[test]
|
||||
fn every_readable_windows_uri_is_stable_after_one_step() {
|
||||
let pieces = [
|
||||
"/",
|
||||
"//",
|
||||
"\\",
|
||||
"a",
|
||||
"Z",
|
||||
"srv",
|
||||
"share",
|
||||
"localhost",
|
||||
"LocalHost",
|
||||
"C:",
|
||||
"c%3A",
|
||||
".",
|
||||
"..",
|
||||
"?",
|
||||
"%2F",
|
||||
"%5C",
|
||||
"%2E",
|
||||
"%3F",
|
||||
"%40",
|
||||
"%00",
|
||||
"%25",
|
||||
"%FF",
|
||||
"%",
|
||||
"@",
|
||||
":",
|
||||
"[",
|
||||
"]",
|
||||
"$",
|
||||
" ",
|
||||
"é",
|
||||
"%C3%A9",
|
||||
"#f",
|
||||
"?q",
|
||||
"x.sv",
|
||||
];
|
||||
let mut seed: u64 = 0x9e37_79b9_7f4a_7c15;
|
||||
let mut readable = 0;
|
||||
for _ in 0..100_000 {
|
||||
let mut text = String::from("file://");
|
||||
seed = seed.wrapping_mul(6_364_136_223_846_793_005).wrapping_add(1);
|
||||
for _ in 0..(seed >> 60) % 9 {
|
||||
seed ^= seed << 13;
|
||||
seed ^= seed >> 7;
|
||||
seed ^= seed << 17;
|
||||
text.push_str(pieces[(seed % pieces.len() as u64) as usize]);
|
||||
}
|
||||
let Some(first) = decode_uri(&text, W) else { continue };
|
||||
readable += 1;
|
||||
let written = to_uri(&first, W);
|
||||
assert!(written.is_some(), "{text} read to {first:?}, which is not written");
|
||||
let second = written.as_deref().and_then(|uri| to_path(uri, W));
|
||||
assert_eq!(second.as_deref(), Some(first.as_str()), "{text} → {first:?} → {written:?}");
|
||||
let again = second.as_deref().and_then(|path| to_uri(path, W));
|
||||
assert_eq!(again, written, "{text}: not fixed after one step");
|
||||
}
|
||||
assert!(readable > 5_000, "the soup must reach the reader: {readable}");
|
||||
}
|
||||
|
||||
/// Trunk's implementation (`36733e2`), POSIX branch, kept verbatim as the
|
||||
/// oracle the POSIX flavour is diffed against.
|
||||
mod trunk {
|
||||
pub fn path_to_uri(path: &str) -> String {
|
||||
let mut out = String::from("file://");
|
||||
if !path.starts_with('/') {
|
||||
out.push('/');
|
||||
}
|
||||
for byte in path.bytes() {
|
||||
match byte {
|
||||
b'/' | b'-' | b'.' | b'_' | b'~' => out.push(byte as char),
|
||||
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' => out.push(byte as char),
|
||||
b'\\' => out.push('/'),
|
||||
_ => out.push_str(&format!("%{byte:02X}")),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn uri_to_path(uri: &str) -> Option<String> {
|
||||
let rest = uri.strip_prefix("file://")?;
|
||||
let path = match rest.strip_prefix('/') {
|
||||
Some(_) => rest,
|
||||
None => &rest[rest.find('/')?..],
|
||||
};
|
||||
String::from_utf8(super::percent_decode(path)).ok()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_posix_flavour_is_byte_identical_to_trunk() {
|
||||
let paths = [
|
||||
"/home/u/rtl/top.sv",
|
||||
"/",
|
||||
"/rtl/dir/",
|
||||
"//server/share/a.sv",
|
||||
"/a b/c#d?e/f.sv",
|
||||
"/100%/x.sv",
|
||||
"/rtl/münchen/✓/top.sv",
|
||||
"/C:/x.sv",
|
||||
"/tmp/~user/a-b_c.d.sv",
|
||||
"/w/[x]/@y/$z/+q/,r;s=t&u'v(w)*!.sv",
|
||||
"rtl/relative.sv",
|
||||
"",
|
||||
];
|
||||
for path in paths {
|
||||
assert_eq!(encode_path(path, P), Some(trunk::path_to_uri(path)), "path {path:?}");
|
||||
}
|
||||
let uris = [
|
||||
"file:///home/u/rtl/top.sv",
|
||||
"file:///",
|
||||
"file:///a%20b/c%23d%3Fe/f.sv",
|
||||
"file:///rtl/%C3%A9.sv",
|
||||
"file://localhost/rtl/top.sv",
|
||||
"file://server/share/a.sv",
|
||||
"file:////server/share/a.sv",
|
||||
"file:///C:/x.sv",
|
||||
"file:///c%3A/x.sv",
|
||||
"file:///100%/x",
|
||||
"file:///%zz",
|
||||
"file:///a%FF",
|
||||
"file://server",
|
||||
"file:/x",
|
||||
"untitled:Untitled-1",
|
||||
];
|
||||
for uri in uris {
|
||||
assert_eq!(decode_uri(uri, P), trunk::uri_to_path(uri), "URI {uri:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_two_deliberate_posix_changes_against_trunk() {
|
||||
// 1. A backslash is an ordinary file-name byte on POSIX. Trunk wrote it as
|
||||
// a `/`, naming a different file (`/tmp/a/b.sv`); it is `%5C` now.
|
||||
assert_eq!(trunk::path_to_uri(r"/tmp/a\b.sv"), "file:///tmp/a/b.sv");
|
||||
assert_eq!(to_uri(r"/tmp/a\b.sv", P).as_deref(), Some("file:///tmp/a%5Cb.sv"));
|
||||
assert_eq!(to_path("file:///tmp/a%5Cb.sv", P).as_deref(), Some(r"/tmp/a\b.sv"));
|
||||
// 2. A query or fragment ends the path. Trunk kept `?q#f` in the path.
|
||||
assert_eq!(trunk::uri_to_path("file:///a.sv?q#f").as_deref(), Some("/a.sv?q#f"));
|
||||
assert_eq!(to_path("file:///a.sv?q#f", P).as_deref(), Some("/a.sv"));
|
||||
assert_eq!(to_path("file:///a.sv#f", P).as_deref(), Some("/a.sv"));
|
||||
}
|
||||
|
||||
// QA 2026-11-26 — findings F2–F4 in the feature README's QA log, fixed in
|
||||
// the same round's fix pass (lead's rulings 1–3).
|
||||
|
||||
#[test]
|
||||
fn qa_a_localhost_share_round_trips() {
|
||||
let uri = to_uri(r"\\localhost\c$\a.sv", W).expect("written");
|
||||
assert_eq!(to_path(&uri, W).as_deref(), Some(r"\\localhost\c$\a.sv"), "{uri}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qa_no_uri_reads_as_a_device_path() {
|
||||
for uri in ["file://./PhysicalDrive0/", "file://./pipe/x", "file://%3F/GLOBALROOT/x"] {
|
||||
let path = to_path(uri, W);
|
||||
assert!(path.as_deref().is_none_or(|p| encode_path(p, W).is_some()), "{uri} → {path:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qa_an_encoded_separator_is_not_a_host_boundary() {
|
||||
for uri in ["file://srv%5Cshare/x.sv", "file://srv%2Fshare/x.sv"] {
|
||||
let path = to_path(uri, W);
|
||||
let back = path.as_deref().and_then(|p| to_uri(p, W));
|
||||
assert!(path.is_none() || back.as_deref() == Some(uri), "{uri} → {path:?} → {back:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn posix_drops_a_unc_host_as_it_always_has() {
|
||||
// There is no way to reach `server` from a POSIX path, so the path the
|
||||
// URI names on this machine is what follows the authority.
|
||||
assert_eq!(to_path("file://server/share/a.sv", P).as_deref(), Some("/share/a.sv"));
|
||||
assert_eq!(to_path("file:///C:/x.sv", P).as_deref(), Some("/C:/x.sv"));
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -0,0 +1,185 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The Windows half of `file:` URI ↔ path: drive letters, UNC shares and
|
||||
//! verbatim paths, as plain string code so every platform tests it.
|
||||
//!
|
||||
//! The URI forms are the ones VS Code writes (RFC 8089 Appendix E):
|
||||
//! `C:\x` is `file:///C%3A/x` (drive-letter case kept), and the share
|
||||
//! `\\server\share\x` is `file://server/share/x` — the host is the URI's
|
||||
//! authority. The legacy `file:////server/share/x` is read as the same share,
|
||||
//! but never written. Reading refuses any URI whose path the writer would
|
||||
//! refuse, so URI → path → URI is fixed after one step.
|
||||
|
||||
use super::{local_uri, percent_decode, push_encoded};
|
||||
|
||||
/// What a Windows path names, as far as its URI is concerned.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum Shape<'a> {
|
||||
/// `\\host\rest…` — `rest` starts at the separator after the host.
|
||||
Unc { host: &'a str, rest: &'a str },
|
||||
/// A drive path, or anything else that is not a share.
|
||||
Local(&'a str),
|
||||
}
|
||||
|
||||
/// The `file:` URI text for a Windows path, or `None` for a path no `file:`
|
||||
/// URI names: a device path (`\\.\…`), a verbatim volume (`\\?\Volume{…}\`),
|
||||
/// or a host with no share after it (`\\server`).
|
||||
pub(super) fn path_to_uri(path: &str) -> Option<String> {
|
||||
match shape(path)? {
|
||||
Shape::Unc { host, rest } => {
|
||||
let mut out = String::from("file://");
|
||||
push_encoded(&mut out, host);
|
||||
push_encoded(&mut out, &slashed(rest));
|
||||
Some(out)
|
||||
}
|
||||
Shape::Local(local) => Some(local_uri(&slashed(local))),
|
||||
}
|
||||
}
|
||||
|
||||
/// The Windows path a URI's raw `authority` and decoded `path` name, or `None`
|
||||
/// for one [`path_to_uri`] could not write back. An empty authority is this
|
||||
/// machine; `localhost` is too, but only before a drive letter — otherwise it
|
||||
/// is a UNC host like any other, as `vscode-uri` reads it.
|
||||
pub(super) fn path_from_parts(authority: &str, path: &str) -> Option<String> {
|
||||
let drive = drive_letter_tail(path);
|
||||
let local = match drive {
|
||||
Some(_) => authority.is_empty() || is_localhost(authority),
|
||||
None => authority.is_empty(),
|
||||
};
|
||||
// `/C:/x` names `C:\x`; `//server/share` (the four-slash form) becomes
|
||||
// `\\server\share` by the separator swap alone.
|
||||
let read = if local {
|
||||
backslashed(drive.unwrap_or(path))
|
||||
} else {
|
||||
format!(r"\\{}{}", unc_host(authority)?, backslashed(path))
|
||||
};
|
||||
writable(&read).then_some(read)
|
||||
}
|
||||
|
||||
/// Whether a raw authority spells `localhost`, in any case or encoding.
|
||||
fn is_localhost(authority: &str) -> bool {
|
||||
percent_decode(authority).eq_ignore_ascii_case(b"localhost")
|
||||
}
|
||||
|
||||
/// The UNC host a raw authority names, or `None` when no `\\host\` spells it
|
||||
/// back: userinfo, a port or an IP literal (`@`, `:`, `[`, `]` as written), or
|
||||
/// a decoded host that is empty, holds a separator or NUL, or is a namespace.
|
||||
fn unc_host(authority: &str) -> Option<String> {
|
||||
if authority.contains(['@', ':', '[', ']']) {
|
||||
return None;
|
||||
}
|
||||
let host = String::from_utf8(percent_decode(authority)).ok()?;
|
||||
spellable(&host).then_some(host)
|
||||
}
|
||||
|
||||
/// Whether `host` can stand between `\\` and a share and be read back as
|
||||
/// the same host: not empty, no separator or NUL, not the `.`/`?` namespaces.
|
||||
fn spellable(host: &str) -> bool {
|
||||
!host.is_empty() && !host.contains(['/', '\\', '\0']) && host != "." && host != "?"
|
||||
}
|
||||
|
||||
/// Whether [`path_to_uri`] writes a URI for a path read from one: a `\\…`
|
||||
/// result must be a share, never a device, verbatim or share-less path.
|
||||
fn writable(path: &str) -> bool {
|
||||
match path.strip_prefix(r"\\") {
|
||||
Some(after) => unc_shape(after).is_some(),
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sort a path into a share or a local path, seeing through `\\?\`.
|
||||
fn shape(path: &str) -> Option<Shape<'_>> {
|
||||
if let Some(verbatim) = path.strip_prefix(r"\\?\") {
|
||||
return verbatim_shape(verbatim);
|
||||
}
|
||||
match path.strip_prefix(r"\\").or_else(|| path.strip_prefix("//")) {
|
||||
Some(after) => unc_shape(after),
|
||||
None => Some(Shape::Local(path)),
|
||||
}
|
||||
}
|
||||
|
||||
/// `\\?\C:\x` is the drive path `C:\x`, `\\?\UNC\server\share\x` the share;
|
||||
/// any other verbatim namespace has no `file:` spelling.
|
||||
fn verbatim_shape(verbatim: &str) -> Option<Shape<'_>> {
|
||||
if let Some(share) = verbatim.strip_prefix(r"UNC\") {
|
||||
return unc_shape(share);
|
||||
}
|
||||
is_drive(verbatim).then_some(Shape::Local(verbatim))
|
||||
}
|
||||
|
||||
/// `server\share…` after the leading pair of separators. A host must be
|
||||
/// followed by a share and be [`spellable`]; `?` and `.` are the verbatim and
|
||||
/// device namespaces. `localhost` with a drive-shaped share (`\\localhost\C:\x`,
|
||||
/// no legal share name) is refused too: its URI would read back as the drive.
|
||||
fn unc_shape(after: &str) -> Option<Shape<'_>> {
|
||||
let (host, rest) = after.split_at(after.find(['\\', '/'])?);
|
||||
let reads_as_drive = host.eq_ignore_ascii_case("localhost") && is_drive(&rest[1..]);
|
||||
(spellable(host) && !reads_as_drive).then_some(Shape::Unc { host, rest })
|
||||
}
|
||||
|
||||
/// Whether `path` starts with a drive letter and its colon.
|
||||
fn is_drive(path: &str) -> bool {
|
||||
let bytes = path.as_bytes();
|
||||
bytes.len() >= 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':'
|
||||
}
|
||||
|
||||
/// `/C:/x` → `C:/x`, when the leading `/` is a URI artifact and not a root.
|
||||
fn drive_letter_tail(path: &str) -> Option<&str> {
|
||||
let tail = path.strip_prefix('/')?;
|
||||
is_drive(tail).then_some(tail)
|
||||
}
|
||||
|
||||
/// Windows separators become the URI's own.
|
||||
fn slashed(path: &str) -> String {
|
||||
path.replace('\\', "/")
|
||||
}
|
||||
|
||||
/// A URI's separators become Windows' own.
|
||||
fn backslashed(path: &str) -> String {
|
||||
path.replace('/', "\\")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn each_shape_is_recognised() {
|
||||
let unc = |host, rest| Some(Shape::Unc { host, rest });
|
||||
assert_eq!(shape(r"\\srv\share\a.sv"), unc("srv", r"\share\a.sv"));
|
||||
assert_eq!(shape("//srv/share/a.sv"), unc("srv", "/share/a.sv"));
|
||||
assert_eq!(shape(r"\\?\UNC\srv\share\a.sv"), unc("srv", r"\share\a.sv"));
|
||||
assert_eq!(shape(r"\\?\C:\a.sv"), Some(Shape::Local(r"C:\a.sv")));
|
||||
assert_eq!(shape(r"C:\a.sv"), Some(Shape::Local(r"C:\a.sv")));
|
||||
assert_eq!(shape(r"\rtl\a.sv"), Some(Shape::Local(r"\rtl\a.sv")));
|
||||
let drive_share = r"\\LocalHost\C:\x.sv";
|
||||
for none in
|
||||
[r"\\srv", r"\\", r"\\\x", r"\\.\COM1\x", r"\\?\Volume{1}\x", r"\\?\", drive_share]
|
||||
{
|
||||
assert_eq!(shape(none), None, "{none}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drive_needs_its_letter_and_colon() {
|
||||
assert!(is_drive("C:") && is_drive("z:/x"));
|
||||
assert!(!is_drive("C") && !is_drive("1:") && !is_drive(":C") && !is_drive("é:"));
|
||||
assert_eq!(drive_letter_tail("/c:/x"), Some("c:/x"));
|
||||
assert_eq!(drive_letter_tail("c:/x"), None, "no URI artifact to strip");
|
||||
}
|
||||
|
||||
/// Re-QA N1: the four-slash spelling of a `localhost` "share" named like a
|
||||
/// drive is refused, so no readable URI changes meaning after one step.
|
||||
#[test]
|
||||
fn a_localhost_share_named_like_a_drive_is_refused() {
|
||||
assert_eq!(path_from_parts("", "//localhost/C:/x.sv"), None);
|
||||
assert_eq!(path_to_uri(r"\\localhost\a:x\y"), None);
|
||||
assert_eq!(path_from_parts("localhost", "/C:/x.sv").as_deref(), Some(r"C:\x.sv"));
|
||||
assert_eq!(
|
||||
path_from_parts("localhost", "/c$/a.sv").as_deref(),
|
||||
Some(r"\\localhost\c$\a.sv")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -0,0 +1,691 @@
|
||||
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||||
|
||||
# windows-uri-editors-r11
|
||||
|
||||
## Goal
|
||||
|
||||
Round 11 of the 7–12 series (`docs/rounds-7-12-handoff.md` §"Round 11"): bug
|
||||
fixes and polish only, no features. (1) Make `crates/lucisv_server/src/uri.rs`
|
||||
read and write Windows `file:` URIs correctly for every path shape RFC 8089
|
||||
Appendix E and VS Code use — UNC shares above all, which trunk mangled in both
|
||||
directions — with the Windows logic as pure string code tested on every
|
||||
platform, and Unix behaviour byte-identical except where trunk was provably
|
||||
wrong. (2) Fix the demonstrable defects and stale statements in
|
||||
`editors/vscode/{hierarchyView.js,hierarchyCurrent.js,mcp.js,README.md}` and
|
||||
`editors/nvim/README.md`.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **Path separators on Windows.** `uri_to_path` now returns `\`-separated
|
||||
paths on Windows (`C:\x.sv`, not trunk's `C:/x.sv`). Rust's `Path`
|
||||
equality, hashing and ordering are component-wise on Windows, so every
|
||||
`HashMap<PathBuf>`/`BTreeMap` key and `strip_prefix` behaves the same; only
|
||||
`Display` of a path changes (to the spelling Windows itself uses).
|
||||
- **Drive-letter case is preserved**, in both directions. Windows is
|
||||
case-insensitive, but Rust's `Prefix::Disk` comparison is not, and every
|
||||
path held for a client document comes from that client's own URIs — so
|
||||
keeping the client's case is what keeps one file one key. VS Code itself
|
||||
treats `file:///C%3A/x` and `file:///c%3A/x` as the same document.
|
||||
- **UNC host case is preserved** for the same reason (`Prefix::UNC` compares
|
||||
case-sensitively); hosts are case-insensitive per RFC 3986 and VS Code
|
||||
lowercases them when it prints a URI, so the client matches either way.
|
||||
- **A verbatim path reads back as its plain spelling.** `\\?\C:\x` writes
|
||||
`file:///C%3A/x`, which reads back as `C:\x`. The two name the same file;
|
||||
Rust's `std::fs` re-adds `\\?\` itself for long paths. They are not
|
||||
`Path`-equal in Rust, so a server path that is verbatim (only
|
||||
`std::fs::canonicalize` produces one) does not compare equal to the client's
|
||||
plain path — that was already true on trunk and is unchanged.
|
||||
- The legacy `file:///C|/x` (pipe for colon) is not read as a drive; no
|
||||
current client sends it.
|
||||
- **F6 (QA, recorded).** Trunk's own five-slash UNC URIs
|
||||
(`file://///srv/share/a.sv`) are now refused on read (they would read as the
|
||||
share-less `\\\srv\…`). Nothing persists URIs (the cache is keyed by
|
||||
path), so only a URI held across an upgrade inside one live session could
|
||||
meet this.
|
||||
- **F7 (QA, recorded; unchanged from trunk).** `%2F`/`%5C` inside a path
|
||||
segment decode to separators: `file:///C:/a%2Fb.sv` reads as `C:\a\b.sv`,
|
||||
the same file as `file:///C:/a/b.sv`, and `%2F..%2F` is `..` exactly as a
|
||||
literal `/../` is — as trunk and `vscode-uri`'s `fsPath` do. It adds no
|
||||
capability. (Inside the *host* an encoded separator is refused: F4.)
|
||||
- **`localhost`** is this machine only before a drive letter
|
||||
(`file://localhost/C:/x`); before anything else it is a UNC host
|
||||
(`file://localhost/c%24/a.sv` → `\\localhost\c$\a.sv`), as `vscode-uri`
|
||||
reads it.
|
||||
- **Hosts a UNC path cannot spell back are refused on read** (decision for
|
||||
F4): a raw authority holding `@`, `:`, `[` or `]` — userinfo, a port, an
|
||||
IPv6 literal — returns `None`, as does a host that decodes to empty, `.`,
|
||||
`?`, or anything holding `/`, `\` or NUL. Refusing is the simplest rule that
|
||||
keeps URI → path → URI fixed after one step: a UNC path has no syntax for a
|
||||
port or userinfo, and Windows spells an IPv6 host as
|
||||
`fe80--1.ipv6-literal.net`, not `[fe80::1]`, so any mapping would either name
|
||||
a host the client did not mean or not write back. Percent-*encoded* `@`/`:`
|
||||
are ordinary host characters (WebDAV's `\\srv@SSL\DavWWWRoot` round-trips as
|
||||
`file://srv%40SSL/DavWWWRoot`). The writer refuses the same decoded hosts
|
||||
(`spellable`), so the two directions agree.
|
||||
- A relative path is written as on trunk (`rtl\a.sv` → `file:///rtl/a.sv`);
|
||||
`path_to_uri` is documented for absolute paths only.
|
||||
|
||||
## Handshakes
|
||||
|
||||
- **Consumes** `lsp_types::Uri` (`fluent_uri` 0.x) only to validate text and
|
||||
read `as_str()`; no new dependency.
|
||||
- **Promises** (unchanged signatures): `uri::path_to_uri(&Path) -> Option<Uri>`
|
||||
and `uri::uri_to_path(&Uri) -> Option<PathBuf>`. Behaviour changes callers
|
||||
can observe:
|
||||
- Windows: UNC shares, the four-slash form, verbatim paths and
|
||||
query/fragment are now handled (table below); output paths use `\`.
|
||||
- Unix: two deliberate changes, both fixing a wrong file being named — a
|
||||
`\` in a file name is written `%5C` (trunk wrote `/`), and a URI's
|
||||
`?query`/`#fragment` no longer becomes part of the path.
|
||||
- **F5 — Windows index cache key changes once.** On Windows the workspace
|
||||
roots `uri_to_path` returns change spelling (`c:/proj` → `c:\proj`), and
|
||||
`index_cache::workspace_key` (`index_cache.rs:735-745`) hashes
|
||||
`root.to_string_lossy()`. So each Windows workspace gets a new cache key
|
||||
once: one full cold rescan and an orphaned old cache directory, no
|
||||
corruption (the old directory is simply never read again).
|
||||
- **No same bug elsewhere.** `crates/lucisv_mcp` has no `file:` URI code (its
|
||||
resources are `lucisv://…` with workspace-relative paths, and its roots
|
||||
arrive as `--root <path>`); `lucisv_core`, `lucisv` and the `vlog_*` crates
|
||||
have none either. No Handshake request filed.
|
||||
- **Editor side**: `hierarchyView.js` compares the server's definition URIs
|
||||
with the active editor's through `vscode.Uri.parse(...).toString()`.
|
||||
Trunk's UNC URIs (`file://///server/share/…`) never matched VS Code's
|
||||
`file://server/share/…`, so the current-file highlight could not light a
|
||||
module on a share; the server fix makes them match. No JS change was needed
|
||||
for that.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] Establish trunk behaviour for every requested URI/path shape (table below).
|
||||
- [x] `uri.rs`: `Flavor` (Posix/Windows) as pure string code; only the choice
|
||||
of `NATIVE` follows `cfg!(windows)`. Windows shapes in `uri/windows.rs`.
|
||||
- [x] Tests: `uri/flavor_tests.rs` (Windows path and URI tables, canonical
|
||||
fixed point, verbatim, refusals, malformed input, a 4 000-input
|
||||
no-panic sweep, Posix diffed against a verbatim copy of trunk, the two
|
||||
deliberate Posix deltas) and `uri/windows.rs` unit tests. The six
|
||||
existing tests in `uri.rs` are textually untouched.
|
||||
- [x] `mcp.js`: `findable` accepts `C:\tools\lucisv-mcp` when
|
||||
`lucisv-mcp.exe` is there (test in `mcp_test.js`).
|
||||
- [x] `hierarchyView.js`: a failing webview action warns instead of an
|
||||
unhandled rejection; a disposed view disposes its own listeners (tests
|
||||
in `hierarchyView_test.js`).
|
||||
- [x] `hierarchyCurrent.js`: read in full; no defect found, unchanged.
|
||||
- [x] VS Code README: `lucisv.index.scopeDepth` default, the eight missing
|
||||
`lucisv.format.*` rows, the stale "everything else ships in 0.10.2".
|
||||
- [x] nvim README: references are workspace-wide, `--stdio` is accepted.
|
||||
- [x] Fix round (lead's rulings on QA F1–F7): F2 `localhost` only before a
|
||||
drive, F3 no device/verbatim path read, F4 unspellable hosts refused,
|
||||
F1 `scopeDepth` example in README and `package.json`, F5–F7 recorded,
|
||||
the two Windows-only test warnings gated `#[cfg(unix)]`.
|
||||
- [ ] **Release note needed** (lead): on Windows the persisted index cache is
|
||||
rebuilt once after upgrading (F5), and UNC workspaces now work.
|
||||
- [ ] Windows runtime behaviour: not executed (no Windows host, no Wine).
|
||||
|
||||
### URI shape table — Windows flavour
|
||||
|
||||
"Before" is trunk `36733e2` with `cfg!(windows)` true (emulated line for line
|
||||
from the trunk source); "after" is this round, asserted in `flavor_tests.rs`.
|
||||
|
||||
| Input | Before | After |
|
||||
|---|---|---|
|
||||
| path `C:\x.sv` | `file:///C%3A/x.sv` → `C:/x.sv` | `file:///C%3A/x.sv` → `C:\x.sv` |
|
||||
| path `c:\x.sv` | `file:///c%3A/x.sv` → `c:/x.sv` | `file:///c%3A/x.sv` → `c:\x.sv` |
|
||||
| path `C:\rtl\dir\` | `file:///C%3A/rtl/dir/` | same; reads back `C:\rtl\dir\` |
|
||||
| path `\\server\share\dir\a.sv` | `file://///server/share/dir/a.sv` → `///server/share/dir/a.sv` (broken) | `file://server/share/dir/a.sv` → `\\server\share\dir\a.sv` |
|
||||
| path `\\server\share` | `file://///server/share` | `file://server/share` |
|
||||
| path `\\?\C:\rtl\a.sv` | `file://///%3F/C%3A/rtl/a.sv` (broken) | `file:///C%3A/rtl/a.sv` → `C:\rtl\a.sv` |
|
||||
| path `\\?\UNC\server\share\a.sv` | `file://///%3F/UNC/server/share/a.sv` (broken) | `file://server/share/a.sv` → `\\server\share\a.sv` |
|
||||
| path `\rtl\a.sv` | `file:////rtl/a.sv` → `//rtl/a.sv` (a UNC!) | `file:///rtl/a.sv` → `\rtl\a.sv` |
|
||||
| path `C:\a b\c#d%e\f?.sv` | `file:///C%3A/a%20b/c%23d%25e/f%3F.sv` | same; reads back exactly |
|
||||
| path `\\server`, `\\.\COM1`, `\\?\Volume{…}\` | garbage URIs | `None` |
|
||||
| URI `file:///C:/x.sv` | `C:/x.sv` | `C:\x.sv` → writes `file:///C%3A/x.sv` |
|
||||
| URI `file:///c%3A/x.sv` (VS Code) | `c:/x.sv` | `c:\x.sv` → writes it back unchanged |
|
||||
| URI `file://localhost/C:/x.sv` | `C:/x.sv` | `C:\x.sv` → `file:///C%3A/x.sv` |
|
||||
| URI `file://server/share/dir/a.sv` | `/share/dir/a.sv` (host dropped: wrong file) | `\\server\share\dir\a.sv` → writes it back unchanged |
|
||||
| URI `file:////server/share/a.sv` | `//server/share/a.sv` → writes `file:////…` | `\\server\share\a.sv` → `file://server/share/a.sv` |
|
||||
| URI `file://server/share/a%20b%23%25.sv` | `/share/a b#%.sv` | `\\server\share\a b#%.sv` → back unchanged |
|
||||
| URI `file://server/share/%C3%A9.sv` | `/share/é.sv` | `\\server\share\é.sv` → back unchanged |
|
||||
| URI `file:///C:/x.sv?query#frag` | `C:/x.sv?query#frag` | `C:\x.sv` |
|
||||
| URI `file://server` (no path), `untitled:…`, invalid UTF-8 | `None` | `None` |
|
||||
| URI `file://localhost/c%24/a.sv` | `\c$\a.sv` (with `/`) | `\\localhost\c$\a.sv` → back unchanged (fix round, F2) |
|
||||
| URI `file://./pipe/x`, `file://%3F/GLOBALROOT/x` | `/pipe/x`, `/GLOBALROOT/x` | `None` (round 1 read `\\.\pipe\x`; fix round, F3) |
|
||||
| URI `file://srv%5Cshare/x.sv`, `file://srv%2Fshare/x.sv` | `/x.sv` | `None` (round 1 read host+share; fix round, F4) |
|
||||
| URI `file://user@srv/…`, `file://srv:445/…`, `file://[::1]/…` | `/…` (host dropped) | `None` (F4 decision) |
|
||||
| URI `file:////x`, `file://///srv/share/a.sv` | `//x`, `///srv/…` | `None` (no share / share-less host) |
|
||||
|
||||
### URI shape table — Posix flavour
|
||||
|
||||
Byte-identical to trunk over 12 paths and 15 URIs
|
||||
(`the_posix_flavour_is_byte_identical_to_trunk`, against a verbatim copy of
|
||||
trunk's code), except:
|
||||
|
||||
| Input | Before | After |
|
||||
|---|---|---|
|
||||
| path `/tmp/a\b.sv` | `file:///tmp/a/b.sv` (names `/tmp/a/b.sv`) | `file:///tmp/a%5Cb.sv` (round-trips) |
|
||||
| URI `file:///a.sv?q#f` | `/a.sv?q#f` | `/a.sv` |
|
||||
|
||||
`file://server/share/a.sv` still reads as `/share/a.sv` on Unix, as on trunk
|
||||
(no POSIX spelling reaches a remote host).
|
||||
|
||||
### Canonical form
|
||||
|
||||
What the server writes is the form VS Code writes, so a URI the server sends
|
||||
back compares equal to the client's: `file://<host>/<share>/…` for a UNC path
|
||||
(never the four-slash form), `file:///<drive>%3A/…` for a drive path with the
|
||||
drive letter as the path spells it (trunk already wrote `%3A`, so no client
|
||||
that worked before sees a different string), and `file:///…` unchanged for
|
||||
Unix. Everything outside `A–Z a–z 0–9 - . _ ~ /` is percent-encoded with
|
||||
upper-case hex, as on trunk. A canonical URI is a fixed point of
|
||||
URI → path → URI (asserted for every row).
|
||||
|
||||
### Editor audit items
|
||||
|
||||
The audit (`docs/repository-analysis.md`) names no concrete item for these
|
||||
five files — its only editor line is the inventory at line 63 — and
|
||||
`TODO.md`/`docs/topo.md` §2.9 have no open row naming them. Each fix below is
|
||||
therefore a defect found by reading, with its evidence:
|
||||
|
||||
| File | Defect | Evidence |
|
||||
|---|---|---|
|
||||
| `mcp.js` `findable` | On Windows a `lucisv.mcp.path` like `C:\tools\lucisv-mcp` was refused ("not found") although the spawn runs `lucisv-mcp.exe` | the bare-name branch already tried `.exe`; the directory branch did not. `aWindowsPathWithoutExeIsFound` fails on trunk's `mcp.js` |
|
||||
| `hierarchyView.js` | A webview action that throws (open a definition whose file was deleted) was an unhandled rejection: VS Code ignores the listener's promise, the user saw nothing | `aFailedActionIsReportedAndADisposedViewLetsGo`: on trunk the promise rejects |
|
||||
| `hierarchyView.js` | Each `resolveWebviewView` pushed its two listeners onto `context.subscriptions`, so a view VS Code disposed and resolved again left them behind until deactivation | same test: on trunk the subscription count grows by 2 and nothing is disposed with the view |
|
||||
| `vscode/README.md:340` | `lucisv.index.scopeDepth` default given as `0` | `package.json` and `settings.rs` `DEFAULT_SCOPE_DEPTH` are `2` (changed 2026-08-28) |
|
||||
| `vscode/README.md:348`, `vscode/package.json:774` (fix round, QA F1) | "`2` lets a file in `hw/ip/aes/rtl/` index all of `hw/ip/aes/`" (round 1 copied it from `package.json`); `package.json` also said a rootless session should set `0` | `state/scope.rs` `raised()` climbs the file's own folder `depth` times, so `rtl/` reaches `hw/ip/`; the true example is `settings.rs:57-63` (`hw/ip/aes/dv/tb/` → `hw/ip/aes/`). `raised()` returns the folder unchanged when there are no roots, so a rootless session never climbs |
|
||||
| `vscode/README.md` Settings | The eight `lucisv.format.*` overrides (`begin`, `else`, `elseAfterLabel`, `portLists`, `listIndent`, `alignment`, `connectionAlignMin`, `uvmUtilsIndent`) were missing from the table | `package.json` contributes them; rows written from their own descriptions |
|
||||
| `vscode/README.md:361` | "everything else ships in 0.10.2" | `lucisv.mcp.*`, `lucisv.hierarchy.*`, `lucisv.format.*` and others shipped later (CHANGELOG) |
|
||||
| `nvim/README.md:99` | "`gr` (references, in-file only for now)" | `nav.rs::references` is workspace-wide; CHANGELOG 0.12.0/0.55.0 |
|
||||
| `nvim/README.md` `--verbose` | "The server takes one argument … anything other than `--verbose` is refused … one usage line" | `main.rs` `verbose_flag` also accepts `--stdio`; two stderr lines (`error: unknown option`, usage) |
|
||||
|
||||
Every other README claim checked against code (all 119 contributed setting
|
||||
ids and defaults by script, the 8 commands, the five read-only MCP tools, the
|
||||
nine tools, the capabilities `nvim/README.md` lists, `positionEncoding`
|
||||
`utf-16`, the `lucisv.instantiate` argument order) matched.
|
||||
|
||||
Left alone, as features or as unprovable from this repository:
|
||||
|
||||
- `mcp.js` passes a non-`file:` workspace folder's `fsPath` as `--root`;
|
||||
whether VS Code ever activates this extension in a virtual workspace is not
|
||||
decidable from the manifest (no `capabilities.virtualWorkspaces`).
|
||||
- `mcp.js` checks a relative `lucisv.mcp.path` against the extension host's
|
||||
cwd while the spawn's cwd is the folder; relative paths are not documented.
|
||||
- `nvim/README.md` uses `vim.lsp.buf.execute_command`, which Neovim 0.11
|
||||
deprecates for `client:exec_cmd`; it still works and is Neovim's API, not
|
||||
ours.
|
||||
- `nvim/README.md` "the workspace index rebuilds on save" — the index now
|
||||
updates one file on save rather than rebuilding, but the staleness model it
|
||||
describes (cross-file answers as of the last write) is what
|
||||
`docs/features/lucisv-server/README.md` still states; left as is.
|
||||
|
||||
## Work log
|
||||
|
||||
**2026-11-26 (dev).** Read `CLAUDE.md`, the handoff's Round 11, topo
|
||||
`lucisv_server` and §2.9, the audit. Traced every `uri_to_path`/`path_to_uri`
|
||||
caller: documents are keyed by the client's own `Uri`, and the server's
|
||||
written URIs go out in locations/edits, so the written form must match the
|
||||
client's spelling — hence VS Code's form as canonical.
|
||||
|
||||
- Emulated trunk's Windows branch line for line to get the "before" column;
|
||||
UNC was broken both ways (five-slash URIs written, host dropped on read),
|
||||
verbatim paths wrote `%3F` garbage, and a root-relative `\rtl` wrote a
|
||||
four-slash URI that reads back as a share.
|
||||
- Split `uri.rs` into a `Flavor`-parameterised core (`encode_path`,
|
||||
`decode_uri`) with the Windows shapes in `uri/windows.rs`; `NATIVE` is the
|
||||
only `cfg!(windows)`. Public signatures unchanged. Production lines (non-blank,
|
||||
non-comment, before tests): `uri.rs` 81, `uri/windows.rs` 60.
|
||||
- The two Unix deltas are deliberate and pinned by
|
||||
`the_two_deliberate_posix_changes_against_trunk`; everything else is diffed
|
||||
against a verbatim copy of trunk's code.
|
||||
- Editor fixes as in the table above; each JS test was run against trunk's
|
||||
file (copied to a scratch directory) and fails there.
|
||||
- Stamp headers/footers on the three new files (`uri/windows.rs`,
|
||||
`uri/flavor_tests.rs`, this README) written by hand in the repository's
|
||||
convention; `stamp_author.py --check` only sees tracked files.
|
||||
- Checks run: `cargo fmt --all -- --check` clean; `cargo clippy --workspace
|
||||
--all-targets` clean; guarded `cargo test -p lucisv_server` 2 256 passed,
|
||||
0 failed, 53 ignored (all pre-existing ignores; 18 of the passes are the
|
||||
`uri::` tests); `node --test editors/vscode/*_test.js` 37/37 (14 files, the
|
||||
two edited ones gained a check function each); `tools/gates.sh --only cross`
|
||||
pass — `cargo check` of the `lucisv`, `lucisv_server`, `lucisv_mcp`
|
||||
binaries for `x86_64-pc-windows-gnu` and `x86_64-unknown-linux-musl`:
|
||||
compile only, no tests, no link. Additionally `cargo test --no-run --target
|
||||
x86_64-pc-windows-gnu -p lucisv_server` (rustup stable + Homebrew mingw)
|
||||
compiles and links all five test executables; they were not run.
|
||||
- Seen while doing that, not mine to fix (files outside this round's scope):
|
||||
the Windows test build warns `unused import: super::*` at
|
||||
`crates/lucisv_server/src/state/tests/qa_walking.rs:14` and
|
||||
`the_whole_workspace_flat is never used` at
|
||||
`crates/lucisv_server/src/server/tests/startup.rs:66` — unix-only tests
|
||||
leaving their helpers unused on Windows.
|
||||
|
||||
**2026-11-26 (dev, fix round — lead's rulings on the QA log).**
|
||||
|
||||
- F2/F3/F4 in `uri/windows.rs`: `path_from_parts` now treats `localhost` as
|
||||
local only before a drive letter, takes a UNC host only through `unc_host`
|
||||
(raw `@ : [ ]` refused, decoded host must be `spellable`), and refuses any
|
||||
read path the writer would refuse (`writable`). `unc_shape` uses the same
|
||||
`spellable`, so the writer also refuses a NUL host. Production lines:
|
||||
`uri.rs` 81, `uri/windows.rs` 82.
|
||||
- QA's three `qa_*` tests: `#[ignore]` removed, assertions unchanged, they
|
||||
pass. New: `unspellable_hosts_and_shapes_are_refused_on_read`,
|
||||
`localhost_is_local_only_before_a_drive_letter`, and
|
||||
`every_readable_windows_uri_is_stable_after_one_step` (100 000 generated URI
|
||||
texts from 34 pieces — separators, `localhost`, drives, `.`, `?`, `%2F`,
|
||||
`%5C`, `%00`, `%FF`, `@`, `:`, `[`, `]`, UTF-8, query/fragment; asserts that
|
||||
every one that reads to a path reads to a path the writer writes, that the
|
||||
written URI reads back to the same path, and that writing again gives the
|
||||
same URI; 0 exceptions, and it asserts more than 5 000 of them were readable).
|
||||
Its first run found a case the rulings did not name (`file:////h%00…`: a
|
||||
NUL host reached through the four-slash form), fixed by sharing `spellable`.
|
||||
- Posix flavour untouched (`windows.rs` only); the trunk differential and the
|
||||
two-delta test pass unchanged.
|
||||
- F1: README row and the `lucisv.index.scopeDepth` `markdownDescription`
|
||||
corrected (both wrong sentences in that description; no other
|
||||
`package.json` change). `docs/site/src/content/docs/start/configuration.md:95`
|
||||
and `README.md:1064` carry no example and are correct; no other copy found
|
||||
(grep for `scopeDepth` and `hw/ip/aes/rtl` over `docs/site/src`, `README.md`,
|
||||
`editors/`, `docs/*.md`). Not edited, outside the ruling: the doc comment at
|
||||
`crates/lucisv_server/src/settings.rs:62` says two levels turn "a `dv/tb` or
|
||||
an `rtl` file" into the IP block — the `rtl` half is the same mistake.
|
||||
- Windows-only warnings: `#[cfg(unix)]` on `use super::*` in
|
||||
`state/tests/qa_walking.rs` (both its tests are unix-only) and on
|
||||
`the_whole_workspace_flat` in `server/tests/startup.rs` (its three users are
|
||||
unix-only).
|
||||
- Checks: fmt clean; clippy `--workspace --all-targets` 0 warnings; guarded
|
||||
`cargo test -p lucisv_server` 2 262 passed, 0 failed, 53 ignored (unit
|
||||
2152/0/48, e2e 106/0/3, grammar 3, ifdef_folding 1, opentitan_references
|
||||
0/0/2); `uri::` 24 passed, 0 ignored; node 37/37, 0 skipped;
|
||||
`gates.sh --only cross` pass; Windows `cargo test --no-run --target
|
||||
x86_64-pc-windows-gnu -p lucisv_server` compiles and links all five test
|
||||
executables with **0 warnings** (not run); `stamp_author.py --check` 0 files.
|
||||
|
||||
## QA log
|
||||
|
||||
**2026-11-26 (QA).** Verdict: **PASS with findings**. Nothing blocks the round.
|
||||
F1 is a documentation error this diff introduced. F2–F4 are Windows edge
|
||||
shapes: none is a regression for a real VS Code session against trunk, and
|
||||
each is pinned by a deliberately failing, `#[ignore]`d `qa_*` test in
|
||||
`uri/flavor_tests.rs`. Windows *runtime* is unverified: there is no Windows
|
||||
host and no Wine.
|
||||
|
||||
What was run:
|
||||
|
||||
- `cargo fmt --all -- --check` is clean. `cargo clippy --workspace
|
||||
--all-targets` reports 0 warnings, and still does after my test additions.
|
||||
Guarded `cargo test -p lucisv_server` (`-m 8 -t 600`): 2 256 passed,
|
||||
0 failed, 53 ignored. That matches the dev's count, and there were no guard
|
||||
kills. After my additions, `uri::` gives 18 passed and 3 ignored; with
|
||||
`--include-ignored` the three `qa_*` tests fail as intended.
|
||||
- `node --test editors/vscode/*_test.js`: 37 tests, 37 pass, 0 fail,
|
||||
0 skipped. `tools/gates.sh --only cross` passes.
|
||||
- `stamp_author.py --check` stamps 0 files. I also checked the stamps on the
|
||||
three new files by hand: header and footer are both present.
|
||||
- Production lines (non-blank, non-comment, before `#[cfg(test)]`):
|
||||
`uri.rs` 81 and `uri/windows.rs` 60. Library code has no `unwrap`,
|
||||
`expect`, `panic!`, `unsafe` or `#[allow]`.
|
||||
- The six trunk tests are byte-identical to `36733e2`, checked by diffing the
|
||||
`mod tests` block. `percent_decode` is also byte-identical.
|
||||
- The dev's `trunk` oracle module in `flavor_tests.rs` matches
|
||||
`git show 36733e2:…/uri.rs` in substance. It drops the comments and the
|
||||
`Path`/`Uri` wrapping. It omits the `cfg(windows)` drive branch, which is
|
||||
correct for a Posix oracle.
|
||||
- Windows cross-build: `cargo test --no-run --target x86_64-pc-windows-gnu
|
||||
-p lucisv_server`, using the rustup toolchain that `gates.sh` uses, built and
|
||||
linked all 5 test executables. The only two warnings are the pre-existing
|
||||
ones the dev named (`state/tests/qa_walking.rs:14`,
|
||||
`server/tests/startup.rs:66`). Both files are untouched by this diff.
|
||||
The executables were not run.
|
||||
|
||||
**Posix differential (independent harness).** I built a scratch crate
|
||||
containing trunk's `uri.rs` extracted with `git show` and the new
|
||||
`uri.rs`/`uri/windows.rs` copied unchanged, linked against
|
||||
`lsp-types 0.97.0`/`fluent-uri 0.1.4`. The inputs were 400 000 generated paths,
|
||||
plus 539 832 URI texts tried both raw and after `Uri::from_str`. The
|
||||
generators used ASCII punctuation including `% # ? \ : space`, non-ASCII
|
||||
text, `..`, `//`, trailing `/`, valid, invalid and mixed-case `%XX` escapes,
|
||||
NUL, DEL, `file://host/`, `localhost`, `LOCALHOST`, `file:/`, `FILE:///`,
|
||||
four- and five-slash forms, IPv4, IPv6 and userinfo hosts, and `untitled:`.
|
||||
|
||||
Result: **0 undeclared differences.** Every path diff is exactly
|
||||
`\`→`%5C`, and every URI diff is exactly the `?`/`#` cut. There were also
|
||||
0 round-trip failures for absolute paths.
|
||||
|
||||
I judged the two deliberate changes on their merits:
|
||||
|
||||
- **(a) Stripping `?`/`#`.** `path_to_uri` writes `%3F`/`%23` and they
|
||||
round-trip. That is covered by the fuzz and by the trunk test
|
||||
`spaces_and_specials_are_percent_encoded`.
|
||||
- The clients I know of all percent-encode both characters in file paths:
|
||||
VS Code (`vscode-uri`), Neovim (`vim.uri_from_fname`, RFC 3986 set),
|
||||
Helix (`url` crate), eglot and Kate. This comes from reading their source
|
||||
in the past, not from running them here. An unencoded `?` meant a query
|
||||
on trunk as well; trunk merely misread it.
|
||||
- Documents are keyed by the client's own `Uri`. Path-to-document lookups
|
||||
go through `Path` equality (`state/buffers.rs:25` `open_document_for_path`),
|
||||
so no document can be re-keyed under a second spelling.
|
||||
- **(b) `%5C`.** A `\` in a Unix file name now round-trips, and VS Code and
|
||||
Neovim both send `%5C`.
|
||||
- `nav.rs:109` `path_to_uri_or_self` re-spells a client's URI through its
|
||||
path. Trunk turned `…/a%5Cb.sv` into `…/a/b.sv`, which named a different
|
||||
file. The new code keeps `%5C`, so this is a fix, not a risk.
|
||||
- I grepped every `path_to_uri`/`uri_to_path` caller (33 files) and every
|
||||
`HashMap<Uri,…>`/`HashSet<Uri>`. None compares a server-written URI
|
||||
string with a client string.
|
||||
|
||||
**Windows flavour (independent table and 400 000-input fuzz).** I derived the
|
||||
expectations from RFC 8089 Appendix E and from `vscode-uri`'s
|
||||
`URI.file`/`fsPath`. The `vscode-uri` behaviour comes from knowledge of its
|
||||
source; I did not run it.
|
||||
|
||||
- Every row of the dev's before/after table reproduces, including the
|
||||
"before" column when trunk runs under emulated `cfg!(windows)`.
|
||||
- Every absolute, non-relative path the writer accepts reads back as its
|
||||
canonical spelling (`/`→`\`, verbatim prefix dropped). I found no aliases
|
||||
and no invalid URIs.
|
||||
- Writing is refused for `\\.\COM1`, `\\?\Volume{…}`, `\\server` and
|
||||
`\\?\UNC\srv`.
|
||||
- `C:`, `C:x.sv`, `C:/mixed\seps`, `//server/share`, `\\srv\c$\x`,
|
||||
`\\?\UNC\srv\c$\x`, IPv4 hosts, dotted hosts, spaces, `$`, trailing dots
|
||||
and spaces, `CON` and `nul` all behave as expected.
|
||||
- Reading `file:///%43:/x`, `file://%6Cocalhost/C:/x`, `file:///c%3a/x` and
|
||||
`file://127.0.0.1/share/a.sv` works. `file:///C|/x` is rejected by
|
||||
`fluent_uri` before it reaches the decoder.
|
||||
- There were no panics.
|
||||
- Of the URIs that read to a path, 26 001 read to one that `path_to_uri`
|
||||
then refuses. These are mostly `file:////x` and `file://///…` shapes with
|
||||
no share. 39 URIs were unstable after one step, all in classes F2 and F4.
|
||||
|
||||
I checked the claim that `\` separators are harmless by reading the code.
|
||||
`is_excluded` (`lucisv_core/src/walk.rs:490`) works on components, and
|
||||
`includes.rs:273/342/446` folds a `to_str()` key. That key now agrees with
|
||||
walk-discovered paths, which always used `\` (better than trunk). The include
|
||||
spelling replaces `\` (`file_ops.rs:345`). I found no `rsplit('/')`,
|
||||
`contains('/')` or string-prefix work on URI-derived paths. One observable
|
||||
change is F5.
|
||||
|
||||
**JS.** On a scratch copy of `editors/vscode` with trunk's `mcp.js` and
|
||||
`hierarchyView.js` restored:
|
||||
|
||||
- `aWindowsPathWithoutExeIsFound` fails at "win32: a directory part without
|
||||
.exe finds the .exe".
|
||||
- `aFailedActionIsReportedAndADisposedViewLetsGo` fails at the
|
||||
subscription-count assert. With that assert removed it fails at "the
|
||||
promise VS Code drops never rejects" (`rejected`). So both halves of the
|
||||
test are real.
|
||||
- The `.exe` candidate is added only when `process.platform === 'win32'`.
|
||||
- `message()` is `async` (`hierarchyView.js:264`), so `.catch` always has a
|
||||
promise to attach to. The catch covers only this one listener and warns
|
||||
once per rejection. A normal or cancelled action resolves and does not
|
||||
warn.
|
||||
- A re-resolved view gets fresh listeners, and the `this.view === view`
|
||||
guard keeps a late dispose of the old view from clearing the new one.
|
||||
- The listeners are no longer on `context.subscriptions`. They therefore rely
|
||||
on VS Code disposing the view at deactivation, which it does as far as I
|
||||
know. I did not verify this in VS Code.
|
||||
|
||||
**READMEs.**
|
||||
|
||||
- I wrote a script to compare the settings table with `package.json`. All
|
||||
44 rows exist, with matching defaults, types and enums. The 75 ids without
|
||||
a row are the generated `lucisv.lint.rules.*`, as the README says.
|
||||
- There are six `lucisv.index.*` ids, as stated.
|
||||
- The claim that `lucisv.toml` outranks `lucisv.format.*` holds in
|
||||
`format.rs:266-273`.
|
||||
- In the nvim README, the statements about `--stdio`, the two stderr lines
|
||||
and exit code 2 match `main.rs:93-116`. "References across the indexed
|
||||
workspace" matches `nav.rs:117-139`.
|
||||
- `git diff editors/vscode/package.json` is empty, and so are `Cargo.toml`,
|
||||
`Cargo.lock`, the CHANGELOGs and `TODO.md`.
|
||||
|
||||
Findings, by severity:
|
||||
|
||||
- **F1 (low–medium; docs; introduced by this diff).** The new
|
||||
`lucisv.index.scopeDepth` row in `editors/vscode/README.md` says "`2` lets a
|
||||
file in `hw/ip/aes/rtl/` index all of `hw/ip/aes/`". The code raises a file's
|
||||
own folder `depth` times: `state/scope.rs:116-133` `raised()`, called from
|
||||
`opened_dirs` at `scope.rs:79`. Depth 2 from `hw/ip/aes/rtl` therefore
|
||||
reaches `hw/ip/`, which is every IP block. `scope.rs:110-112` says so itself
|
||||
("raise … into `~/work/chip/hw/ip/`").
|
||||
- A correct example is `settings.rs:57-63`: `hw/ip/aes/dv/tb/` → `hw/ip/aes/`.
|
||||
- The wrong example was copied from `package.json`'s description of the
|
||||
same setting. That description predates this round and is outside its
|
||||
scope; it is reported here, not edited.
|
||||
- **F2 (low–medium; Windows; not a regression).** `\\localhost\c$\a.sv` writes
|
||||
`file://localhost/c%24/a.sv`, which reads back as `\c$\a.sv`: a root-relative
|
||||
path on the current drive, so a different file.
|
||||
- Repro: `qa_a_localhost_share_round_trips`.
|
||||
- Cause: `path_from_parts` (`uri/windows.rs:41-50`) treats a `localhost`
|
||||
authority as this machine even when the path has no drive letter.
|
||||
`vscode-uri` reads the same URI as `\\localhost\c$\a.sv`.
|
||||
- So a folder VS Code opened through a localhost share gets server
|
||||
locations that name the wrong path. This contradicts "the canonical form
|
||||
is VS Code's" and the no-alias property.
|
||||
- Trunk was broken for every UNC path, so this is not worse than trunk.
|
||||
- Suggestion: treat `localhost` as local only before a `/X:` drive letter.
|
||||
- **F3 (low; Windows; new reachable shape).** The reader turns host `.` or `?`
|
||||
into device or verbatim namespace paths that the writer refuses:
|
||||
- `file://./PhysicalDrive0/` → `\\.\PhysicalDrive0\`
|
||||
- `file://./pipe/x` → `\\.\pipe\x`
|
||||
- `file://%3F/GLOBALROOT/x` → `\\?\GLOBALROOT\x`
|
||||
|
||||
Trunk read these as `/PhysicalDrive0/` and similar. A workspace folder or
|
||||
watched-file URI of this shape would make the server open a device or
|
||||
named pipe. Only the client can send one, so the risk is low.
|
||||
- Repro: `qa_no_uri_reads_as_a_device_path`.
|
||||
- Suggestion: refuse these hosts on read, as `unc_shape` already does on
|
||||
write.
|
||||
- **F4 (low; Windows).** The authority is percent-decoded without refusing
|
||||
separators. `file://srv%5Cshare/x.sv` → `\\srv\share\x.sv`: the host becomes
|
||||
host plus share. `file://a%2Fb/c` → `\\a/b\c` → writes `file://a/b/c`.
|
||||
Neither is stable after one step.
|
||||
- Related: `[::1]` and `u@h:80` hosts write back percent-encoded
|
||||
(`file://%5B%3A%3A1%5D/…`) rather than as the client spelled them.
|
||||
Windows UNC takes no IPv6 literals anyway.
|
||||
- Repro: `qa_an_encoded_separator_is_not_a_host_boundary`.
|
||||
- **F5 (low; Windows upgrade effect; not in Handshakes).** `index_cache.rs:735-745`
|
||||
`workspace_key` hashes `root.to_string_lossy()`. Roots come from
|
||||
`uri_to_path` (`main.rs:732-741`, `server/notification.rs:471`), so a
|
||||
Windows root changes from `c:/proj` to `c:\proj`. Every Windows user's
|
||||
persisted index cache key changes once. The result is one cold rescan and
|
||||
an orphaned old cache directory, not corruption. It is worth a line in
|
||||
Handshakes and the CHANGELOG.
|
||||
- **F6 (info).** Trunk's own five-slash UNC URIs (`file://///srv/share/a.sv`)
|
||||
now read as `\\\srv\share\a.sv`, which the writer refuses. I found no place
|
||||
where URIs are persisted (the cache is keyed by path), so only a URI held
|
||||
across an upgrade inside one live session could hit this.
|
||||
- **F7 (info; unchanged from trunk).** `%2F`/`%5C` inside a segment decode to
|
||||
separators: `file:///C:/a%2Fb.sv` → `C:\a\b.sv`, the same file as
|
||||
`file:///C:/a/b.sv`. `%2F..%2F` gives `..` traversal exactly as a literal
|
||||
`/../` does. This is the same as trunk and the same as `vscode-uri` `fsPath`,
|
||||
and it adds no capability.
|
||||
|
||||
Not verified:
|
||||
|
||||
- Windows runtime: no host, no Wine, test executables not run.
|
||||
- Real VS Code, Neovim and other clients: their URI spellings come from
|
||||
knowledge of their source, not from running them.
|
||||
- `hierarchyView.js` inside a real VS Code.
|
||||
|
||||
Scratch directory removed. `git -C /Users/lucio/repo/opentitan status
|
||||
--porcelain` is empty.
|
||||
|
||||
**2026-11-26 (QA, re-QA of the fix round).** Verdict: **PASS with findings**.
|
||||
F1–F4 are fixed, and each fix is caught by a test. F5–F7 are recorded. Three
|
||||
new low or info findings are below: one shape the "fixed after one step"
|
||||
claim misses, one mixed-separator writer gap, and one incomplete sentence in
|
||||
the reworded `scopeDepth` description. None of them blocks the round.
|
||||
Windows runtime remains unverified.
|
||||
|
||||
- **(a) Gates.**
|
||||
- My three `qa_*` tests are un-ignored, their assertions are unchanged
|
||||
(checked by reading them), and they pass.
|
||||
- Guarded `cargo test -p lucisv_server`: 2 262 passed, 0 failed, 53 ignored.
|
||||
The unit tests are 2152/0/48, and `uri::` is 24 passed with 0 ignored.
|
||||
There were no guard kills.
|
||||
- fmt is clean, and clippy `--workspace --all-targets` reports 0 warnings.
|
||||
- node: 37 pass, 0 fail, 0 skipped. `gates.sh --only cross` and
|
||||
`--only docs` both pass. The `vlog_linter` `vscode` tests (`package.json`
|
||||
sync) are green. `stamp_author.py --check` stamps 0 files.
|
||||
- The Windows `cargo test --no-run --target x86_64-pc-windows-gnu
|
||||
-p lucisv_server`, built with the rustup toolchain, links all 5
|
||||
executables with **0 warnings**. Both `#[cfg(unix)]` gates are correct:
|
||||
every user of the gated items is unix-only.
|
||||
- Production lines: `uri.rs` 81, `uri/windows.rs` 82. No
|
||||
unwrap/expect/panic/unsafe/`#[allow]` in library code.
|
||||
- **(b) Harness.** I re-ran my scratch harness on the new files (fresh trunk
|
||||
extract, new files copied unchanged).
|
||||
- **Posix:** 400 000 paths and 545 943 URIs show 0 undeclared differences
|
||||
and 0 round-trip failures. The two declared deltas are still the only
|
||||
ones.
|
||||
- **Windows:** 400 000 paths plus 231 941 readable URIs, raw and validated.
|
||||
The generators now add `localhost`/`LOCALHOST`/`%6Cocalhost`, `.`, `%2E`,
|
||||
`%3F`, `%40`, `%5C`/`%2F` hosts, `srv:445`, `[::1]`, `u@h`, WebDAV and
|
||||
`\\localhost\C:\` heads.
|
||||
- **0 read paths the writer refuses**, 0 invalid URIs written, and no
|
||||
panics.
|
||||
- **1 URI unstable after one step** (N1 below). Every path→URI→path
|
||||
failure belongs to a class that names an illegal Windows path:
|
||||
- 21 427 have a `\\localhost\X:…` drive-like share (N1);
|
||||
- the rest are `\C:…` root-relative names, or `\/…` mixed-separator
|
||||
shapes (N2).
|
||||
|
||||
`:` cannot appear in a Windows file or share name, so none of these is a
|
||||
real file.
|
||||
- **Dev's fuzz:** `every_readable_windows_uri_is_stable_after_one_step`
|
||||
generates `localhost`, `LocalHost`, `.`, `?`, `%2E`, `%3F`, `%2F`, `%5C`,
|
||||
`%00`, `@`, `:`, `[`, `]`. That is rich enough to reach F2–F4. It
|
||||
composes from `file://` only, never from a `file:////` prefix with a
|
||||
`localhost` share, which is why it missed N1.
|
||||
- **Mutation check** on a scratch copy, reverting each fix in turn:
|
||||
- F2 (`localhost` local everywhere) fails 3 tests, including
|
||||
`qa_a_localhost_share_round_trips`.
|
||||
- F3 (`writable` removed) fails 2 tests.
|
||||
- F3 (namespace hosts accepted in `unc_host`) **survives alone**, because
|
||||
`writable` still refuses the result: a redundant second guard, not a
|
||||
gap. With both F3 mechanisms reverted, 3 tests fail, including
|
||||
`qa_no_uri_reads_as_a_device_path`.
|
||||
- F4 (raw `@ : [ ]` check removed) fails
|
||||
`unspellable_hosts_and_shapes_are_refused_on_read`.
|
||||
- F4 (separators accepted in the host) fails 3 tests, including
|
||||
`qa_an_encoded_separator_is_not_a_host_boundary`.
|
||||
- **(c) New refusals.**
|
||||
- Every production caller handles `None` from `uri_to_path` without
|
||||
panicking. The only `expect` is in `file_ops.rs:1633`, inside
|
||||
`mod tests` (line 494).
|
||||
- On `didOpen`, `set_document` (`state/buffers.rs:102-120`) still stores the
|
||||
document under the client's URI with `path: None`, exactly as for an
|
||||
`untitled:` buffer. Lint and format run on its text, and it has no
|
||||
on-disk identity.
|
||||
- Workspace folders (`main.rs:734`, `notification.rs:472`) and watched files
|
||||
(`notification.rs:199`) use `filter_map`, so the root or event is dropped.
|
||||
- Trunk read the same URIs as a host-dropped `\s\a` on the current drive,
|
||||
a wrong and possibly real file. Refusing degrades no worse than that.
|
||||
- On Posix, `file://u@h:80/s/a`, `file://[::1]/s/a` and
|
||||
`file://///srv/share/a.sv` read exactly as on trunk (`/s/a`,
|
||||
`///srv/share/a.sv`). The authority rules apply only under the Windows
|
||||
flavour, and `decode_uri`'s Posix arm is unchanged.
|
||||
- Other shapes, all sane:
|
||||
|
||||
| Input | Read | Written back |
|
||||
|---|---|---|
|
||||
| `file://LOCALHOST/c%3A/x` | `c:\x` | `file:///c%3A/x` |
|
||||
| `file://localhost/C\|/x` | rejected by `fluent_uri` | |
|
||||
| `file://localhost/` | `\\localhost\` | stable |
|
||||
| `file://localhost` | `None` | |
|
||||
| `\\localhost\C:\x` | (path) | `file://localhost/C%3A/x`, which reads `C:\x` (N1) |
|
||||
| `\\srv\c:\x` | (path) | `file://srv/c%3A/x`, which reads back exactly |
|
||||
| WebDAV `\\srv@SSL\DavWWWRoot\a.sv` | (path) | round-trips |
|
||||
|
||||
`\\srv\c:\x` is not a legal share name, but it is neither refused nor
|
||||
mangled.
|
||||
- **(d) F1.**
|
||||
- The corrected README row and `package.json` example match
|
||||
`state/scope.rs:116-133` `raised()`, which climbs from the buffer's own
|
||||
folder. They also match `state/tests/folder_scope.rs`
|
||||
`a_scope_depth_of_one_reaches_the_folder_beside_it` (`rtl/` + 1 = the
|
||||
tree root).
|
||||
- `git diff editors/vscode/package.json` is one line: that
|
||||
`markdownDescription` only.
|
||||
- `settings.rs:62` was wrong in the same way, and **I fixed the comment
|
||||
directly**: a `dv/tb` file reaches `hw/ip/aes`, an `rtl` file reaches
|
||||
`hw/ip`. It is a comment-only change and fmt is clean.
|
||||
- **(e) README.** The before/after rows for the new refusals, the IPv6 and
|
||||
userinfo decision, the F5 handshake, the "Release note needed" item, and
|
||||
F6/F7 under Assumptions are all present and accurate. One exception: the
|
||||
"fixed after one step" claim, see N1.
|
||||
|
||||
New findings:
|
||||
|
||||
- **N1 (low; Windows; illegal names only).** A UNC path whose host is
|
||||
`localhost` and whose share looks like a drive is written as
|
||||
`file://localhost/X%3A/…`. That reads back as the local drive path.
|
||||
- Repro: `file:////localhost/C:/x.sv` (a valid URI) → `\\localhost\C:\x.sv`
|
||||
→ `file://localhost/C%3A/x.sv` → `C:\x.sv`. The same happens with
|
||||
`file:////localhost/a:x`.
|
||||
- This is a counterexample to "URI → path → URI is fixed after one step"
|
||||
(`uri/windows.rs:10-11`, Assumptions).
|
||||
- No real file is affected, because a share name cannot contain `:`.
|
||||
- Suggested fix: `writable`/`unc_shape` refuse host `localhost` with a
|
||||
drive-like share.
|
||||
- **N2 (info; Windows).** `shape()` (`uri/windows.rs`, the `\\`/`//` match)
|
||||
does not recognise the mixed `\/` or `/\` UNC prefixes that Windows
|
||||
accepts.
|
||||
- `\/srv/share/a` writes the non-canonical `file:////srv/share/a`. It still
|
||||
reads back as `\\srv\share\a`.
|
||||
- `\/srv` writes `file:////srv`, which the reader refuses.
|
||||
- Paths from client URIs and walks never take this spelling.
|
||||
- **N3 (low; docs; fix-round change).** The reworded end of the
|
||||
`lucisv.index.scopeDepth` description (`package.json` and the README row)
|
||||
says that with no workspace folder "a lone file indexes its own folder
|
||||
whatever this is set to".
|
||||
- The *folder* part is right (`scope.rs:117-119`). The *read* is not:
|
||||
`discover.rs:360-372` reads that folder flat only at depth 0, and walks it
|
||||
**recursively** at any depth ≥ 1. The test
|
||||
`folder_scope.rs` `a_rootless_session_reads_its_own_directory_flat_until_the_depth_is_raised`
|
||||
pins this.
|
||||
- So at the shipped depth 2, opening `~/x.sv` alone walks all of `~`.
|
||||
Trunk's advice "set it to `0` when you open single files on their own"
|
||||
was accurate, and dropping it loses a useful instruction.
|
||||
|
||||
Not verified: Windows runtime; real-client URI spellings (Neovim, Emacs or
|
||||
Java UNC forms, from knowledge of their source only).
|
||||
|
||||
Scratch directory removed. opentitan `status --porcelain` is empty.
|
||||
|
||||
## Review
|
||||
|
||||
**2026-11-26 — lead: accepted after one fix round, a re-QA, and two small
|
||||
lead edits.**
|
||||
|
||||
- Delivered: Windows UNC `file:` URIs read and written in VS Code's form
|
||||
(`file://server/share/…`), verbatim paths seen through, device and
|
||||
unspellable hosts refused. The Posix flavour is trunk's except the two
|
||||
declared fixes (`\` written `%5C`; `?query#frag` stripped), confirmed by
|
||||
QA's own differential over ~950k inputs, twice.
|
||||
- **Windows is compile- and link-checked only.** No Windows host or Wine was
|
||||
available; every Windows rule was tested as string code on macOS. The
|
||||
`Path` conversion itself has never run.
|
||||
- Ruling on re-QA N1: fixed by the lead — `unc_shape` refuses a `localhost`
|
||||
host whose share is drive-shaped (`\\localhost\C:\x`, not a legal share),
|
||||
so the four-slash spelling no longer changes meaning after one step
|
||||
(`a_localhost_share_named_like_a_drive_is_refused`).
|
||||
- Ruling on re-QA N3: fixed by the lead — the `scopeDepth` description in
|
||||
`package.json` and the README row say again that single files opened with
|
||||
no workspace folder want `0` (any higher value reads the folder
|
||||
recursively, `discover.rs:360-372`).
|
||||
- Accepted limits: N2 (mixed `\/` UNC prefixes are not canonicalised; no
|
||||
client or walk produces them); F6 (trunk's own five-slash URIs are refused;
|
||||
never persisted); F7 (`%2F`/`%5C` in a segment decode to separators, as in
|
||||
`vscode-uri`); URIs with a port, userinfo or IPv6 literal are refused on
|
||||
Windows — the document stays open as a pathless buffer, where trunk read a
|
||||
wrong path.
|
||||
- Release note owed (F5): on Windows a workspace root's spelling changes, so
|
||||
its saved index cache is rebuilt once and the old directory is orphaned.
|
||||
- Editor items: the audit named nothing concrete for these files; the three
|
||||
JS fixes and the README corrections are defects shown by a failing test on
|
||||
trunk's file or by the contradicting code. Tested against stubbed `vscode`
|
||||
only. Left as features: non-`file:` workspace folders and a relative
|
||||
`lucisv.mcp.path` in `mcp.js`.
|
||||
- No §2.9 rows opened or closed by this round.
|
||||
|
||||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|
||||
+1
-1
@@ -43,7 +43,7 @@ lint rules (`8` error, `24` warning, `43` style); persisted facts codec
|
||||
TODO §55 (`state/` decomposition), call hierarchy, top-rooted paths, range/selection
|
||||
formatting, sticky scroll, auto-`end` and instantiation highlighting, the eight-item
|
||||
overnight queue (TODO §71), `instance-folding` (TODO §72), and Round 1–3 correctness,
|
||||
ordering, index-lifecycle, and MCP hardening items. After Rounds 4–10, §2.9 keeps open handshakes `#67` (filed by Round 7),
|
||||
ordering, index-lifecycle, and MCP hardening items. After Rounds 4–11 (Round 11, `windows-uri-editors-r11`, touched no row), §2.9 keeps open handshakes `#67` (filed by Round 7),
|
||||
`#68–70` (filed by Round 8) and `#71–74` (filed by Round 10).
|
||||
See [repository-analysis.md](repository-analysis.md) for evidence and validation.
|
||||
Feature QA logs and TODO checkboxes remain the acceptance authority; remote
|
||||
|
||||
@@ -95,7 +95,7 @@ coc has no `vim.lsp`; it takes servers from `coc-settings.json` (`:CocConfig`):
|
||||
## What you get, and what you don't
|
||||
|
||||
Everything in `docs/features/lucisv-server/README.md`'s capability table:
|
||||
`gd` (definition), `gr` (references, in-file only for now), `K` (hover,
|
||||
`gd` (definition), `gr` (references, across the indexed workspace), `K` (hover,
|
||||
including `` `define`` expansion), `vim.lsp.buf.format()`, document and
|
||||
workspace symbols, diagnostics as you type, and semantic tokens — Neovim
|
||||
applies those on top of its treesitter/syntax highlighting with no extra setup.
|
||||
@@ -196,13 +196,14 @@ agree.
|
||||
|
||||
## When it feels slow: `--verbose`
|
||||
|
||||
The server takes one argument, and it is the only one it takes. Start it with
|
||||
The server takes one option. (`--stdio` is accepted too and changes nothing:
|
||||
stdio is the only transport, and some clients always pass it.) Start it with
|
||||
`--verbose` and every operation says how long it took, as ordinary
|
||||
`window/logMessage` lines in your client's LSP log:
|
||||
|
||||
```lua
|
||||
vim.lsp.config('lucisv', {
|
||||
cmd = { 'lucisv-server', '--verbose' }, -- the one argument the server takes
|
||||
cmd = { 'lucisv-server', '--verbose' }, -- the one option the server takes
|
||||
filetypes = { 'verilog', 'systemverilog' },
|
||||
root_markers = { 'lucisv.toml', '.lucisv.toml', '.git' },
|
||||
})
|
||||
@@ -234,8 +235,8 @@ coc.nvim puts them in its own output channel instead
|
||||
(`:CocCommand workspace.showOutput`); these are the same lines the VS Code
|
||||
extension shows when you turn on `lucisv.verbose`.
|
||||
|
||||
Anything other than `--verbose` is refused: the server prints one usage line on
|
||||
stderr and exits 2, so a misspelled flag shows up as a server that will not
|
||||
Anything other than `--verbose` and `--stdio` is refused: the server names the
|
||||
unknown option and its usage on stderr and exits 2, so a misspelled flag shows up as a server that will not
|
||||
start rather than as a session that quietly logs nothing. Without the flag not
|
||||
one `timing:` line is ever sent — this is a diagnostic, not a default, and a
|
||||
busy session logs a line per keystroke.
|
||||
|
||||
@@ -332,12 +332,20 @@ Server-side templates add `if`, `if/else`, `else if`, `case`, `for`, `while`,
|
||||
| `lucisv.lineLength` | unset | Maximum formatter width, 40–400; built-in default is 100 |
|
||||
| `lucisv.indent` | unset | Indent width, 1–8; falls back to the editor tab size, then 2 |
|
||||
| `lucisv.format.style` | `lucisv` | A drop-down of layout presets — `lucisv`, `google`, `lowrisc`, `ansi`, `microsoft`, `nxp` — or `auto`, which keeps each file in the preset it is already closest to (remembered per document from its last full format, so on-type and selection formatting stay fast and keep the preset while the file has a syntax error). `auto` picks a layout for the configured indent and width and never infers them: set `lucisv.indent` (or the project's `indent`) to match the file first — a 4-space Allman file under `auto` at indent 2 comes out in the `lucisv` layout. A preset also sets the indent and line length, below `lucisv.indent`/`lucisv.lineLength`; `ansi`, `microsoft` and `nxp` are lucisv's guesses, not those organisations' rules. See the [style table](https://git.luci.ooo/lucio/lucisv/src/branch/master/README.md#named-styles) |
|
||||
| `lucisv.format.begin` | unset | Override where a block's `begin` sits after its header (`same-line` or `own-line`), on top of the style; unset lets the style decide |
|
||||
| `lucisv.format.else` | unset | Override where `else` sits after `end` (`same-line` or `own-line`) |
|
||||
| `lucisv.format.elseAfterLabel` | unset | Override where `else` sits after a labelled `end : label` (`same-line` or `own-line`) |
|
||||
| `lucisv.format.portLists` | unset | Override header parameter/port lists and named instance lists (`fit` or `one-per-line`) |
|
||||
| `lucisv.format.listIndent` | unset | Override the indentation of broken header and instance lists (`block` or `wrap`) |
|
||||
| `lucisv.format.alignment` | unset | Override column alignment of header parameters, ANSI ports, parameter declarations and named connections (`infer` or `always`) |
|
||||
| `lucisv.format.connectionAlignMin` | unset | Minimum spaces before `(` on the widest row of an aligned connection or `#(...)` table (`0` gives `.long_port(sig)`, `1` gives `.long_port (sig)`) |
|
||||
| `lucisv.format.uvmUtilsIndent` | `false` | Indent the `` `uvm_field_* `` macros between `` `uvm_*_utils_begin `` and `` _end `` one level; on changes the output of files that are already clean |
|
||||
| `lucisv.exclude` | `[]` | Extra index exclusions added to the project's own patterns |
|
||||
| `lucisv.filelist` | `""` | EDA `.f` filelist to index instead of walking the folder |
|
||||
| `lucisv.hierarchy.duts` | `[]` | Modules the Hierarchy pane treats as DUTs, by name — the checked-in list a team shares. Each one adds two sections ahead of "Other modules"; a DUT from this setting is shown locked and can only be removed here |
|
||||
| `lucisv.hierarchy.highlightCurrent` | `true` | Light the Hierarchy pane's rows leading to the active file, brightest on the file's own module and dimmer each level up |
|
||||
| `lucisv.index.scope` | `folder` | Index the folders your open files live in, or every workspace folder with `workspace`; answers stay scope-relative until the scope reaches a folder |
|
||||
| `lucisv.index.scopeDepth` | `0` | How many folders above an open file the `folder` scope starts from; `1` lets a file in `rtl/` index `include/` beside it |
|
||||
| `lucisv.index.scopeDepth` | `2` | How many folders above an open file the `folder` scope starts from, never leaving its workspace folder; `2` lets a file in `hw/ip/aes/dv/tb/` index all of `hw/ip/aes/` (from `hw/ip/aes/rtl/` it reaches `hw/ip/`), and `0` is the file's own folder alone; with no workspace folder open it does not climb, but any value above `0` still reads the file's folder recursively, so use `0` for single files opened on their own |
|
||||
| `lucisv.index.maxFileSize` | `1 MiB` | Largest walked file the index reads, in bytes; `0` removes the cap, and a file you open is always indexed in full |
|
||||
| `lucisv.index.logFiles` | `true` | Name every indexed, cached, and cap-skipped file in the lucisv output channel |
|
||||
| `lucisv.index.persist` | `true` | Remember what indexing each file found, so a reopen resumes instead of rescanning |
|
||||
@@ -359,8 +367,9 @@ Server-side templates add `if`, `if/else`, `else if`, `case`, `for`, `while`,
|
||||
| `lucisv.verbose` | `false` | Print how long every operation took in the lucisv output channel — one `timing:` line per request, notification, scan, widen, buffer flush, and per request that had to wait behind a rescan. **Restarts the language server when changed**, because it is an argument the server is started with |
|
||||
|
||||
The six `lucisv.index.*` settings and `lucisv.largeFile.threshold` arrive with
|
||||
the [large workspaces](#large-workspaces) work; everything else ships in
|
||||
0.10.2. The `lucisv.lint.*` settings are **generated from the rule registry**,
|
||||
the [large workspaces](#large-workspaces) work; the rest arrived with the
|
||||
features they configure (the changelog names each). A checked-in `lucisv.toml`
|
||||
outranks every `lucisv.format.*` override. The `lucisv.lint.*` settings are **generated from the rule registry**,
|
||||
so a rule cannot ship without its toggle.
|
||||
|
||||
When several of them disagree, this is the order — each step may undo the one
|
||||
|
||||
@@ -109,12 +109,17 @@ class HierarchyView {
|
||||
enableScripts: true,
|
||||
localResourceRoots: [media],
|
||||
};
|
||||
this.context.subscriptions.push(
|
||||
view.webview.onDidReceiveMessage((message) => this.message(message)),
|
||||
view.onDidDispose(() => {
|
||||
if (this.view === view) this.view = undefined;
|
||||
}),
|
||||
);
|
||||
// Held by the view, not by the extension's subscriptions: a view VS Code
|
||||
// disposes and resolves again must not leave its listeners behind.
|
||||
const listeners = [
|
||||
// VS Code drops the listener's promise, so a failure here (a definition
|
||||
// whose file is gone) is reported rather than left unhandled.
|
||||
view.webview.onDidReceiveMessage((message) => this.message(message).catch(reportFailure)),
|
||||
];
|
||||
listeners.push(view.onDidDispose(() => {
|
||||
if (this.view === view) this.view = undefined;
|
||||
for (const listener of listeners) listener.dispose();
|
||||
}));
|
||||
// Install the receiver before loading the document: its script posts
|
||||
// `ready` immediately, and even a fast webview must not outrun the host.
|
||||
view.webview.html = html(view.webview, media);
|
||||
@@ -441,6 +446,13 @@ class HierarchyView {
|
||||
}
|
||||
}
|
||||
|
||||
/// One warning for a row action that failed, instead of an unhandled rejection
|
||||
/// the user never sees.
|
||||
function reportFailure(error) {
|
||||
const reason = (error && error.message) || String(error);
|
||||
vscode.window.showWarningMessage(`lucisv hierarchy: ${reason}`);
|
||||
}
|
||||
|
||||
/// The active editor's file as a comparable string, or `undefined` for none.
|
||||
/// The Output panel's channels are text editors too, and are never a module.
|
||||
function activeUriOf(editor) {
|
||||
|
||||
@@ -22,6 +22,8 @@ let configurationChanged;
|
||||
let activeEditorChanged;
|
||||
/** What `lucisv.hierarchy.highlightCurrent` is set to; unset is the default. */
|
||||
let highlightCurrent;
|
||||
/** Whether the stub's `openTextDocument` rejects, as it does for a deleted file. */
|
||||
let openFails = false;
|
||||
|
||||
class Range {
|
||||
constructor(startLine, startCharacter, endLine, endCharacter) {
|
||||
@@ -58,6 +60,7 @@ const vscode = {
|
||||
},
|
||||
onDidChangeConfiguration(handler) { configurationChanged = handler; return disposables(); },
|
||||
async openTextDocument(uri) {
|
||||
if (openFails) throw new Error(`cannot open ${uri.value}`);
|
||||
opened.push(uri.value);
|
||||
return {
|
||||
uri,
|
||||
@@ -320,7 +323,8 @@ async function run() {
|
||||
|
||||
await theActiveFileIsLitWithoutARefetch(rendered);
|
||||
await persistenceSurvivesAReload();
|
||||
console.log('hierarchy view: OK — collapsed rows, lazy opening, search list, navigation, menu, bookmark, no preview, DUT sections (star, unstar, clear, persistence, the setting lock), and the active file lit (relit in place, no refetch, the setting)');
|
||||
await aFailedActionIsReportedAndADisposedViewLetsGo();
|
||||
console.log('hierarchy view: OK — collapsed rows, lazy opening, search list, navigation, menu, bookmark, no preview, DUT sections (star, unstar, clear, persistence, the setting lock), the active file lit (relit in place, no refetch, the setting), a failed action reported, a disposed view releasing its listeners');
|
||||
}
|
||||
|
||||
function editorFor(value, scheme = 'file') {
|
||||
@@ -403,6 +407,43 @@ async function persistenceSurvivesAReload() {
|
||||
], 'both starred names come back, the number 7 and the blank do not');
|
||||
}
|
||||
|
||||
/// A row action whose file cannot be opened warns instead of rejecting the
|
||||
/// promise VS Code drops; and a view VS Code disposes releases its own
|
||||
/// listeners rather than leaving them on the extension's subscriptions.
|
||||
async function aFailedActionIsReportedAndADisposedViewLetsGo() {
|
||||
state.clear();
|
||||
new HierarchyView(context, client);
|
||||
const subscriptionsBefore = context.subscriptions.length;
|
||||
const disposed = [];
|
||||
const counted = (name) => ({ dispose() { disposed.push(name); } });
|
||||
let disposeView;
|
||||
const posts = [];
|
||||
provider.resolveWebviewView({
|
||||
webview: {
|
||||
...webview,
|
||||
postMessage(message) { posts.push(message); },
|
||||
onDidReceiveMessage(handler) { receive = handler; return counted('message'); },
|
||||
},
|
||||
onDidDispose(handler) { disposeView = handler; return counted('dispose'); },
|
||||
});
|
||||
assert.equal(context.subscriptions.length, subscriptionsBefore, 'the view holds its own listeners');
|
||||
await receive({ type: 'ready' });
|
||||
const top = posts.findLast((message) => message.type === 'render').rows[0];
|
||||
assert.equal(top.label, 'top');
|
||||
|
||||
// Opening `top`'s definition fails, as it does when the file was deleted.
|
||||
openFails = true;
|
||||
const warnedBefore = warned.length;
|
||||
const outcome = await receive({ type: 'activate', id: top.id }).then(() => 'resolved', () => 'rejected');
|
||||
openFails = false;
|
||||
assert.equal(outcome, 'resolved', 'the promise VS Code drops never rejects');
|
||||
assert.equal(warned.length, warnedBefore + 1, 'one warning');
|
||||
assert.equal(warned.at(-1), 'lucisv hierarchy: cannot open file:///top.sv');
|
||||
|
||||
disposeView();
|
||||
assert.deepEqual(disposed.sort(), ['dispose', 'message'], 'both listeners disposed with the view');
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
|
||||
@@ -131,10 +131,14 @@ async function copyConfig(context, bundledBinary, log) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Whether `command` names a file: as given if it has a directory part, else somewhere on PATH. */
|
||||
/**
|
||||
* Whether `command` names a file: as given if it has a directory part, else
|
||||
* somewhere on PATH. On Windows `lucisv-mcp` also matches `lucisv-mcp.exe`,
|
||||
* with or without a directory part, because that is what the spawn runs.
|
||||
*/
|
||||
function findable(command) {
|
||||
if (command.includes('/') || command.includes('\\')) return fs.existsSync(command);
|
||||
const names = process.platform === 'win32' ? [command, `${command}.exe`] : [command];
|
||||
if (command.includes('/') || command.includes('\\')) return names.some((name) => fs.existsSync(name));
|
||||
return (process.env.PATH || '')
|
||||
.split(path.delimiter)
|
||||
.filter((dir) => dir !== '')
|
||||
|
||||
@@ -255,6 +255,27 @@ function aMissingBinaryIsNotStarted() {
|
||||
assert.match(log[0], /"lucisv-mcp" not found/);
|
||||
}
|
||||
|
||||
/// On Windows a spawn of `C:\tools\lucisv-mcp` runs `lucisv-mcp.exe`, so a
|
||||
/// `lucisv.mcp.path` written without the extension must not be refused.
|
||||
function aWindowsPathWithoutExeIsFound() {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'lucisv-mcp-exe-'));
|
||||
const exe = path.join(dir, 'lucisv-mcp.exe');
|
||||
fs.writeFileSync(exe, '');
|
||||
const bare = path.join(dir, 'lucisv-mcp');
|
||||
const platform = Object.getOwnPropertyDescriptor(process, 'platform');
|
||||
try {
|
||||
Object.defineProperty(process, 'platform', { value: 'win32' });
|
||||
assert.equal(mcp.findable(bare), true, 'win32: a directory part without .exe finds the .exe');
|
||||
assert.equal(mcp.findable(exe), true, 'win32: the .exe itself');
|
||||
assert.equal(mcp.findable(path.join(dir, 'other')), false, 'win32: a missing file is still missing');
|
||||
Object.defineProperty(process, 'platform', { value: 'linux' });
|
||||
assert.equal(mcp.findable(bare), false, 'elsewhere the name is exactly the file');
|
||||
} finally {
|
||||
Object.defineProperty(process, 'platform', platform);
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
async function theThreeSnippets() {
|
||||
const want = {
|
||||
'Claude Code': ['.mcp.json', { mcpServers: { lucisv: { command: '/ext/bin/lucisv-mcp', args: ['--root', '/work/alpha', '--root', '/work/beta'] } } }],
|
||||
@@ -331,9 +352,10 @@ async function run() {
|
||||
disabledOffersNothing();
|
||||
anOldVsCodeRegistersNothing();
|
||||
aMissingBinaryIsNotStarted();
|
||||
aWindowsPathWithoutExeIsFound();
|
||||
await theThreeSnippets();
|
||||
await theReadOnlySnippets();
|
||||
console.log('mcp: OK — binary ladder, one definition per folder, change events, read-only definitions, unknown mode fails safe to read-only, enabled:false, old-VS Code guard, missing binary, three config snippets in both modes');
|
||||
console.log('mcp: OK — binary ladder, one definition per folder, change events, read-only definitions, unknown mode fails safe to read-only, enabled:false, old-VS Code guard, missing binary, a Windows path without .exe, three config snippets in both modes');
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
|
||||
@@ -771,7 +771,7 @@
|
||||
"type": "number",
|
||||
"default": 2,
|
||||
"minimum": 0,
|
||||
"markdownDescription": "How many folders **above** an open file the `folder` scope starts from — the reach for relative files. `2` (the default) starts two folders up, which in a typical layout is the whole block an open file belongs to: a file in `hw/ip/aes/rtl/` indexes all of `hw/ip/aes/`, `dv/` and `rtl/` together. `0` is the file's own folder and nothing above it — the old default, and the narrowest, fastest scope there is. The climb never leaves the workspace folder that contains the file, so a large number simply means the whole workspace folder. Raising this widens every answer listed under `#lucisv.index.scope#` and costs a larger scan. Ignored when `#lucisv.index.scope#` is `workspace` or a `#lucisv.filelist#` is set. With **no** workspace folder open there is nothing to clamp the climb against, so set it to `0` when you open single files on their own."
|
||||
"markdownDescription": "How many folders **above** an open file the `folder` scope starts from — the reach for relative files. `2` (the default) starts two folders up: a file in `hw/ip/aes/dv/tb/` indexes all of `hw/ip/aes/`, its `dv/` and `rtl/` together, while a file in `hw/ip/aes/rtl/` climbs the same two folders, to `hw/ip/`. `0` is the file's own folder and nothing above it — the old default, and the narrowest, fastest scope there is. The climb never leaves the workspace folder that contains the file, so a large number simply means the whole workspace folder. Raising this widens every answer listed under `#lucisv.index.scope#` and costs a larger scan. Ignored when `#lucisv.index.scope#` is `workspace` or a `#lucisv.filelist#` is set. With **no** workspace folder open there is nothing to clamp the climb against, so the scope does not climb: a lone file indexes its own folder — that folder alone at `0`, and everything beneath it at any higher value — so set it to `0` when you open single files on their own."
|
||||
},
|
||||
"lucisv.index.maxFileSize": {
|
||||
"type": "number",
|
||||
|
||||
Reference in new issue
Block a user