@@ -12,7 +12,10 @@ use client::{
use collections::{HashMap, HashSet};
use fs::FakeFs;
use futures::{channel::oneshot, StreamExt as _};
-use gpui::{executor::Deterministic, test::EmptyView, ModelHandle, TestAppContext, ViewHandle};
+use gpui::{
+ elements::*, executor::Deterministic, AnyElement, Entity, ModelHandle, TestAppContext, View,
+ ViewContext, ViewHandle, WeakViewHandle,
+};
use language::LanguageRegistry;
use parking_lot::Mutex;
use project::{Project, WorktreeId};
@@ -462,8 +465,41 @@ impl TestClient {
project: &ModelHandle<Project>,
cx: &mut TestAppContext,
) -> ViewHandle<Workspace> {
- let (window_id, _) = cx.add_window(|_| EmptyView);
- cx.add_view(window_id, |cx| Workspace::test_new(project.clone(), cx))
+ struct WorkspaceContainer {
+ workspace: Option<WeakViewHandle<Workspace>>,
+ }
+
+ impl Entity for WorkspaceContainer {
+ type Event = ();
+ }
+
+ impl View for WorkspaceContainer {
+ fn ui_name() -> &'static str {
+ "WorkspaceContainer"
+ }
+
+ fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
+ if let Some(workspace) = self
+ .workspace
+ .as_ref()
+ .and_then(|workspace| workspace.upgrade(cx))
+ {
+ ChildView::new(&workspace, cx).into_any()
+ } else {
+ Empty::new().into_any()
+ }
+ }
+ }
+
+ // We use a workspace container so that we don't need to remove the window in order to
+ // drop the workspace and we can use a ViewHandle instead.
+ let (window_id, container) = cx.add_window(|_| WorkspaceContainer { workspace: None });
+ let workspace = cx.add_view(window_id, |cx| Workspace::test_new(project.clone(), cx));
+ container.update(cx, |container, cx| {
+ container.workspace = Some(workspace.downgrade());
+ cx.notify();
+ });
+ workspace
}
}