From b625263989201a1eab65bf08dd73ffea121600af Mon Sep 17 00:00:00 2001 From: kallyaleksiev <67751757+kallyaleksiev@users.noreply.github.com> Date: Mon, 3 Nov 2025 11:13:20 +0000 Subject: [PATCH] remote: Close window when SSH connection fails (#41782) ## Context This PR closes issue https://github.com/zed-industries/zed/issues/41781 It essentially `matches` the result of opening the connection here https://github.com/zed-industries/zed/blob/f7153bbe8a869d0e2b25efed64fd7e4217899b63/crates/recent_projects/src/remote_connections.rs#L650 and adds a Close / Retry alert that upon 'Close' closes the new window if the result is an error --- .../recent_projects/src/remote_connections.rs | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/crates/recent_projects/src/remote_connections.rs b/crates/recent_projects/src/remote_connections.rs index c371b27ce1dcfe665d96f548bca2c893559005ec..7c8557f9dac2131a84c54cc60657e105d2839658 100644 --- a/crates/recent_projects/src/remote_connections.rs +++ b/crates/recent_projects/src/remote_connections.rs @@ -574,6 +574,7 @@ pub async fn open_remote_project( open_options: workspace::OpenOptions, cx: &mut AsyncApp, ) -> Result<()> { + let created_new_window = open_options.replace_window.is_none(); let window = if let Some(window) = open_options.replace_window { window } else { @@ -648,7 +649,45 @@ pub async fn open_remote_project( let Some(delegate) = delegate else { break }; let remote_connection = - remote::connect(connection_options.clone(), delegate.clone(), cx).await?; + match remote::connect(connection_options.clone(), delegate.clone(), cx).await { + Ok(connection) => connection, + Err(e) => { + window + .update(cx, |workspace, _, cx| { + if let Some(ui) = workspace.active_modal::(cx) { + ui.update(cx, |modal, cx| modal.finished(cx)) + } + }) + .ok(); + log::error!("Failed to open project: {e:?}"); + let response = window + .update(cx, |_, window, cx| { + window.prompt( + PromptLevel::Critical, + match connection_options { + RemoteConnectionOptions::Ssh(_) => "Failed to connect over SSH", + RemoteConnectionOptions::Wsl(_) => "Failed to connect to WSL", + }, + Some(&e.to_string()), + &["Retry", "Cancel"], + cx, + ) + })? + .await; + + if response == Ok(0) { + continue; + } + + if created_new_window { + window + .update(cx, |_, window, _| window.remove_window()) + .ok(); + } + break; + } + }; + let (paths, paths_with_positions) = determine_paths_with_positions(&remote_connection, paths.clone()).await; @@ -686,7 +725,7 @@ pub async fn open_remote_project( RemoteConnectionOptions::Wsl(_) => "Failed to connect to WSL", }, Some(&e.to_string()), - &["Retry", "Ok"], + &["Retry", "Cancel"], cx, ) })? @@ -694,7 +733,14 @@ pub async fn open_remote_project( if response == Ok(0) { continue; } + + if created_new_window { + window + .update(cx, |_, window, _| window.remove_window()) + .ok(); + } } + Ok(items) => { for (item, path) in items.into_iter().zip(paths_with_positions) { let Some(item) = item else {