diff --git a/crates/workspace/src/persistence.rs b/crates/workspace/src/persistence.rs index cd425c3a28..03a866f2f6 100644 --- a/crates/workspace/src/persistence.rs +++ b/crates/workspace/src/persistence.rs @@ -216,7 +216,9 @@ impl WorkspaceDb { let mut result = Vec::new(); let mut delete_tasks = Vec::new(); for (id, location) in self.recent_workspaces()? { - if location.paths().iter().all(|path| path.exists()) { + if location.paths().iter().all(|path| path.exists()) + && location.paths().iter().any(|path| path.is_dir()) + { result.push((id, location)); } else { delete_tasks.push(self.delete_stale_workspace(id)); @@ -227,14 +229,13 @@ impl WorkspaceDb { Ok(result) } - query! { - pub fn last_workspace() -> Result> { - SELECT workspace_location - FROM workspaces - WHERE workspace_location IS NOT NULL - ORDER BY timestamp DESC - LIMIT 1 - } + pub async fn last_workspace(&self) -> Result> { + Ok(self + .recent_workspaces_on_disk() + .await? + .into_iter() + .next() + .map(|(_, location)| location)) } fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 8bf4cbce32..ac6a9f38ed 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2680,8 +2680,8 @@ pub fn activate_workspace_for_project( None } -pub fn last_opened_workspace_paths() -> Option { - DB.last_workspace().log_err().flatten() +pub async fn last_opened_workspace_paths() -> Option { + DB.last_workspace().await.log_err().flatten() } #[allow(clippy::type_complexity)] diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index f4fa919c48..3861c53e79 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -170,7 +170,8 @@ fn main() { cx.platform().activate(true); let paths = collect_path_args(); if paths.is_empty() { - restore_or_create_workspace(cx); + cx.spawn(|cx| async move { restore_or_create_workspace(cx).await }) + .detach() } else { cx.dispatch_global_action(OpenPaths { paths }); } @@ -179,7 +180,8 @@ fn main() { cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx)) .detach(); } else { - restore_or_create_workspace(cx); + cx.spawn(|cx| async move { restore_or_create_workspace(cx).await }) + .detach() } cx.spawn(|cx| async move { while let Some(connection) = cli_connections_rx.next().await { @@ -203,13 +205,17 @@ fn main() { }); } -fn restore_or_create_workspace(cx: &mut gpui::MutableAppContext) { - if let Some(location) = workspace::last_opened_workspace_paths() { - cx.dispatch_global_action(OpenPaths { - paths: location.paths().as_ref().clone(), - }) +async fn restore_or_create_workspace(mut cx: AsyncAppContext) { + if let Some(location) = workspace::last_opened_workspace_paths().await { + cx.update(|cx| { + cx.dispatch_global_action(OpenPaths { + paths: location.paths().as_ref().clone(), + }) + }); } else { - cx.dispatch_global_action(NewFile); + cx.update(|cx| { + cx.dispatch_global_action(NewFile); + }); } }