Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/ruff_db/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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`.
Expand Down
19 changes: 13 additions & 6 deletions crates/ty_test/src/db.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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())
}
Comment on lines +183 to +194
Copy link
Contributor Author

@Gankra Gankra Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "Hillarious" interaction between strip_prefix and dunce.

dunce removes "unnecessary" UNC prefixes, but the import_basic mdtest actually passes in a really really really long path, which dunce then goes "ah UNC is needed".

This results in canonicalized.strip_prefix(os_system.current_directory()) failing.

If you then go "ah I will simply canonicalize os_system.current_directory()" you still lose because dunce is very helpful and removes the unnecessary UNC prefix from the much shorter cwd!

} else {
Ok(canonicalized)
}
Expand Down
Loading