Skip to content

Commit c2fc0cf

Browse files
redsun82Copilot
andcommitted
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>
1 parent c3cf7c2 commit c2fc0cf

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

ruby/extractor/src/extractor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
9494
node_types::read_node_types_str("erb", tree_sitter_embedded_template::NODE_TYPES)?;
9595
let lines: std::io::Result<Vec<String>> = std::io::BufReader::new(file_list).lines().collect();
9696
let lines = lines?;
97-
let source_root = std::env::current_dir().ok();
97+
let source_root = std::env::current_dir().ok().and_then(|d| d.canonicalize().ok());
9898
lines
9999
.par_iter()
100100
.try_for_each(|line| {

shared/tree-sitter-extractor/src/extractor/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ pub fn extract(
298298
yeast_runner: Option<&yeast::Runner<'_>>,
299299
) {
300300
let path_str = file_paths::normalize_and_transform_path(path, transformer);
301-
let source_root = std::env::current_dir().ok();
301+
let source_root = std::env::current_dir()
302+
.ok()
303+
.and_then(|d| d.canonicalize().ok());
302304
let diagnostics_path = file_paths::relativize_for_diagnostic(path, source_root.as_deref());
303305
let span = tracing::span!(
304306
tracing::Level::TRACE,

shared/tree-sitter-extractor/src/file_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn relativize_for_diagnostic(path: &Path, source_root: Option<&Path>) -> Str
1111
source_root
1212
.and_then(|root| path.strip_prefix(root).ok())
1313
.and_then(|rel| rel.to_str())
14-
.map(|s| s.to_owned())
14+
.map(|s| s.replace('\\', "/"))
1515
.unwrap_or_else(|| path.display().to_string())
1616
}
1717

0 commit comments

Comments
 (0)