Fix Windows path handling in diagnostic relativization

Canonicalize `current_dir()` to match canonicalized file paths (avoids
`\\?\` prefix mismatch on Windows), and normalize backslashes to
forward slashes in relative diagnostic paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paolo Tranquilli
2026-05-13 10:31:48 +02:00
parent c3cf7c2bca
commit c2fc0cf111
3 changed files with 5 additions and 3 deletions

View File

@@ -94,7 +94,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
node_types::read_node_types_str("erb", tree_sitter_embedded_template::NODE_TYPES)?;
let lines: std::io::Result<Vec<String>> = std::io::BufReader::new(file_list).lines().collect();
let lines = lines?;
let source_root = std::env::current_dir().ok();
let source_root = std::env::current_dir().ok().and_then(|d| d.canonicalize().ok());
lines
.par_iter()
.try_for_each(|line| {

View File

@@ -298,7 +298,9 @@ pub fn extract(
yeast_runner: Option<&yeast::Runner<'_>>,
) {
let path_str = file_paths::normalize_and_transform_path(path, transformer);
let source_root = std::env::current_dir().ok();
let source_root = std::env::current_dir()
.ok()
.and_then(|d| d.canonicalize().ok());
let diagnostics_path = file_paths::relativize_for_diagnostic(path, source_root.as_deref());
let span = tracing::span!(
tracing::Level::TRACE,

View File

@@ -11,7 +11,7 @@ pub fn relativize_for_diagnostic(path: &Path, source_root: Option<&Path>) -> Str
source_root
.and_then(|root| path.strip_prefix(root).ok())
.and_then(|rel| rel.to_str())
.map(|s| s.to_owned())
.map(|s| s.replace('\\', "/"))
.unwrap_or_else(|| path.display().to_string())
}