Skip to content

Commit 46c5d51

Browse files
authored
recent_projects: Surface project opening errors to user (#41308)
Release Notes: - N/A *or* Added/Fixed/Improved ...
1 parent 73bd12e commit 46c5d51

File tree

3 files changed

+77
-75
lines changed

3 files changed

+77
-75
lines changed

crates/recent_projects/src/recent_projects.rs

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use ui::{KeyBinding, ListItem, ListItemSpacing, Tooltip, prelude::*, tooltip_con
2828
use util::{ResultExt, paths::PathExt};
2929
use workspace::{
3030
CloseIntent, HistoryManager, ModalView, OpenOptions, PathList, SerializedWorkspaceLocation,
31-
WORKSPACE_DB, Workspace, WorkspaceId, with_active_or_new_workspace,
31+
WORKSPACE_DB, Workspace, WorkspaceId, notifications::DetachAndPromptErr,
32+
with_active_or_new_workspace,
3233
};
3334
use zed_actions::{OpenRecent, OpenRemote};
3435

@@ -420,77 +421,79 @@ impl PickerDelegate for RecentProjectsDelegate {
420421
} else {
421422
!secondary
422423
};
423-
workspace
424-
.update(cx, |workspace, cx| {
425-
if workspace.database_id() == Some(*candidate_workspace_id) {
426-
Task::ready(Ok(()))
427-
} else {
428-
match candidate_workspace_location.clone() {
429-
SerializedWorkspaceLocation::Local => {
430-
let paths = candidate_workspace_paths.paths().to_vec();
431-
if replace_current_window {
432-
cx.spawn_in(window, async move |workspace, cx| {
433-
let continue_replacing = workspace
434-
.update_in(cx, |workspace, window, cx| {
435-
workspace.prepare_to_close(
436-
CloseIntent::ReplaceWindow,
437-
window,
438-
cx,
439-
)
440-
})?
441-
.await?;
442-
if continue_replacing {
424+
workspace.update(cx, |workspace, cx| {
425+
if workspace.database_id() == Some(*candidate_workspace_id) {
426+
return;
427+
}
428+
match candidate_workspace_location.clone() {
429+
SerializedWorkspaceLocation::Local => {
430+
let paths = candidate_workspace_paths.paths().to_vec();
431+
if replace_current_window {
432+
cx.spawn_in(window, async move |workspace, cx| {
433+
let continue_replacing = workspace
434+
.update_in(cx, |workspace, window, cx| {
435+
workspace.prepare_to_close(
436+
CloseIntent::ReplaceWindow,
437+
window,
438+
cx,
439+
)
440+
})?
441+
.await?;
442+
if continue_replacing {
443+
workspace
444+
.update_in(cx, |workspace, window, cx| {
443445
workspace
444-
.update_in(cx, |workspace, window, cx| {
445-
workspace.open_workspace_for_paths(
446-
true, paths, window, cx,
447-
)
448-
})?
449-
.await
450-
} else {
451-
Ok(())
452-
}
453-
})
446+
.open_workspace_for_paths(true, paths, window, cx)
447+
})?
448+
.await
454449
} else {
455-
workspace.open_workspace_for_paths(false, paths, window, cx)
450+
Ok(())
456451
}
457-
}
458-
SerializedWorkspaceLocation::Remote(mut connection) => {
459-
let app_state = workspace.app_state().clone();
460-
461-
let replace_window = if replace_current_window {
462-
window.window_handle().downcast::<Workspace>()
463-
} else {
464-
None
465-
};
466-
467-
let open_options = OpenOptions {
468-
replace_window,
469-
..Default::default()
470-
};
471-
472-
if let RemoteConnectionOptions::Ssh(connection) = &mut connection {
473-
SshSettings::get_global(cx)
474-
.fill_connection_options_from_settings(connection);
475-
};
476-
477-
let paths = candidate_workspace_paths.paths().to_vec();
478-
479-
cx.spawn_in(window, async move |_, cx| {
480-
open_remote_project(
481-
connection.clone(),
482-
paths,
483-
app_state,
484-
open_options,
485-
cx,
486-
)
487-
.await
488-
})
489-
}
452+
})
453+
} else {
454+
workspace.open_workspace_for_paths(false, paths, window, cx)
490455
}
491456
}
492-
})
493-
.detach_and_log_err(cx);
457+
SerializedWorkspaceLocation::Remote(mut connection) => {
458+
let app_state = workspace.app_state().clone();
459+
460+
let replace_window = if replace_current_window {
461+
window.window_handle().downcast::<Workspace>()
462+
} else {
463+
None
464+
};
465+
466+
let open_options = OpenOptions {
467+
replace_window,
468+
..Default::default()
469+
};
470+
471+
if let RemoteConnectionOptions::Ssh(connection) = &mut connection {
472+
SshSettings::get_global(cx)
473+
.fill_connection_options_from_settings(connection);
474+
};
475+
476+
let paths = candidate_workspace_paths.paths().to_vec();
477+
478+
cx.spawn_in(window, async move |_, cx| {
479+
open_remote_project(
480+
connection.clone(),
481+
paths,
482+
app_state,
483+
open_options,
484+
cx,
485+
)
486+
.await
487+
})
488+
}
489+
}
490+
.detach_and_prompt_err(
491+
"Failed to open project",
492+
window,
493+
cx,
494+
|_, _, _| None,
495+
);
496+
});
494497
cx.emit(DismissEvent);
495498
}
496499
}

crates/recent_projects/src/remote_connections.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ impl remote::RemoteClientDelegate for RemoteClientDelegate {
483483
cx: &mut AsyncApp,
484484
) -> Task<anyhow::Result<PathBuf>> {
485485
cx.spawn(async move |cx| {
486-
let binary_path = AutoUpdater::download_remote_server_release(
486+
AutoUpdater::download_remote_server_release(
487487
platform.os,
488488
platform.arch,
489489
release_channel,
@@ -500,8 +500,7 @@ impl remote::RemoteClientDelegate for RemoteClientDelegate {
500500
platform.os,
501501
platform.arch,
502502
)
503-
})?;
504-
Ok(binary_path)
503+
})
505504
})
506505
}
507506

crates/remote/src/remote_client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ impl RemoteClient {
528528
let reconnect_task = cx.spawn(async move |this, cx| {
529529
macro_rules! failed {
530530
($error:expr, $attempts:expr, $ssh_connection:expr, $delegate:expr) => {
531+
delegate.set_status(Some(&format!("{error:#}", error = $error)), cx);
531532
return State::ReconnectFailed {
532533
error: anyhow!($error),
533534
attempts: $attempts,
@@ -999,11 +1000,10 @@ impl ConnectionPool {
9991000
let connection = self.connections.get(&opts);
10001001
match connection {
10011002
Some(ConnectionPoolEntry::Connecting(task)) => {
1002-
let delegate = delegate.clone();
1003-
cx.spawn(async move |cx| {
1004-
delegate.set_status(Some("Waiting for existing connection attempt"), cx);
1005-
})
1006-
.detach();
1003+
delegate.set_status(
1004+
Some("Waiting for existing connection attempt"),
1005+
&mut cx.to_async(),
1006+
);
10071007
return task.clone();
10081008
}
10091009
Some(ConnectionPoolEntry::Connected(ssh)) => {

0 commit comments

Comments
 (0)