Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
workspace: Fix terminal links outside worktrees when the remote OS differs (#66594)
Bruno Cordioli145bcfc1bc3a
diff --git a/crates/workspace/src/path_link.rs b/crates/workspace/src/path_link.rsindex d451e3b2fa9..d26e9386a6c 100644--- a/crates/workspace/src/path_link.rs+++ b/crates/workspace/src/path_link.rs@@ -360,7 +360,8 @@ fn resolve_open_target_internal(})}BackgroundPathChecks::ProjectPathResolution => {- let paths_to_check = project_paths_to_check(&potential_paths, cwd);+ let path_style = project.read(cx).path_style(cx);+ let paths_to_check = project_paths_to_check(&potential_paths, cwd, path_style);cx.spawn(async move |cx| {for mut path_to_check in paths_to_check {let path = path_to_check.path.to_string_lossy();@@ -522,16 +523,18 @@ fn local_paths_to_check(fn project_paths_to_check(potential_paths: &[PathWithPosition],cwd: Option<&Path>,+ path_style: PathStyle,) -> Vec<PathWithPosition> {cwd.iter().flat_map(|cwd| {- potential_paths- .iter()- .filter_map(|path_to_check| normalize_absolute_candidate(cwd, path_to_check))+ potential_paths.iter().filter_map(|path_to_check| {+ normalize_absolute_candidate(cwd, path_to_check, path_style)+ })}).chain(potential_paths.iter().filter_map(|path_to_check| {let maybe_path = &path_to_check.path;- (maybe_path.starts_with("~") || maybe_path.is_absolute()).then(|| path_to_check.clone())+ (maybe_path.starts_with("~") || path_style.is_absolute(maybe_path))+ .then(|| path_to_check.clone())})).collect()}@@ -539,8 +542,9 @@ fn project_paths_to_check(fn normalize_absolute_candidate(cwd: &Path,path_to_check: &PathWithPosition,+ path_style: PathStyle,) -> Option<PathWithPosition> {- path_to_check.path.is_relative().then(|| {+ (!path_style.is_absolute(&path_to_check.path)).then(|| {normalize_lexically(&cwd.join(&path_to_check.path)).ok().map(|path| PathWithPosition {@@ -550,3 +554,24 @@ fn normalize_absolute_candidate(})})?}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_project_paths_to_check_uses_the_project_path_style() {+ let unix = PathWithPosition::parse_str("/home/user/notes/spec.md:12");+ let windows = PathWithPosition::parse_str("C:\\Users\\user\\spec.md");+ let relative = PathWithPosition::parse_str("src/main.rs");+ let candidates = [unix.clone(), windows.clone(), relative];+ assert_eq!(+ project_paths_to_check(&candidates, None, PathStyle::Unix),+ vec![unix]+ );+ assert_eq!(+ project_paths_to_check(&candidates, None, PathStyle::Windows),+ vec![windows]+ );+ }+}