Remove empty workspace placeholder; let the guard do its thing

Richard Feldman created

Change summary

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(-)

Detailed changes

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| {

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::<String>::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)"
     );
 }

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<Self>) {
+    #[cfg(any(test, feature = "test-support"))]
+    pub fn create_test_workspace(
+        &mut self,
+        window: &mut Window,
+        cx: &mut Context<Self>,
+    ) -> 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<Self>,
-    ) -> Task<()> {
-        self.create_empty_workspace(window, cx);
 
         let workspace = self.workspace().clone();
         let weak_workspace = workspace.downgrade();