diff --git a/crates/ruff_db/src/files.rs b/crates/ruff_db/src/files.rs index 754b65642acbb..d7b5ecdeb5c6c 100644 --- a/crates/ruff_db/src/files.rs +++ b/crates/ruff_db/src/files.rs @@ -190,6 +190,7 @@ impl Files { let roots = self.inner.roots.read().unwrap(); let absolute = SystemPath::absolute(path, db.system().current_directory()); + roots.at(&absolute) } @@ -211,7 +212,10 @@ impl Files { let mut roots = self.inner.roots.write().unwrap(); let absolute = SystemPath::absolute(path, db.system().current_directory()); - roots.try_add(db, absolute, kind) + // We need to resolve away symlinks here to avoid getting confused about subdirectories. + let canonicalized = db.system().canonicalize_path(&absolute).unwrap_or(absolute); + + roots.try_add(db, canonicalized, kind) } /// Updates the revision of the root for `path`. diff --git a/crates/ty_test/src/db.rs b/crates/ty_test/src/db.rs index cb05fa0bd8e49..16fbe770b6897 100644 --- a/crates/ty_test/src/db.rs +++ b/crates/ty_test/src/db.rs @@ -1,4 +1,4 @@ -use camino::{Utf8Component, Utf8PathBuf}; +use camino::{Utf8Component, Utf8PathBuf, Utf8Prefix}; use ruff_db::Db as SourceDb; use ruff_db::diagnostic::Severity; use ruff_db::files::{File, Files}; @@ -180,11 +180,18 @@ impl System for MdtestSystem { .canonicalize_path(&self.normalize_path(path))?; if let MdtestSystemInner::Os { os_system, .. } = &*self.0 { - // Make the path relative to the current directory - Ok(canonicalized - .strip_prefix(os_system.current_directory()) - .unwrap() - .to_owned()) + // Make the path relative to the current directory if the path doesn't require + // UNC gunk (`//?/`) to be valid (`strip_prefix` gets really messy otherwise). + if let Some(Utf8Component::Prefix(prefix)) = canonicalized.components().next() + && let Utf8Prefix::VerbatimDisk(_) = prefix.kind() + { + Ok(canonicalized) + } else { + Ok(canonicalized + .strip_prefix(os_system.current_directory()) + .unwrap() + .to_owned()) + } } else { Ok(canonicalized) }