Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(windows): treat rooted debug source paths as absolute

rokartur5334c063bbba
diff --git a/native/crates/app/src/debug/session.rs b/native/crates/app/src/debug/session.rs
index 7a6a59174c2..1e05b46a0d8 100644
--- a/native/crates/app/src/debug/session.rs
+++ b/native/crates/app/src/debug/session.rs
@@ -50,7 +50,7 @@ impl StackFrame {
/// The file the frame is in, when it is on disk.
pub fn path(&self) -> Option<&str> {
let reference = self.source["sourceReference"].as_i64().unwrap_or(0);
- self.source["path"].as_str().filter(|path| reference <= 0 && std::path::Path::new(path).is_absolute())
+ self.source["path"].as_str().filter(|path| reference <= 0 && std::path::Path::new(path).has_root())
}
/// `Source.name`, else the path's last segment.
@@ -494,7 +494,8 @@ fn path_to_uri(source: &mut Value) {
let rest = rest.strip_prefix("//").unwrap_or(rest);
let (authority, path) = rest.split_at(rest.find('/').unwrap_or(rest.len()));
json!({ "$mid": 1, "scheme": scheme, "authority": authority, "path": percent_decode(path), "query": "", "fragment": "" })
- } else if std::path::Path::new(path).is_absolute() {
+ } else if std::path::Path::new(path).has_root() {
+ // path.isAbsolute: node's win32.isAbsolute counts a rooted `/a/b.js`, Path::is_absolute does not.
crate::uri::Uri::file(path).to_json()
} else {
return;
diff --git a/native/crates/app/src/debug/session/tests.rs b/native/crates/app/src/debug/session/tests.rs
index b9e661513b3..7b8a22a0fd5 100644
--- a/native/crates/app/src/debug/session/tests.rs
+++ b/native/crates/app/src/debug/session/tests.rs
@@ -21,7 +21,8 @@ fn request_paths_become_uris_and_response_uris_become_paths() {
let response = json!({ "type": "response", "success": true, "command": "stackTrace", "body": { "stackFrames": [{ "id": 1, "source": { "path": { "scheme": "file", "path": "/a/b.js" } } }, { "id": 2 }] } });
let converted = from_adapter_paths(&response);
- assert_eq!(converted["body"]["stackFrames"][0]["source"]["path"], "/a/b.js");
+ let fs_path = if cfg!(windows) { "\\a\\b.js" } else { "/a/b.js" };
+ assert_eq!(converted["body"]["stackFrames"][0]["source"]["path"], fs_path);
let event = json!({ "type": "event", "event": "output", "body": { "output": "x", "source": { "path": { "scheme": "untitled", "path": "Untitled-1" } } } });
assert_eq!(from_adapter_paths(&event)["body"]["source"]["path"], "untitled:Untitled-1");
}