From 73ad8e3ed01740371df9c1ea579e3f74c4e098d5 Mon Sep 17 00:00:00 2001
From: "Ivan K." <18464660+h4nz4@users.noreply.github.com>
Date: Thu, 12 Nov 2026 21:00:35 +0000
Subject: [PATCH] Fix opening `ssh://` links with a drive letter on Windows
remotes (#66814)
## Summary
Closes #66813
`ssh://host/C:/project` (and `zed://ssh/host/C:/...`) sends
`/C:/project` to the remote, because a URL path keeps a `/` before a
Windows drive letter. A Windows remote server cannot canonicalize that
path (os error 123), so the project fails to open with
`DevServerProjectPathDoesNotExist`.
This is a follow-up to #66497, which fixed the same leading `/` for
local `file://` and `zed://file` links. That fix could not be reused
here: it checks the local OS while the URL is parsed, and for SSH the
remote's OS is only known after connecting. This change strips the slash
in `determine_paths_with_positions`, which runs after the connection and
can ask the remote for its path style. Paths on Unix remotes and `/~`
paths are left alone.
Before (Zed 1.27.0):
After (this branch, same URL):
## Testing
- Windows 11 Pro with OpenSSH Server, connected to itself over
`localhost` (setup in #66813).
- Zed 1.27.0: `zed
ssh://zed-win-repro/C:/Users//zed-ssh-repro/project` fails with
`DevServerProjectPathDoesNotExist path=/C:/...`.
- This branch, debug build, with the remote server built from the same
commit: the same URL opens the project, and the worktree is
`C:\Users\\zed-ssh-repro\project`.
- `cargo test -p recent_projects --lib remote_connections`: 6 passed,
including the new `test_strip_slash_before_drive_letter`, which covers
both path styles and the paths that must stay unchanged.
- `cargo clippy -p recent_projects --tests`: no warnings.
To test a debug build against a Windows remote: the debug remote server
panics outside the checkout ("dev asset loading requires running from
within the checkout"), so build it with `cargo build -p remote_server
--features util/debug-embed` and set `ZED_COPY_REMOTE_SERVER` to
`target/debug/remote-server.exe`.
## Self-review
- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist). (No UI
changes.)
- [x] Tests cover the new or changed behavior.
Release Notes:
- Fixed `ssh://` links with a drive letter (for example
`ssh://user@host/C:/project`) failing to open a project on a Windows
remote.
---
.../recent_projects/src/remote_connections.rs | 241 +++++++++++++++++-
crates/remote/src/transport/mock.rs | 45 +++-
crates/util/src/paths.rs | 41 +++
crates/workspace/src/workspace.rs | 31 ++-
crates/zed/src/zed/open_listener.rs | 18 +-
5 files changed, 348 insertions(+), 28 deletions(-)
diff --git a/crates/recent_projects/src/remote_connections.rs b/crates/recent_projects/src/remote_connections.rs
index 72dc75d5d27..e060ae376ec 100644
--- a/crates/recent_projects/src/remote_connections.rs
+++ b/crates/recent_projects/src/remote_connections.rs
@@ -16,7 +16,7 @@ use remote::{
};
pub use settings::SshConnection;
use settings::{DevContainerConnection, ExtendingVec, RegisterSetting, Settings, WslConnection};
-use util::paths::PathWithPosition;
+use util::paths::{PathStyle, PathWithPosition, url_path_to_path};
use workspace::{AppState, MultiWorkspace, OpenOptions, Workspace, find_existing_workspace};
pub use remote_connection::{
@@ -456,6 +456,7 @@ pub(crate) async fn determine_paths_with_positions(
mut paths: Vec,
) -> (Vec, Vec) {
let mut paths_with_positions = Vec::::new();
+ url_paths_to_paths(&mut paths, remote_connection.path_style());
for path in &mut paths {
if let Some(path_str) = path.to_str() {
let path_with_position = PathWithPosition::parse_str(&path_str);
@@ -472,6 +473,16 @@ pub(crate) async fn determine_paths_with_positions(
(paths, paths_with_positions)
}
+/// `ssh://` URL paths are converted here rather than when the URL is parsed, because the remote's
+/// path style is only known once connected.
+fn url_paths_to_paths(paths: &mut [PathBuf], path_style: PathStyle) {
+ for path in paths {
+ if let Some(url_path) = path.to_str() {
+ *path = PathBuf::from(url_path_to_path(url_path, path_style));
+ }
+ }
+}
+
async fn path_exists(connection: &Arc, path: &Path) -> bool {
let Ok(command) = connection.build_command(
Some("test".to_string()),
@@ -509,6 +520,234 @@ mod tests {
use util::path;
use workspace::find_existing_workspace;
+ // Each remote path style is set explicitly, so the client and remote styles differ on every
+ // platform the tests run on.
+ #[gpui::test]
+ async fn test_determine_paths_with_positions_converts_url_paths_for_remote_path_style(
+ cx: &mut TestAppContext,
+ server_cx: &mut TestAppContext,
+ ) {
+ init_test(cx);
+ // As parsed from `ssh://host/C:/`, `ssh://host/C:/project/src/lib.rs` and `ssh://host/a:12`.
+ let url_paths = ["/C:/", "/C:/project/src/lib.rs", "/a:12"];
+ for (path_style, expected_paths) in [
+ (PathStyle::Windows, ["C:/", "C:/project/src/lib.rs", "/a"]),
+ (PathStyle::Unix, ["/C:/", "/C:/project/src/lib.rs", "/a"]),
+ ] {
+ let (opts, _server_session, connect_guard) = RemoteClient::fake_server(cx, server_cx);
+ cx.update(|cx| remote::MockConnection::set_path_style(&opts, path_style, cx));
+ drop(connect_guard);
+ let connection =
+ remote::connect(opts, Arc::new(remote::MockDelegate), &mut cx.to_async())
+ .await
+ .unwrap();
+
+ let (paths, paths_with_positions) = determine_paths_with_positions(
+ &connection,
+ url_paths.iter().map(PathBuf::from).collect(),
+ )
+ .await;
+
+ let expected_paths = expected_paths.map(PathBuf::from).to_vec();
+ assert_eq!(paths, expected_paths, "{path_style:?}");
+ assert_eq!(
+ paths_with_positions
+ .iter()
+ .map(|path| (path.path.clone(), path.row))
+ .collect::>(),
+ expected_paths
+ .into_iter()
+ .zip([None, None, Some(12)])
+ .collect::>(),
+ "{path_style:?}"
+ );
+ }
+ }
+
+ // A remote workspace on a Unix host cannot hold a `C:` path, so this needs a Windows host.
+ #[cfg(target_os = "windows")]
+ #[gpui::test]
+ async fn test_drive_letter_url_path_matches_saved_connection_with_other_options(
+ cx: &mut TestAppContext,
+ server_cx: &mut TestAppContext,
+ ) {
+ let app_state = init_test(cx);
+ let (opts, _headless) = init_remote_server(cx, server_cx).await;
+ let host = || SshConnectionOptions {
+ host: "example.com".to_string().into(),
+ ..Default::default()
+ };
+ // A saved connection keeps its timeout; options built from a URL leave it unset.
+ let saved = RemoteConnectionOptions::Ssh(SshConnectionOptions {
+ connection_timeout: Some(30),
+ ..host()
+ });
+ cx.update(|cx| remote::MockConnection::report_connection_options(&opts, saved, cx));
+ let mut async_cx = cx.to_async();
+ let window = open_remote_project(
+ opts,
+ vec![PathBuf::from(path!("/project"))],
+ app_state,
+ workspace::OpenOptions::default(),
+ &mut async_cx,
+ )
+ .await
+ .unwrap();
+ cx.executor().run_until_parked();
+
+ let found = find_existing_workspace(
+ &[PathBuf::from("/C:/project/src/lib.rs")],
+ &workspace::OpenOptions::default(),
+ &ProjectHost::Remote(&RemoteConnectionOptions::Ssh(host())),
+ &mut async_cx,
+ );
+
+ assert_eq!(found.map(|target| target.window), Some(window));
+ }
+
+ // A retained workspace on a Windows host matches the requested host, which now answers with a
+ // Unix path style, as when an SSH alias is repointed. Its style must not leak into the paths
+ // sent over the fresh connection. It stays connected because the mock disconnect looks the
+ // connection up by its reported options; no lookup here depends on connection state.
+ #[gpui::test]
+ async fn test_url_path_reaches_fresh_connection_unconverted(
+ cx: &mut TestAppContext,
+ server_cx: &mut TestAppContext,
+ ) {
+ let app_state = init_test(cx);
+ let (opts, _headless) = init_remote_server(cx, server_cx).await;
+ let requested_paths = Arc::new(std::sync::Mutex::new(Vec::new()));
+ cx.update(|cx| {
+ remote::MockConnection::set_path_style(&opts, PathStyle::Unix, cx);
+ remote::MockConnection::intercept_messages(
+ &opts,
+ cx,
+ {
+ let requested_paths = requested_paths.clone();
+ move |envelope| {
+ if let Some(proto::envelope::Payload::AddWorktree(request)) =
+ envelope.payload.as_mut()
+ {
+ // Record the path, then open one the fake server has.
+ let path = path!("/project/src/lib.rs").to_string();
+ let requested = std::mem::replace(&mut request.path, path);
+ requested_paths.lock().unwrap().push(requested);
+ }
+ }
+ },
+ |_| {},
+ );
+ });
+
+ let (stale_opts, stale_session, stale_guard) = RemoteClient::fake_server(cx, server_cx);
+ let ping_handler = server_cx.new(|_| ());
+ stale_session.add_request_handler::(
+ ping_handler.downgrade(),
+ |_, _, _| async { Ok(proto::Ack {}) },
+ );
+ cx.update(|cx| {
+ remote::MockConnection::set_path_style(&stale_opts, PathStyle::Windows, cx);
+ remote::MockConnection::report_connection_options(&stale_opts, opts.clone(), cx);
+ });
+ drop(stale_guard);
+ let stale_client = RemoteClient::connect_mock(stale_opts, cx).await;
+ let stale_project = cx.update(|cx| {
+ Project::remote(
+ stale_client.clone(),
+ app_state.client.clone(),
+ app_state.node_runtime.clone(),
+ app_state.user_store.clone(),
+ app_state.languages.clone(),
+ app_state.fs.clone(),
+ false,
+ cx,
+ )
+ });
+ cx.add_window(|window, cx| {
+ let workspace = cx.new(|cx| {
+ Workspace::new(None, stale_project.clone(), app_state.clone(), window, cx)
+ });
+ MultiWorkspace::new(workspace, window, cx)
+ });
+ cx.executor().run_until_parked();
+ assert_eq!(
+ stale_project.read_with(cx, |project, cx| project.path_style(cx)),
+ PathStyle::Windows
+ );
+
+ // As parsed from `ssh://host/C:/project/src/lib.rs`, opened with `--new`.
+ open_remote_project(
+ opts,
+ vec![PathBuf::from("/C:/project/src/lib.rs")],
+ app_state,
+ workspace::OpenOptions {
+ workspace_matching: workspace::WorkspaceMatching::None,
+ ..Default::default()
+ },
+ &mut cx.to_async(),
+ )
+ .await
+ .unwrap();
+ cx.executor().run_until_parked();
+
+ assert_eq!(
+ *requested_paths.lock().unwrap(),
+ vec!["/C:/project/src/lib.rs".to_string()]
+ );
+ }
+
+ // A remote workspace on a Unix host cannot hold a `C:` path, so this needs a Windows host.
+ #[cfg(target_os = "windows")]
+ #[gpui::test]
+ async fn test_drive_letter_url_path_reuses_open_remote_workspace(
+ cx: &mut TestAppContext,
+ server_cx: &mut TestAppContext,
+ ) {
+ let app_state = init_test(cx);
+ let (opts, _headless) = init_remote_server(cx, server_cx).await;
+ let mut async_cx = cx.to_async();
+
+ let window = open_remote_project(
+ opts.clone(),
+ vec![PathBuf::from(path!("/project"))],
+ app_state.clone(),
+ workspace::OpenOptions::default(),
+ &mut async_cx,
+ )
+ .await
+ .unwrap();
+ cx.executor().run_until_parked();
+
+ // As parsed from `ssh://host/C:/project/src/lib.rs`.
+ open_remote_project(
+ opts,
+ vec![PathBuf::from("/C:/project/src/lib.rs")],
+ app_state,
+ workspace::OpenOptions::default(),
+ &mut async_cx,
+ )
+ .await
+ .unwrap();
+ cx.executor().run_until_parked();
+
+ assert_eq!(
+ cx.update(|cx| cx.windows().len()),
+ 1,
+ "a drive-letter URL path into the open project should reuse its window"
+ );
+ let opened = window
+ .read_with(cx, |multi_workspace, cx| {
+ multi_workspace
+ .workspace()
+ .read(cx)
+ .active_item(cx)
+ .and_then(|item| item.project_path(cx))
+ .map(|project_path| project_path.path.as_unix_str().to_owned())
+ })
+ .unwrap();
+ assert_eq!(opened.as_deref(), Some("src/lib.rs"));
+ }
+
#[gpui::test]
async fn test_open_remote_project_with_mock_connection(
cx: &mut TestAppContext,
diff --git a/crates/remote/src/transport/mock.rs b/crates/remote/src/transport/mock.rs
index 798cd14e3d5..ccc2d9e2649 100644
--- a/crates/remote/src/transport/mock.rs
+++ b/crates/remote/src/transport/mock.rs
@@ -70,6 +70,8 @@ pub struct MockRemoteConnection {
server_channel: Arc,
server_cx: SendableCx,
message_interceptors: parking_lot::Mutex