From de0a191c2f7d8772c0a4c1e311355d433cc01860 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 31 Mar 2026 00:22:33 -0400 Subject: [PATCH] Remove empty workspace placeholder; let the guard do its thing --- crates/sidebar/src/sidebar.rs | 10 ---------- crates/sidebar/src/sidebar_tests.rs | 10 ++++++---- crates/workspace/src/multi_workspace.rs | 20 +++++++++----------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 50a14aec1643b43bbab6e772c7c54279e71fe516..4b3f696f3ca5cac8b7fded9693caaf8fe685d5f4 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -1709,16 +1709,6 @@ impl Sidebar { } } - if to_remove.is_empty() { - return; - } - - if to_remove.len() == workspaces.len() { - multi_workspace.update(cx, |multi_workspace, cx| { - multi_workspace.create_empty_workspace(window, cx); - }); - } - for workspace in &to_remove { if let Some(multi_workspace) = self.multi_workspace.upgrade() { multi_workspace.update(cx, |multi_workspace, cx| { diff --git a/crates/sidebar/src/sidebar_tests.rs b/crates/sidebar/src/sidebar_tests.rs index b81596fc72e445f6702b93a6c4396146abb6f296..af21ff25abfea7021113cbd4dcbf4ee3780bb5e0 100644 --- a/crates/sidebar/src/sidebar_tests.rs +++ b/crates/sidebar/src/sidebar_tests.rs @@ -5333,11 +5333,13 @@ async fn test_removing_workspace_also_removes_absorbed_worktrees(cx: &mut TestAp }); cx.run_until_parked(); - // The worktree workspaces should also have been removed. - // Before the fix, they remain in the sidebar as standalone entries. + // The absorbed worktree workspaces should be pruned. The last one + // survives because MultiWorkspace requires at least one workspace, + // but the first stale worktree is removed. + // Before the fix, both worktree workspaces remained in the sidebar. assert_eq!( visible_entries_as_strings(&sidebar, cx), - Vec::::new(), - "removing the main workspace should also remove the absorbed worktree workspaces" + vec!["v [project]", " Thread B {wt-feature-b}",], + "only the last stale worktree should remain (cannot remove the final workspace)" ); } diff --git a/crates/workspace/src/multi_workspace.rs b/crates/workspace/src/multi_workspace.rs index acc554fdd02ec08c39fc12b434f7b19d60e166b9..a863eecf112d561471b317a42566b555c4183080 100644 --- a/crates/workspace/src/multi_workspace.rs +++ b/crates/workspace/src/multi_workspace.rs @@ -5,7 +5,9 @@ use gpui::{ ManagedView, MouseButton, Pixels, Render, Subscription, Task, Tiling, Window, WindowId, actions, deferred, px, }; -use project::{DisableAiSettings, Project}; +use project::DisableAiSettings; +#[cfg(any(test, feature = "test-support"))] +use project::Project; use settings::Settings; pub use settings::SidebarSide; use std::future::Future; @@ -741,7 +743,12 @@ impl MultiWorkspace { workspace } - pub fn create_empty_workspace(&mut self, window: &mut Window, cx: &mut Context) { + #[cfg(any(test, feature = "test-support"))] + pub fn create_test_workspace( + &mut self, + window: &mut Window, + cx: &mut Context, + ) -> Task<()> { let app_state = self.workspace().read(cx).app_state().clone(); let project = Project::local( app_state.client.clone(), @@ -755,15 +762,6 @@ impl MultiWorkspace { ); let new_workspace = cx.new(|cx| Workspace::new(None, project, app_state, window, cx)); self.activate(new_workspace, window, cx); - } - - #[cfg(any(test, feature = "test-support"))] - pub fn create_test_workspace( - &mut self, - window: &mut Window, - cx: &mut Context, - ) -> Task<()> { - self.create_empty_workspace(window, cx); let workspace = self.workspace().clone(); let weak_workspace = workspace.downgrade();