Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Address issue with workspaces where single file worktrees such as those from git commit messages would get restored Co-authored-by: Mikayla <[email protected]>
Kay Simmons176738d674d1
diff --git a/crates/workspace/src/persistence.rs b/crates/workspace/src/persistence.rsindex cd425c3a286..03a866f2f6c 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<Option<WorkspaceLocation>> {- SELECT workspace_location- FROM workspaces- WHERE workspace_location IS NOT NULL- ORDER BY timestamp DESC- LIMIT 1- }+ pub async fn last_workspace(&self) -> Result<Option<WorkspaceLocation>> {+ Ok(self+ .recent_workspaces_on_disk()+ .await?+ .into_iter()+ .next()+ .map(|(_, location)| location))}fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 8bf4cbce328..ac6a9f38edd 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<WorkspaceLocation> {- DB.last_workspace().log_err().flatten()+pub async fn last_opened_workspace_paths() -> Option<WorkspaceLocation> {+ DB.last_workspace().await.log_err().flatten()}#[allow(clippy::type_complexity)]diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rsindex f4fa919c48e..3861c53e792 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);+ });}}