Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Get tests compiling returning WindowHandle<V: View> from add_window
Nathan Sobo884cee6dfda9
diff --git a/crates/collab/src/tests.rs b/crates/collab/src/tests.rsindex b1d0bedb2cf..4804f5b0f1f 100644--- a/crates/collab/src/tests.rs+++ b/crates/collab/src/tests.rs@@ -495,8 +495,9 @@ impl TestClient {// 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));+ let window = cx.add_window(|_| WorkspaceContainer { workspace: None });+ let container = window.root(cx);+ let workspace = window.add_view(cx, |cx| Workspace::test_new(project.clone(), cx));container.update(cx, |container, cx| {container.workspace = Some(workspace.downgrade());cx.notify();diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rsindex ab94f16a07f..1a8e6d938d6 100644--- a/crates/collab/src/tests/integration_tests.rs+++ b/crates/collab/src/tests/integration_tests.rs@@ -7,8 +7,7 @@ use client::{User, RECEIVE_TIMEOUT};use collections::HashSet;use editor::{test::editor_test_context::EditorTestContext, ConfirmCodeAction, ConfirmCompletion,- ConfirmRename, Editor, ExcerptRange, MultiBuffer, Redo, Rename, ToOffset, ToggleCodeActions,- Undo,+ ConfirmRename, Editor, ExcerptRange, MultiBuffer, Redo, Rename, ToggleCodeActions, Undo,};use fs::{repository::GitFileStatus, FakeFs, Fs as _, LineEnding, RemoveOptions};use futures::StreamExt as _;@@ -1208,7 +1207,7 @@ async fn test_share_project(cx_c: &mut TestAppContext,) {deterministic.forbid_parking();- let (window_b, _) = cx_b.add_window(|_| EmptyView);+ let window_b = cx_b.add_window(|_| EmptyView);let mut server = TestServer::start(&deterministic).await;let client_a = server.create_client(cx_a, "user_a").await;let client_b = server.create_client(cx_b, "user_b").await;@@ -1316,7 +1315,7 @@ async fn test_share_project(.await.unwrap();- let editor_b = cx_b.add_view(window_b, |cx| Editor::for_buffer(buffer_b, None, cx));+ let editor_b = window_b.add_view(cx_b, |cx| Editor::for_buffer(buffer_b, None, cx));// Client A sees client B's selectiondeterministic.run_until_parked();@@ -1499,8 +1498,8 @@ async fn test_host_disconnect(deterministic.run_until_parked();assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared()));- let (window_id_b, workspace_b) =- cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));+ let window_b = cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));+ let workspace_b = window_b.root(cx_b);let editor_b = workspace_b.update(cx_b, |workspace, cx| {workspace.open_path((worktree_id, "b.txt"), None, true, cx)@@ -1509,9 +1508,7 @@ async fn test_host_disconnect(.unwrap().downcast::<Editor>().unwrap();- assert!(cx_b- .read_window(window_id_b, |cx| editor_b.is_focused(cx))- .unwrap());+ assert!(window_b.read_with(cx_b, |cx| editor_b.is_focused(cx)));editor_b.update(cx_b, |editor, cx| editor.insert("X", cx));assert!(cx_b.is_window_edited(workspace_b.window_id()));@@ -1525,7 +1522,7 @@ async fn test_host_disconnect(assert!(worktree_a.read_with(cx_a, |tree, _| !tree.as_local().unwrap().is_shared()));// Ensure client B's edited state is reset and that the whole window is blurred.- cx_b.read_window(window_id_b, |cx| {+ window_b.read_with(cx_b, |cx| {assert_eq!(cx.focused_view_id(), None);});assert!(!cx_b.is_window_edited(workspace_b.window_id()));@@ -3445,13 +3442,11 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(.update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)).await.unwrap();- let (window_a, _) = cx_a.add_window(|_| EmptyView);- let editor_a = cx_a.add_view(window_a, |cx| {- Editor::for_buffer(buffer_a, Some(project_a), cx)- });+ let window_a = cx_a.add_window(|_| EmptyView);+ let editor_a = window_a.add_view(cx_a, |cx| Editor::for_buffer(buffer_a, Some(project_a), cx));let mut editor_cx_a = EditorTestContext {cx: cx_a,- window_id: window_a,+ window_id: window_a.id(),editor: editor_a,};@@ -3460,13 +3455,11 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(.update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)).await.unwrap();- let (window_b, _) = cx_b.add_window(|_| EmptyView);- let editor_b = cx_b.add_view(window_b, |cx| {- Editor::for_buffer(buffer_b, Some(project_b), cx)- });+ let window_b = cx_b.add_window(|_| EmptyView);+ let editor_b = window_b.add_view(cx_b, |cx| Editor::for_buffer(buffer_b, Some(project_b), cx));let mut editor_cx_b = EditorTestContext {cx: cx_b,- window_id: window_b,+ window_id: window_b.id(),editor: editor_b,};@@ -4205,8 +4198,8 @@ async fn test_collaborating_with_completion(.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx)).await.unwrap();- let (window_b, _) = cx_b.add_window(|_| EmptyView);- let editor_b = cx_b.add_view(window_b, |cx| {+ let window_b = cx_b.add_window(|_| EmptyView);+ let editor_b = window_b.add_view(cx_b, |cx| {Editor::for_buffer(buffer_b.clone(), Some(project_b.clone()), cx)});@@ -5316,7 +5309,8 @@ async fn test_collaborating_with_code_actions(// Join the project as client B.let project_b = client_b.build_remote_project(project_id, cx_b).await;- let (_window_b, workspace_b) = cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));+ let window_b = cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));+ let workspace_b = window_b.root(cx_b);let editor_b = workspace_b.update(cx_b, |workspace, cx| {workspace.open_path((worktree_id, "main.rs"), None, true, cx)@@ -5540,7 +5534,8 @@ async fn test_collaborating_with_renames(.unwrap();let project_b = client_b.build_remote_project(project_id, cx_b).await;- let (_window_b, workspace_b) = cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));+ let window_b = cx_b.add_window(|cx| Workspace::test_new(project_b.clone(), cx));+ let workspace_b = window_b.root(cx_b);let editor_b = workspace_b.update(cx_b, |workspace, cx| {workspace.open_path((worktree_id, "one.rs"), None, true, cx)@@ -5571,6 +5566,7 @@ async fn test_collaborating_with_renames(.unwrap();prepare_rename.await.unwrap();editor_b.update(cx_b, |editor, cx| {+ use editor::ToOffset;let rename = editor.pending_rename().unwrap();let buffer = editor.buffer().read(cx).snapshot(cx);assert_eq!(@@ -7601,8 +7597,8 @@ async fn test_on_input_format_from_host_to_guest(.update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx)).await.unwrap();- let (window_a, _) = cx_a.add_window(|_| EmptyView);- let editor_a = cx_a.add_view(window_a, |cx| {+ let window_a = cx_a.add_window(|_| EmptyView);+ let editor_a = window_a.add_view(cx_a, |cx| {Editor::for_buffer(buffer_a, Some(project_a.clone()), cx)});@@ -7730,8 +7726,8 @@ async fn test_on_input_format_from_guest_to_host(.update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx)).await.unwrap();- let (window_b, _) = cx_b.add_window(|_| EmptyView);- let editor_b = cx_b.add_view(window_b, |cx| {+ let window_b = cx_b.add_window(|_| EmptyView);+ let editor_b = window_b.add_view(cx_b, |cx| {Editor::for_buffer(buffer_b, Some(project_b.clone()), cx)});diff --git a/crates/collab_ui/src/incoming_call_notification.rs b/crates/collab_ui/src/incoming_call_notification.rsindex 4066b5b229a..a9c5e697a5f 100644--- a/crates/collab_ui/src/incoming_call_notification.rs+++ b/crates/collab_ui/src/incoming_call_notification.rs@@ -31,7 +31,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {for screen in cx.platform().screens() {let screen_bounds = screen.bounds();- let (window_id, _) = cx.add_window(+ let window = cx.add_window(WindowOptions {bounds: WindowBounds::Fixed(RectF::new(screen_bounds.upper_right()@@ -49,7 +49,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {|_| IncomingCallNotification::new(incoming_call.clone(), app_state.clone()),);- notification_windows.push(window_id);+ notification_windows.push(window.id());}}}diff --git a/crates/collab_ui/src/project_shared_notification.rs b/crates/collab_ui/src/project_shared_notification.rsindex fea6118bdf4..03ab91623b4 100644--- a/crates/collab_ui/src/project_shared_notification.rs+++ b/crates/collab_ui/src/project_shared_notification.rs@@ -26,7 +26,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {for screen in cx.platform().screens() {let screen_bounds = screen.bounds();- let (window_id, _) = cx.add_window(+ let window = cx.add_window(WindowOptions {bounds: WindowBounds::Fixed(RectF::new(screen_bounds.upper_right() - vec2f(PADDING + window_size.x(), PADDING),@@ -52,7 +52,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {notification_windows.entry(*project_id).or_insert(Vec::new())- .push(window_id);+ .push(window.id());}}room::Event::RemoteProjectUnshared { project_id } => {diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex 7461fb28c73..7d4b4126b70 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -295,7 +295,9 @@ mod tests {let app_state = init_test(cx);let project = Project::test(app_state.fs.clone(), [], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();let editor = cx.add_view(window_id, |cx| {let mut editor = Editor::single_line(None, cx);editor.set_text("abc", cx);diff --git a/crates/copilot/src/sign_in.rs b/crates/copilot/src/sign_in.rsindex fec8f27c973..659bee7445f 100644--- a/crates/copilot/src/sign_in.rs+++ b/crates/copilot/src/sign_in.rs@@ -27,7 +27,7 @@ pub fn init(cx: &mut AppContext) {if let Some(code_verification_handle) = code_verification.as_mut() {let window_id = code_verification_handle.id();let updated = cx.update_window(window_id, |cx| {- code_verification_handle.update(cx, |code_verification, cx| {+ code_verification_handle.update_root(cx, |code_verification, cx| {code_verification.set_status(status.clone(), cx)});cx.activate_window();@@ -41,9 +41,9 @@ pub fn init(cx: &mut AppContext) {}Status::Authorized | Status::Unauthorized => {if let Some(code_verification) = code_verification.as_ref() {- let window_id = code_verification.window_id();+ let window_id = code_verification.id();cx.update_window(window_id, |cx| {- code_verification.update(cx, |code_verification, cx| {+ code_verification.update_root(cx, |code_verification, cx| {code_verification.set_status(status, cx)});@@ -54,7 +54,7 @@ pub fn init(cx: &mut AppContext) {}_ => {if let Some(code_verification) = code_verification.take() {- cx.update_window(code_verification.window_id(), |cx| cx.remove_window());+ code_verification.update(cx, |cx| cx.remove_window());}}}diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rsindex d0cd437946a..2444465be66 100644--- a/crates/diagnostics/src/diagnostics.rs+++ b/crates/diagnostics/src/diagnostics.rs@@ -855,7 +855,9 @@ mod tests {let language_server_id = LanguageServerId(0);let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();// Create some diagnosticsproject.update(cx, |project, cx| {@@ -1248,7 +1250,9 @@ mod tests {let server_id_1 = LanguageServerId(100);let server_id_2 = LanguageServerId(101);let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();let view = cx.add_view(window_id, |cx| {ProjectDiagnosticsEditor::new(project.clone(), workspace.downgrade(), cx)diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex eb03d2bdc0f..96921643d45 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -48,36 +48,40 @@ fn test_edit_events(cx: &mut TestAppContext) {});let events = Rc::new(RefCell::new(Vec::new()));- let (_, editor1) = cx.add_window({- let events = events.clone();- |cx| {- cx.subscribe(&cx.handle(), move |_, _, event, _| {- if matches!(- event,- Event::Edited | Event::BufferEdited | Event::DirtyChanged- ) {- events.borrow_mut().push(("editor1", event.clone()));- }- })- .detach();- Editor::for_buffer(buffer.clone(), None, cx)- }- });- let (_, editor2) = cx.add_window({- let events = events.clone();- |cx| {- cx.subscribe(&cx.handle(), move |_, _, event, _| {- if matches!(- event,- Event::Edited | Event::BufferEdited | Event::DirtyChanged- ) {- events.borrow_mut().push(("editor2", event.clone()));- }- })- .detach();- Editor::for_buffer(buffer.clone(), None, cx)- }- });+ let editor1 = cx+ .add_window({+ let events = events.clone();+ |cx| {+ cx.subscribe(&cx.handle(), move |_, _, event, _| {+ if matches!(+ event,+ Event::Edited | Event::BufferEdited | Event::DirtyChanged+ ) {+ events.borrow_mut().push(("editor1", event.clone()));+ }+ })+ .detach();+ Editor::for_buffer(buffer.clone(), None, cx)+ }+ })+ .detach(cx);+ let editor2 = cx+ .add_window({+ let events = events.clone();+ |cx| {+ cx.subscribe(&cx.handle(), move |_, _, event, _| {+ if matches!(+ event,+ Event::Edited | Event::BufferEdited | Event::DirtyChanged+ ) {+ events.borrow_mut().push(("editor2", event.clone()));+ }+ })+ .detach();+ Editor::for_buffer(buffer.clone(), None, cx)+ }+ })+ .detach(cx);assert_eq!(mem::take(&mut *events.borrow_mut()), []);// Mutating editor 1 will emit an `Edited` event only for that editor.@@ -173,7 +177,9 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) {let buffer = cx.add_model(|cx| language::Buffer::new(0, "123456", cx));let group_interval = buffer.read_with(cx, |buffer, _| buffer.transaction_group_interval());let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, editor) = cx.add_window(|cx| build_editor(buffer.clone(), cx));+ let editor = cx+ .add_window(|cx| build_editor(buffer.clone(), cx))+ .detach(cx);editor.update(cx, |editor, cx| {editor.start_transaction_at(now, cx);@@ -343,10 +349,12 @@ fn test_ime_composition(cx: &mut TestAppContext) {fn test_selection_with_mouse(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\nddddddd\n", cx);- build_editor(buffer, cx)- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\nddddddd\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);editor.update(cx, |view, cx| {view.begin_selection(DisplayPoint::new(2, 2), false, 1, cx);});@@ -410,10 +418,12 @@ fn test_selection_with_mouse(cx: &mut TestAppContext) {fn test_canceling_pending_selection(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.begin_selection(DisplayPoint::new(2, 2), false, 1, cx);@@ -456,10 +466,12 @@ fn test_clone(cx: &mut TestAppContext) {true,);- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&text, cx);- build_editor(buffer, cx)- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&text, cx);+ build_editor(buffer, cx)+ })+ .detach(cx);editor.update(cx, |editor, cx| {editor.change_selections(None, cx, |s| s.select_ranges(selection_ranges.clone()));@@ -473,9 +485,11 @@ fn test_clone(cx: &mut TestAppContext) {);});- let (_, cloned_editor) = editor.update(cx, |editor, cx| {- cx.add_window(Default::default(), |cx| editor.clone(cx))- });+ let cloned_editor = editor+ .update(cx, |editor, cx| {+ cx.add_window(Default::default(), |cx| editor.clone(cx))+ })+ .detach(cx);let snapshot = editor.update(cx, |e, cx| e.snapshot(cx));let cloned_snapshot = cloned_editor.update(cx, |e, cx| e.snapshot(cx));@@ -509,7 +523,9 @@ async fn test_navigation_history(cx: &mut TestAppContext) {let fs = FakeFs::new(cx.background());let project = Project::test(fs, [], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());cx.add_view(window_id, |cx| {let buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx);@@ -618,10 +634,12 @@ async fn test_navigation_history(cx: &mut TestAppContext) {fn test_cancel(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("aaaaaa\nbbbbbb\ncccccc\ndddddd\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.begin_selection(DisplayPoint::new(3, 4), false, 1, cx);@@ -661,9 +679,10 @@ fn test_cancel(cx: &mut TestAppContext) {fn test_fold_action(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(- &"+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(+ &"impl Foo {// Hello!@@ -680,11 +699,12 @@ fn test_fold_action(cx: &mut TestAppContext) {}}"- .unindent(),- cx,- );- build_editor(buffer.clone(), cx)- });+ .unindent(),+ cx,+ );+ build_editor(buffer.clone(), cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {@@ -752,7 +772,9 @@ fn test_move_cursor(cx: &mut TestAppContext) {init_test(cx, |_| {});let buffer = cx.update(|cx| MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx));- let (_, view) = cx.add_window(|cx| build_editor(buffer.clone(), cx));+ let view = cx+ .add_window(|cx| build_editor(buffer.clone(), cx))+ .detach(cx);buffer.update(cx, |buffer, cx| {buffer.edit(@@ -827,10 +849,12 @@ fn test_move_cursor(cx: &mut TestAppContext) {fn test_move_cursor_multibyte(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("ⓐⓑⓒⓓⓔ\nabcde\nαβγδε\n", cx);- build_editor(buffer.clone(), cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("ⓐⓑⓒⓓⓔ\nabcde\nαβγδε\n", cx);+ build_editor(buffer.clone(), cx)+ })+ .detach(cx);assert_eq!('ⓐ'.len_utf8(), 3);assert_eq!('α'.len_utf8(), 2);@@ -932,10 +956,12 @@ fn test_move_cursor_multibyte(cx: &mut TestAppContext) {fn test_move_cursor_different_line_lengths(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("ⓐⓑⓒⓓⓔ\nabcd\nαβγ\nabcd\nⓐⓑⓒⓓⓔ\n", cx);- build_editor(buffer.clone(), cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("ⓐⓑⓒⓓⓔ\nabcd\nαβγ\nabcd\nⓐⓑⓒⓓⓔ\n", cx);+ build_editor(buffer.clone(), cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([empty_range(0, "ⓐⓑⓒⓓⓔ".len())]);@@ -982,10 +1008,12 @@ fn test_move_cursor_different_line_lengths(cx: &mut TestAppContext) {fn test_beginning_end_of_line(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("abc\n def", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("abc\n def", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([@@ -1145,10 +1173,12 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) {fn test_prev_next_word_boundary(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("use std::str::{foo, bar}\n\n {baz.qux()}", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("use std::str::{foo, bar}\n\n {baz.qux()}", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([@@ -1197,10 +1227,13 @@ fn test_prev_next_word_boundary(cx: &mut TestAppContext) {fn test_prev_next_word_bounds_with_soft_wrap(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("use one::{\n two::three::four::five\n};", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer =+ MultiBuffer::build_simple("use one::{\n two::three::four::five\n};", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.set_wrap_width(Some(140.), cx);@@ -1530,10 +1563,12 @@ async fn test_delete_to_beginning_of_line(cx: &mut gpui::TestAppContext) {fn test_delete_to_word_boundary(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("one two three four", cx);- build_editor(buffer.clone(), cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("one two three four", cx);+ build_editor(buffer.clone(), cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {@@ -1566,10 +1601,12 @@ fn test_delete_to_word_boundary(cx: &mut TestAppContext) {fn test_newline(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("aaaa\n bbbb\n", cx);- build_editor(buffer.clone(), cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("aaaa\n bbbb\n", cx);+ build_editor(buffer.clone(), cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {@@ -1589,9 +1626,10 @@ fn test_newline(cx: &mut TestAppContext) {fn test_newline_with_old_selections(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(- "+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(+ "ab(X@@ -1600,19 +1638,20 @@ fn test_newline_with_old_selections(cx: &mut TestAppContext) {X)"- .unindent()- .as_str(),- cx,- );- let mut editor = build_editor(buffer.clone(), cx);- editor.change_selections(None, cx, |s| {- s.select_ranges([- Point::new(2, 4)..Point::new(2, 5),- Point::new(5, 4)..Point::new(5, 5),- ])- });- editor- });+ .unindent()+ .as_str(),+ cx,+ );+ let mut editor = build_editor(buffer.clone(), cx);+ editor.change_selections(None, cx, |s| {+ s.select_ranges([+ Point::new(2, 4)..Point::new(2, 5),+ Point::new(5, 4)..Point::new(5, 5),+ ])+ });+ editor+ })+ .detach(cx);editor.update(cx, |editor, cx| {// Edit the buffer directly, deleting ranges surrounding the editor's selections@@ -1817,12 +1856,14 @@ async fn test_newline_comments(cx: &mut gpui::TestAppContext) {fn test_insert_with_old_selections(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("a( X ), b( Y ), c( Z )", cx);- let mut editor = build_editor(buffer.clone(), cx);- editor.change_selections(None, cx, |s| s.select_ranges([3..4, 11..12, 19..20]));- editor- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("a( X ), b( Y ), c( Z )", cx);+ let mut editor = build_editor(buffer.clone(), cx);+ editor.change_selections(None, cx, |s| s.select_ranges([3..4, 11..12, 19..20]));+ editor+ })+ .detach(cx);editor.update(cx, |editor, cx| {// Edit the buffer directly, deleting ranges surrounding the editor's selections@@ -2329,10 +2370,12 @@ async fn test_delete(cx: &mut gpui::TestAppContext) {fn test_delete_line(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([@@ -2352,10 +2395,12 @@ fn test_delete_line(cx: &mut TestAppContext) {);});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([DisplayPoint::new(2, 0)..DisplayPoint::new(0, 1)])@@ -2654,10 +2699,12 @@ async fn test_manipulate_lines_with_multi_selection(cx: &mut TestAppContext) {fn test_duplicate_line(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([@@ -2680,10 +2727,12 @@ fn test_duplicate_line(cx: &mut TestAppContext) {);});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([@@ -2707,10 +2756,12 @@ fn test_duplicate_line(cx: &mut TestAppContext) {fn test_move_line_up_down(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.fold_ranges(vec![@@ -2806,10 +2857,12 @@ fn test_move_line_up_down(cx: &mut TestAppContext) {fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx);- build_editor(buffer, cx)- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx);+ build_editor(buffer, cx)+ })+ .detach(cx);editor.update(cx, |editor, cx| {let snapshot = editor.buffer.read(cx).snapshot(cx);editor.insert_blocks(@@ -2834,102 +2887,94 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) {fn test_transpose(cx: &mut TestAppContext) {init_test(cx, |_| {});- _ = cx- .add_window(|cx| {- let mut editor = build_editor(MultiBuffer::build_simple("abc", cx), cx);+ _ = cx.add_window(|cx| {+ let mut editor = build_editor(MultiBuffer::build_simple("abc", cx), cx);- editor.change_selections(None, cx, |s| s.select_ranges([1..1]));- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bac");- assert_eq!(editor.selections.ranges(cx), [2..2]);+ editor.change_selections(None, cx, |s| s.select_ranges([1..1]));+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bac");+ assert_eq!(editor.selections.ranges(cx), [2..2]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bca");- assert_eq!(editor.selections.ranges(cx), [3..3]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bca");+ assert_eq!(editor.selections.ranges(cx), [3..3]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bac");- assert_eq!(editor.selections.ranges(cx), [3..3]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bac");+ assert_eq!(editor.selections.ranges(cx), [3..3]);- editor- })- .1;+ editor+ });- _ = cx- .add_window(|cx| {- let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);+ _ = cx.add_window(|cx| {+ let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);- editor.change_selections(None, cx, |s| s.select_ranges([3..3]));- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "acb\nde");- assert_eq!(editor.selections.ranges(cx), [3..3]);+ editor.change_selections(None, cx, |s| s.select_ranges([3..3]));+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "acb\nde");+ assert_eq!(editor.selections.ranges(cx), [3..3]);- editor.change_selections(None, cx, |s| s.select_ranges([4..4]));- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "acbd\ne");- assert_eq!(editor.selections.ranges(cx), [5..5]);+ editor.change_selections(None, cx, |s| s.select_ranges([4..4]));+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "acbd\ne");+ assert_eq!(editor.selections.ranges(cx), [5..5]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "acbde\n");- assert_eq!(editor.selections.ranges(cx), [6..6]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "acbde\n");+ assert_eq!(editor.selections.ranges(cx), [6..6]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "acbd\ne");- assert_eq!(editor.selections.ranges(cx), [6..6]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "acbd\ne");+ assert_eq!(editor.selections.ranges(cx), [6..6]);- editor- })- .1;+ editor+ });- _ = cx- .add_window(|cx| {- let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);+ _ = cx.add_window(|cx| {+ let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), cx);- editor.change_selections(None, cx, |s| s.select_ranges([1..1, 2..2, 4..4]));- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bacd\ne");- assert_eq!(editor.selections.ranges(cx), [2..2, 3..3, 5..5]);+ editor.change_selections(None, cx, |s| s.select_ranges([1..1, 2..2, 4..4]));+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bacd\ne");+ assert_eq!(editor.selections.ranges(cx), [2..2, 3..3, 5..5]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bcade\n");- assert_eq!(editor.selections.ranges(cx), [3..3, 4..4, 6..6]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bcade\n");+ assert_eq!(editor.selections.ranges(cx), [3..3, 4..4, 6..6]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bcda\ne");- assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bcda\ne");+ assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bcade\n");- assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bcade\n");+ assert_eq!(editor.selections.ranges(cx), [4..4, 6..6]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "bcaed\n");- assert_eq!(editor.selections.ranges(cx), [5..5, 6..6]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "bcaed\n");+ assert_eq!(editor.selections.ranges(cx), [5..5, 6..6]);- editor- })- .1;+ editor+ });- _ = cx- .add_window(|cx| {- let mut editor = build_editor(MultiBuffer::build_simple("🍐🏀✋", cx), cx);+ _ = cx.add_window(|cx| {+ let mut editor = build_editor(MultiBuffer::build_simple("🍐🏀✋", cx), cx);- editor.change_selections(None, cx, |s| s.select_ranges([4..4]));- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "🏀🍐✋");- assert_eq!(editor.selections.ranges(cx), [8..8]);+ editor.change_selections(None, cx, |s| s.select_ranges([4..4]));+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "🏀🍐✋");+ assert_eq!(editor.selections.ranges(cx), [8..8]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "🏀✋🍐");- assert_eq!(editor.selections.ranges(cx), [11..11]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "🏀✋🍐");+ assert_eq!(editor.selections.ranges(cx), [11..11]);- editor.transpose(&Default::default(), cx);- assert_eq!(editor.text(cx), "🏀🍐✋");- assert_eq!(editor.selections.ranges(cx), [11..11]);+ editor.transpose(&Default::default(), cx);+ assert_eq!(editor.text(cx), "🏀🍐✋");+ assert_eq!(editor.selections.ranges(cx), [11..11]);- editor- })- .1;+ editor+ });}#[gpui::test]@@ -3132,10 +3177,12 @@ async fn test_paste_multiline(cx: &mut gpui::TestAppContext) {fn test_select_all(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("abc\nde\nfgh", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("abc\nde\nfgh", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.select_all(&SelectAll, cx);assert_eq!(@@ -3149,10 +3196,12 @@ fn test_select_all(cx: &mut TestAppContext) {fn test_select_line(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&sample_text(6, 5, 'a'), cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&sample_text(6, 5, 'a'), cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {s.select_display_ranges([@@ -3196,10 +3245,12 @@ fn test_select_line(cx: &mut TestAppContext) {fn test_split_selection_into_lines(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&sample_text(9, 5, 'a'), cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&sample_text(9, 5, 'a'), cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.fold_ranges(vec![@@ -3267,10 +3318,12 @@ fn test_split_selection_into_lines(cx: &mut TestAppContext) {fn test_add_selection_above_below(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, view) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("abc\ndefghi\n\njk\nlmno\n", cx);- build_editor(buffer, cx)- });+ let view = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("abc\ndefghi\n\njk\nlmno\n", cx);+ build_editor(buffer, cx)+ })+ .detach(cx);view.update(cx, |view, cx| {view.change_selections(None, cx, |s| {@@ -3555,7 +3608,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));+ let view = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);view.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)).await;@@ -3718,7 +3771,7 @@ async fn test_autoindent_selections(cx: &mut gpui::TestAppContext) {let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));+ let editor = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);editor.condition(cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx)).await;@@ -4281,7 +4334,7 @@ async fn test_surround_with_pair(cx: &mut gpui::TestAppContext) {let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));+ let view = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);view.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)).await;@@ -4429,7 +4482,7 @@ async fn test_delete_autoclose_pair(cx: &mut gpui::TestAppContext) {let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));+ let editor = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);editor.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)).await;@@ -4519,7 +4572,7 @@ async fn test_snippets(cx: &mut gpui::TestAppContext) {);let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx));- let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));+ let editor = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);editor.update(cx, |editor, cx| {let snippet = Snippet::parse("f(${1:one}, ${2:two}, ${1:three})$0").unwrap();@@ -4649,7 +4702,7 @@ async fn test_document_format_during_save(cx: &mut gpui::TestAppContext) {let fake_server = fake_servers.next().await.unwrap();let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));+ let editor = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));assert!(cx.read(|cx| editor.is_dirty(cx)));@@ -4761,7 +4814,7 @@ async fn test_range_format_during_save(cx: &mut gpui::TestAppContext) {let fake_server = fake_servers.next().await.unwrap();let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));+ let editor = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));assert!(cx.read(|cx| editor.is_dirty(cx)));@@ -4875,7 +4928,7 @@ async fn test_document_format_manual_trigger(cx: &mut gpui::TestAppContext) {let fake_server = fake_servers.next().await.unwrap();let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx));+ let editor = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));let format = editor.update(cx, |editor, cx| {@@ -5653,7 +5706,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {multibuffer});- let (_, view) = cx.add_window(|cx| build_editor(multibuffer, cx));+ let view = cx.add_window(|cx| build_editor(multibuffer, cx)).detach(cx);view.update(cx, |view, cx| {assert_eq!(view.text(cx), "aaaa\nbbbb");view.change_selections(None, cx, |s| {@@ -5723,7 +5776,7 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) {multibuffer});- let (_, view) = cx.add_window(|cx| build_editor(multibuffer, cx));+ let view = cx.add_window(|cx| build_editor(multibuffer, cx)).detach(cx);view.update(cx, |view, cx| {let (expected_text, selection_ranges) = marked_text_ranges(indoc! {"@@ -5799,22 +5852,24 @@ fn test_refresh_selections(cx: &mut TestAppContext) {multibuffer});- let (_, editor) = cx.add_window(|cx| {- let mut editor = build_editor(multibuffer.clone(), cx);- let snapshot = editor.snapshot(cx);- editor.change_selections(None, cx, |s| {- s.select_ranges([Point::new(1, 3)..Point::new(1, 3)])- });- editor.begin_selection(Point::new(2, 1).to_display_point(&snapshot), true, 1, cx);- assert_eq!(- editor.selections.ranges(cx),- [- Point::new(1, 3)..Point::new(1, 3),- Point::new(2, 1)..Point::new(2, 1),- ]- );- editor- });+ let editor = cx+ .add_window(|cx| {+ let mut editor = build_editor(multibuffer.clone(), cx);+ let snapshot = editor.snapshot(cx);+ editor.change_selections(None, cx, |s| {+ s.select_ranges([Point::new(1, 3)..Point::new(1, 3)])+ });+ editor.begin_selection(Point::new(2, 1).to_display_point(&snapshot), true, 1, cx);+ assert_eq!(+ editor.selections.ranges(cx),+ [+ Point::new(1, 3)..Point::new(1, 3),+ Point::new(2, 1)..Point::new(2, 1),+ ]+ );+ editor+ })+ .detach(cx);// Refreshing selections is a no-op when excerpts haven't changed.editor.update(cx, |editor, cx| {@@ -5884,16 +5939,18 @@ fn test_refresh_selections_while_selecting_with_mouse(cx: &mut TestAppContext) {multibuffer});- let (_, editor) = cx.add_window(|cx| {- let mut editor = build_editor(multibuffer.clone(), cx);- let snapshot = editor.snapshot(cx);- editor.begin_selection(Point::new(1, 3).to_display_point(&snapshot), false, 1, cx);- assert_eq!(- editor.selections.ranges(cx),- [Point::new(1, 3)..Point::new(1, 3)]- );- editor- });+ let editor = cx+ .add_window(|cx| {+ let mut editor = build_editor(multibuffer.clone(), cx);+ let snapshot = editor.snapshot(cx);+ editor.begin_selection(Point::new(1, 3).to_display_point(&snapshot), false, 1, cx);+ assert_eq!(+ editor.selections.ranges(cx),+ [Point::new(1, 3)..Point::new(1, 3)]+ );+ editor+ })+ .detach(cx);multibuffer.update(cx, |multibuffer, cx| {multibuffer.remove_excerpts([excerpt1_id.unwrap()], cx);@@ -5956,7 +6013,7 @@ async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) {let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));- let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));+ let view = cx.add_window(|cx| build_editor(buffer, cx)).detach(cx);view.condition(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)).await;@@ -5992,10 +6049,12 @@ async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) {fn test_highlighted_ranges(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&sample_text(16, 8, 'a'), cx);- build_editor(buffer.clone(), cx)- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&sample_text(16, 8, 'a'), cx);+ build_editor(buffer.clone(), cx)+ })+ .detach(cx);editor.update(cx, |editor, cx| {struct Type1;@@ -6084,16 +6143,20 @@ async fn test_following(cx: &mut gpui::TestAppContext) {.unwrap();cx.add_model(|cx| MultiBuffer::singleton(buffer, cx))});- let (_, leader) = cx.add_window(|cx| build_editor(buffer.clone(), cx));- let (_, follower) = cx.update(|cx| {- cx.add_window(- WindowOptions {- bounds: WindowBounds::Fixed(RectF::from_points(vec2f(0., 0.), vec2f(10., 80.))),- ..Default::default()- },- |cx| build_editor(buffer.clone(), cx),- )- });+ let leader = cx+ .add_window(|cx| build_editor(buffer.clone(), cx))+ .detach(cx);+ let follower = cx+ .update(|cx| {+ cx.add_window(+ WindowOptions {+ bounds: WindowBounds::Fixed(RectF::from_points(vec2f(0., 0.), vec2f(10., 80.))),+ ..Default::default()+ },+ |cx| build_editor(buffer.clone(), cx),+ )+ })+ .detach(cx);let is_still_following = Rc::new(RefCell::new(true));let follower_edit_event_count = Rc::new(RefCell::new(0));@@ -6224,7 +6287,9 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {let fs = FakeFs::new(cx.background());let project = Project::test(fs, ["/file.rs".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());let leader = pane.update(cx, |_, cx| {@@ -6968,7 +7033,7 @@ async fn test_copilot_multibuffer();multibuffer});- let (_, editor) = cx.add_window(|cx| build_editor(multibuffer, cx));+ let editor = cx.add_window(|cx| build_editor(multibuffer, cx)).detach(cx);handle_copilot_completion_request(&copilot_lsp,@@ -7098,7 +7163,7 @@ async fn test_copilot_disabled_globs();multibuffer});- let (_, editor) = cx.add_window(|cx| build_editor(multibuffer, cx));+ let editor = cx.add_window(|cx| build_editor(multibuffer, cx)).detach(cx);let mut copilot_requests = copilot_lsp.handle_request::<copilot::request::GetCompletions, _, _>(move |_params, _cx| async move {@@ -7177,7 +7242,9 @@ async fn test_on_type_formatting_not_triggered(cx: &mut gpui::TestAppContext) {.await;let project = Project::test(fs, ["/a".as_ref()], cx).await;project.update(cx, |project, _| project.languages().add(Arc::new(language)));- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let worktree_id = workspace.update(cx, |workspace, cx| {workspace.project().read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()@@ -7282,7 +7349,7 @@ async fn test_language_server_restart_due_to_settings_change(cx: &mut gpui::Test.await;let project = Project::test(fs, ["/a".as_ref()], cx).await;project.update(cx, |project, _| project.languages().add(Arc::new(language)));- let (_, _workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let _window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));let _buffer = project.update(cx, |project, cx| {project.open_local_buffer("/a/main.rs", cx)diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 750beaea138..dc40e7fb856 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -3002,10 +3002,12 @@ mod tests {fn test_layout_line_numbers(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);- Editor::new(EditorMode::Full, buffer, None, None, cx)- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);+ Editor::new(EditorMode::Full, buffer, None, None, cx)+ })+ .detach(cx);let element = EditorElement::new(editor.read_with(cx, |editor, cx| editor.style(cx)));let layouts = editor.update(cx, |editor, cx| {@@ -3021,10 +3023,12 @@ mod tests {fn test_layout_with_placeholder_text_and_blocks(cx: &mut TestAppContext) {init_test(cx, |_| {});- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple("", cx);- Editor::new(EditorMode::Full, buffer, None, None, cx)- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple("", cx);+ Editor::new(EditorMode::Full, buffer, None, None, cx)+ })+ .detach(cx);editor.update(cx, |editor, cx| {editor.set_placeholder_text("hello", cx);@@ -3231,10 +3235,12 @@ mod tests {info!("Creating editor with mode {editor_mode:?}, width {editor_width} and text '{input_text}'");- let (_, editor) = cx.add_window(|cx| {- let buffer = MultiBuffer::build_simple(&input_text, cx);- Editor::new(editor_mode, buffer, None, None, cx)- });+ let editor = cx+ .add_window(|cx| {+ let buffer = MultiBuffer::build_simple(&input_text, cx);+ Editor::new(editor_mode, buffer, None, None, cx)+ })+ .detach(cx);let mut element = EditorElement::new(editor.read_with(cx, |editor, cx| editor.style(cx)));let (_, layout_state) = editor.update(cx, |editor, cx| {diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rsindex 63076ba234d..089cbb29958 100644--- a/crates/editor/src/inlay_hint_cache.rs+++ b/crates/editor/src/inlay_hint_cache.rs@@ -1136,7 +1136,9 @@ mod tests {).await;let project = Project::test(fs, ["/a".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let worktree_id = workspace.update(cx, |workspace, cx| {workspace.project().read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()@@ -1836,7 +1838,9 @@ mod tests {.await;let project = Project::test(fs, ["/a".as_ref()], cx).await;project.update(cx, |project, _| project.languages().add(Arc::new(language)));- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let worktree_id = workspace.update(cx, |workspace, cx| {workspace.project().read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()@@ -1989,7 +1993,9 @@ mod tests {project.update(cx, |project, _| {project.languages().add(Arc::clone(&language))});- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let worktree_id = workspace.update(cx, |workspace, cx| {workspace.project().read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()@@ -2075,8 +2081,9 @@ mod tests {deterministic.run_until_parked();cx.foreground().run_until_parked();- let (_, editor) =- cx.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx));+ let editor = cx+ .add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx))+ .detach(cx);let editor_edited = Arc::new(AtomicBool::new(false));let fake_server = fake_servers.next().await.unwrap();let closure_editor_edited = Arc::clone(&editor_edited);@@ -2328,7 +2335,9 @@ all hints should be invalidated and requeried for all of its visible excerpts"project.update(cx, |project, _| {project.languages().add(Arc::clone(&language))});- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let worktree_id = workspace.update(cx, |workspace, cx| {workspace.project().read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()@@ -2373,8 +2382,9 @@ all hints should be invalidated and requeried for all of its visible excerpts"deterministic.run_until_parked();cx.foreground().run_until_parked();- let (_, editor) =- cx.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx));+ let editor = cx+ .add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), cx))+ .detach(cx);let editor_edited = Arc::new(AtomicBool::new(false));let fake_server = fake_servers.next().await.unwrap();let closure_editor_edited = Arc::clone(&editor_edited);@@ -2562,7 +2572,9 @@ all hints should be invalidated and requeried for all of its visible excerpts"let project = Project::test(fs, ["/a".as_ref()], cx).await;project.update(cx, |project, _| project.languages().add(Arc::new(language)));- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let worktree_id = workspace.update(cx, |workspace, cx| {workspace.project().read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()diff --git a/crates/editor/src/test/editor_lsp_test_context.rs b/crates/editor/src/test/editor_lsp_test_context.rsindex 0fe49d4d046..f53115f224a 100644--- a/crates/editor/src/test/editor_lsp_test_context.rs+++ b/crates/editor/src/test/editor_lsp_test_context.rs@@ -69,7 +69,8 @@ impl<'a> EditorLspTestContext<'a> {.insert_tree("/root", json!({ "dir": { file_name.clone(): "" }})).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);project.update(cx, |project, cx| {project.find_or_create_local_worktree("/root", true, cx)@@ -98,7 +99,7 @@ impl<'a> EditorLspTestContext<'a> {Self {cx: EditorTestContext {cx,- window_id,+ window_id: window.id(),editor,},lsp,diff --git a/crates/editor/src/test/editor_test_context.rs b/crates/editor/src/test/editor_test_context.rsindex bac70f139a6..c7ea1b4f385 100644--- a/crates/editor/src/test/editor_test_context.rs+++ b/crates/editor/src/test/editor_test_context.rs@@ -32,16 +32,14 @@ impl<'a> EditorTestContext<'a> {let buffer = project.update(cx, |project, cx| project.create_buffer("", None, cx)).unwrap();- let (window_id, editor) = cx.update(|cx| {- cx.add_window(Default::default(), |cx| {- cx.focus_self();- build_editor(MultiBuffer::build_from_buffer(buffer, cx), cx)- })+ let window = cx.add_window(|cx| {+ cx.focus_self();+ build_editor(MultiBuffer::build_from_buffer(buffer, cx), cx)});-+ let editor = window.root(cx);Self {cx,- window_id,+ window_id: window.id(),editor,}}diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rsindex b6701f12d6e..2c9d9c0c71e 100644--- a/crates/file_finder/src/file_finder.rs+++ b/crates/file_finder/src/file_finder.rs@@ -617,8 +617,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));- cx.dispatch_action(window_id, Toggle);+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ cx.dispatch_action(window.id(), Toggle);let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());finder@@ -631,8 +632,8 @@ mod tests {});let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());- cx.dispatch_action(window_id, SelectNext);- cx.dispatch_action(window_id, Confirm);+ cx.dispatch_action(window.id(), SelectNext);+ cx.dispatch_action(window.id(), Confirm);active_pane.condition(cx, |pane, _| pane.active_item().is_some()).await;@@ -671,8 +672,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));- cx.dispatch_action(window_id, Toggle);+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ cx.dispatch_action(window.id(), Toggle);let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());let file_query = &first_file_name[..3];@@ -704,8 +706,8 @@ mod tests {});let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());- cx.dispatch_action(window_id, SelectNext);- cx.dispatch_action(window_id, Confirm);+ cx.dispatch_action(window.id(), SelectNext);+ cx.dispatch_action(window.id(), Confirm);active_pane.condition(cx, |pane, _| pane.active_item().is_some()).await;@@ -754,8 +756,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));- cx.dispatch_action(window_id, Toggle);+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ cx.dispatch_action(window.id(), Toggle);let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());let file_query = &first_file_name[..3];@@ -787,8 +790,8 @@ mod tests {});let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());- cx.dispatch_action(window_id, SelectNext);- cx.dispatch_action(window_id, Confirm);+ cx.dispatch_action(window.id(), SelectNext);+ cx.dispatch_action(window.id(), Confirm);active_pane.condition(cx, |pane, _| pane.active_item().is_some()).await;@@ -837,19 +840,23 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/dir".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));- let (_, finder) = cx.add_window(|cx| {- Picker::new(- FileFinderDelegate::new(- workspace.downgrade(),- workspace.read(cx).project().clone(),- None,- Vec::new(),+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);+ let finder = cx+ .add_window(|cx| {+ Picker::new(+ FileFinderDelegate::new(+ workspace.downgrade(),+ workspace.read(cx).project().clone(),+ None,+ Vec::new(),+ cx,+ ),cx,- ),- cx,- )- });+ )+ })+ .detach(cx);let query = test_path_like("hi");finder@@ -931,19 +938,23 @@ mod tests {cx,).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));- let (_, finder) = cx.add_window(|cx| {- Picker::new(- FileFinderDelegate::new(- workspace.downgrade(),- workspace.read(cx).project().clone(),- None,- Vec::new(),+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);+ let finder = cx+ .add_window(|cx| {+ Picker::new(+ FileFinderDelegate::new(+ workspace.downgrade(),+ workspace.read(cx).project().clone(),+ None,+ Vec::new(),+ cx,+ ),cx,- ),- cx,- )- });+ )+ })+ .detach(cx);finder.update(cx, |f, cx| {f.delegate_mut().spawn_search(test_path_like("hi"), cx)@@ -967,19 +978,23 @@ mod tests {cx,).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));- let (_, finder) = cx.add_window(|cx| {- Picker::new(- FileFinderDelegate::new(- workspace.downgrade(),- workspace.read(cx).project().clone(),- None,- Vec::new(),+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);+ let finder = cx+ .add_window(|cx| {+ Picker::new(+ FileFinderDelegate::new(+ workspace.downgrade(),+ workspace.read(cx).project().clone(),+ None,+ Vec::new(),+ cx,+ ),cx,- ),- cx,- )- });+ )+ })+ .detach(cx);// Even though there is only one worktree, that worktree's filename// is included in the matching, because the worktree is a single file.@@ -1015,61 +1030,6 @@ mod tests {finder.read_with(cx, |f, _| assert_eq!(f.delegate().matches.len(), 0));}- #[gpui::test]- async fn test_multiple_matches_with_same_relative_path(cx: &mut TestAppContext) {- let app_state = init_test(cx);- app_state- .fs- .as_fake()- .insert_tree(- "/root",- json!({- "dir1": { "a.txt": "" },- "dir2": { "a.txt": "" }- }),- )- .await;-- let project = Project::test(- app_state.fs.clone(),- ["/root/dir1".as_ref(), "/root/dir2".as_ref()],- cx,- )- .await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));-- let (_, finder) = cx.add_window(|cx| {- Picker::new(- FileFinderDelegate::new(- workspace.downgrade(),- workspace.read(cx).project().clone(),- None,- Vec::new(),- cx,- ),- cx,- )- });-- // Run a search that matches two files with the same relative path.- finder- .update(cx, |f, cx| {- f.delegate_mut().spawn_search(test_path_like("a.t"), cx)- })- .await;-- // Can switch between different matches with the same relative path.- finder.update(cx, |finder, cx| {- let delegate = finder.delegate_mut();- assert_eq!(delegate.matches.len(), 2);- assert_eq!(delegate.selected_index(), 0);- delegate.set_selected_index(1, cx);- assert_eq!(delegate.selected_index(), 1);- delegate.set_selected_index(0, cx);- assert_eq!(delegate.selected_index(), 0);- });- }-#[gpui::test]async fn test_path_distance_ordering(cx: &mut TestAppContext) {let app_state = init_test(cx);@@ -1089,7 +1049,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);let worktree_id = cx.read(|cx| {let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();assert_eq!(worktrees.len(), 1);@@ -1103,18 +1065,20 @@ mod tests {worktree_id,path: Arc::from(Path::new("/root/dir2/b.txt")),}));- let (_, finder) = cx.add_window(|cx| {- Picker::new(- FileFinderDelegate::new(- workspace.downgrade(),- workspace.read(cx).project().clone(),- b_path,- Vec::new(),+ let finder = cx+ .add_window(|cx| {+ Picker::new(+ FileFinderDelegate::new(+ workspace.downgrade(),+ workspace.read(cx).project().clone(),+ b_path,+ Vec::new(),+ cx,+ ),cx,- ),- cx,- )- });+ )+ })+ .detach(cx);finder.update(cx, |f, cx| {@@ -1151,19 +1115,23 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));- let (_, finder) = cx.add_window(|cx| {- Picker::new(- FileFinderDelegate::new(- workspace.downgrade(),- workspace.read(cx).project().clone(),- None,- Vec::new(),+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);+ let finder = cx+ .add_window(|cx| {+ Picker::new(+ FileFinderDelegate::new(+ workspace.downgrade(),+ workspace.read(cx).project().clone(),+ None,+ Vec::new(),+ cx,+ ),cx,- ),- cx,- )- });+ )+ })+ .detach(cx);finder.update(cx, |f, cx| {f.delegate_mut().spawn_search(test_path_like("dir"), cx)@@ -1198,7 +1166,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();let worktree_id = cx.read(|cx| {let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();assert_eq!(worktrees.len(), 1);@@ -1404,7 +1374,9 @@ mod tests {.detach();deterministic.run_until_parked();- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();let worktree_id = cx.read(|cx| {let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();assert_eq!(worktrees.len(), 1,);diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rsindex 9c0e50647c6..45169ed3af4 100644--- a/crates/gpui/src/app.rs+++ b/crates/gpui/src/app.rs@@ -1424,7 +1424,7 @@ impl AppContext {&mut self,window_id: usize,build_root_view: F,- ) -> Option<ViewHandle<V>>+ ) -> Option<WindowHandle<V>>whereV: View,F: FnOnce(&mut ViewContext<V>) -> V,@@ -3826,6 +3826,15 @@ impl<V: View> WindowHandle<V> {self.read_with(cx, |cx| cx.root_view().clone().downcast().unwrap())}+ /// Keep this window open until it's explicitly closed.+ //+ // TODO: Implement window dropping behavior when we don't call this.+ pub fn detach(mut self, cx: &impl BorrowAppContext) -> ViewHandle<V> {+ let root = self.root(cx);+ self.any_handle.ref_counts.take();+ root+ }+pub fn read_with<C, F, R>(&self, cx: &C, read: F) -> RwhereC: BorrowAppContext,@@ -3893,7 +3902,7 @@ impl<V: View> WindowHandle<V> {pub struct AnyWindowHandle {window_id: usize,root_view_type: TypeId,- ref_counts: Arc<Mutex<RefCounts>>,+ ref_counts: Option<Arc<Mutex<RefCounts>>>,#[cfg(any(test, feature = "test-support"))]handle_id: usize,@@ -3913,7 +3922,7 @@ impl AnyWindowHandle {Self {window_id,root_view_type: TypeId::of::<V>(),- ref_counts,+ ref_counts: Some(ref_counts),#[cfg(any(test, feature = "test-support"))]handle_id,}@@ -3937,7 +3946,16 @@ impl AnyWindowHandle {impl Drop for AnyWindowHandle {fn drop(&mut self) {- self.ref_counts.lock().dec_window(self.window_id)+ if let Some(ref_counts) = self.ref_counts.as_ref() {+ ref_counts.lock().dec_window(self.window_id);++ #[cfg(any(test, feature = "test-support"))]+ ref_counts+ .lock()+ .leak_detector+ .lock()+ .handle_dropped(self.window_id, self.handle_id);+ }}}diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rsindex 9dc5d99bc5e..7cdcbc2c8fc 100644--- a/crates/gpui/src/app/window.rs+++ b/crates/gpui/src/app/window.rs@@ -15,7 +15,7 @@ use crate::{util::post_inc,Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect,Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, SceneBuilder, Subscription,- View, ViewContext, ViewHandle, WindowInvalidation,+ View, ViewContext, ViewHandle, WindowHandle, WindowInvalidation,};use anyhow::{anyhow, bail, Result};use collections::{HashMap, HashSet};@@ -1151,15 +1151,15 @@ impl<'a> WindowContext<'a> {self.window.platform_window.prompt(level, msg, answers)}- pub fn replace_root_view<V, F>(&mut self, build_root_view: F) -> ViewHandle<V>+ pub fn replace_root_view<V, F>(&mut self, build_root_view: F) -> WindowHandle<V>whereV: View,F: FnOnce(&mut ViewContext<V>) -> V,{let root_view = self.add_view(|cx| build_root_view(cx));- self.window.root_view = Some(root_view.clone().into_any());self.window.focused_view_id = Some(root_view.id());- root_view+ self.window.root_view = Some(root_view.into_any());+ WindowHandle::new(self.window_id, self.ref_counts.clone())}pub fn add_view<T, F>(&mut self, build_view: F) -> ViewHandle<T>diff --git a/crates/language_tools/src/lsp_log_tests.rs b/crates/language_tools/src/lsp_log_tests.rsindex d4a16b5758a..ce05a417ad8 100644--- a/crates/language_tools/src/lsp_log_tests.rs+++ b/crates/language_tools/src/lsp_log_tests.rs@@ -61,7 +61,9 @@ async fn test_lsp_logs(cx: &mut TestAppContext) {.receive_notification::<lsp::notification::DidOpenTextDocument>().await;- let (_, log_view) = cx.add_window(|cx| LspLogView::new(project.clone(), log_store.clone(), cx));+ let log_view = cx+ .add_window(|cx| LspLogView::new(project.clone(), log_store.clone(), cx))+ .detach(cx);language_server.notify::<lsp::notification::LogMessage>(lsp::LogMessageParams {message: "hello from the server".into(),diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex 0be52646e63..fdc5ea108a8 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -1780,7 +1780,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));assert_eq!(visible_entries_as_strings(&panel, 0..50, cx),@@ -1868,7 +1870,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));select_path(&panel, "root1", cx);@@ -2219,7 +2223,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/root1".as_ref(), "/root2".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));select_path(&panel, "root1", cx);@@ -2319,7 +2325,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/root1".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));panel.update(cx, |panel, cx| {@@ -2392,7 +2400,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));toggle_expand_dir(&panel, "src/test", cx);@@ -2481,7 +2491,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));select_path(&panel, "src/", cx);@@ -2627,7 +2639,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));let new_search_events_count = Arc::new(AtomicUsize::new(0));@@ -2714,7 +2728,9 @@ mod tests {.await;let project = Project::test(fs.clone(), ["/project_root".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx));panel.update(cx, |panel, cx| {diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rsindex cbf914230d3..8471f3a3a70 100644--- a/crates/project_symbols/src/project_symbols.rs+++ b/crates/project_symbols/src/project_symbols.rs@@ -326,7 +326,9 @@ mod tests {},);- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);+ let window_id = window.id();// Create the project symbols view.let symbols = cx.add_view(window_id, |cx| {diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rsindex 45842aa5617..1e635432bd5 100644--- a/crates/search/src/buffer_search.rs+++ b/crates/search/src/buffer_search.rs@@ -849,11 +849,13 @@ mod tests {cx,)});- let (window_id, _root_view) = cx.add_window(|_| EmptyView);+ let window = cx.add_window(|_| EmptyView);- let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx));+ let editor = cx.add_view(window.id(), |cx| {+ Editor::for_buffer(buffer.clone(), None, cx)+ });- let search_bar = cx.add_view(window_id, |cx| {+ let search_bar = cx.add_view(window.id(), |cx| {let mut search_bar = BufferSearchBar::new(cx);search_bar.set_active_pane_item(Some(&editor), cx);search_bar.show(cx);@@ -1229,7 +1231,8 @@ mod tests {"Should pick a query with multiple results");let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx));- let (window_id, _root_view) = cx.add_window(|_| EmptyView);+ let window = cx.add_window(|_| EmptyView);+ let window_id = window.id();let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx));@@ -1416,11 +1419,13 @@ mod tests {"#.unindent();let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx));- let (window_id, _root_view) = cx.add_window(|_| EmptyView);+ let window = cx.add_window(|_| EmptyView);- let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx));+ let editor = cx.add_view(window.id(), |cx| {+ Editor::for_buffer(buffer.clone(), None, cx)+ });- let search_bar = cx.add_view(window_id, |cx| {+ let search_bar = cx.add_view(window.id(), |cx| {let mut search_bar = BufferSearchBar::new(cx);search_bar.set_active_pane_item(Some(&editor), cx);search_bar.show(cx);diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rsindex 1b4e32f4b83..e57edd3b147 100644--- a/crates/search/src/project_search.rs+++ b/crates/search/src/project_search.rs@@ -1447,7 +1447,9 @@ pub mod tests {.await;let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;let search = cx.add_model(|cx| ProjectSearch::new(project, cx));- let (_, search_view) = cx.add_window(|cx| ProjectSearchView::new(search.clone(), cx));+ let search_view = cx+ .add_window(|cx| ProjectSearchView::new(search.clone(), cx))+ .detach(cx);search_view.update(cx, |search_view, cx| {search_view@@ -1564,7 +1566,9 @@ pub mod tests {).await;let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();let active_item = cx.read(|cx| {workspace@@ -1748,7 +1752,9 @@ pub mod tests {let worktree_id = project.read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()});- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);let active_item = cx.read(|cx| {workspace@@ -1866,7 +1872,9 @@ pub mod tests {).await;let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();workspace.update(cx, |workspace, cx| {ProjectSearchView::deploy(workspace, &workspace::NewSearch, cx)});diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rsindex e108a05ccc0..874978b4fc5 100644--- a/crates/terminal_view/src/terminal_view.rs+++ b/crates/terminal_view/src/terminal_view.rs@@ -1070,7 +1070,9 @@ mod tests {});let project = Project::test(params.fs.clone(), [], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);(project, workspace)}diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex ee658c9cc92..98883fac337 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -1972,7 +1972,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());pane.update(cx, |pane, cx| {@@ -1987,7 +1988,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());// 1. Add with a destination index@@ -2065,7 +2067,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());// 1. Add with a destination index@@ -2141,7 +2144,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());// singleton view@@ -2209,7 +2213,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());add_labeled_item(&pane, "A", false, cx);@@ -2256,7 +2261,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());set_labeled_items(&pane, ["A", "B", "C*", "D", "E"], cx);@@ -2276,7 +2282,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());add_labeled_item(&pane, "A", true, cx);@@ -2299,7 +2306,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());set_labeled_items(&pane, ["A", "B", "C*", "D", "E"], cx);@@ -2319,7 +2327,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());set_labeled_items(&pane, ["A", "B", "C*", "D", "E"], cx);@@ -2339,7 +2348,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());add_labeled_item(&pane, "A", false, cx);diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 434975216ad..3222ea2eb8c 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -793,7 +793,7 @@ impl Workspace {DB.next_id().await.unwrap_or(0)};- let workspace = requesting_window_id+ let window = requesting_window_id.and_then(|window_id| {cx.update(|cx| {cx.replace_root_view(window_id, |cx| {@@ -852,9 +852,9 @@ impl Workspace {)},)- .1});+ let workspace = window.root(&cx);(app_state.initialize_workspace)(workspace.downgrade(),serialized_workspace.is_some(),@@ -864,7 +864,7 @@ impl Workspace {.await.log_err();- cx.update_window(workspace.window_id(), |cx| cx.activate_window());+ window.update(&mut cx, |cx| cx.activate_window());let workspace = workspace.downgrade();notify_if_database_failed(&workspace, &mut cx);@@ -3977,7 +3977,7 @@ pub fn join_remote_project(.await?;let window_bounds_override = window_bounds_env_override(&cx);- let (_, workspace) = cx.add_window(+ let window = cx.add_window((app_state.build_window_options)(window_bounds_override,None,@@ -3985,6 +3985,7 @@ pub fn join_remote_project(),|cx| Workspace::new(0, project, app_state.clone(), cx),);+ let workspace = window.root(&cx);(app_state.initialize_workspace)(workspace.downgrade(),false,@@ -4113,10 +4114,11 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, [], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);// Adding an item with no ambiguity renders the tab without detail.- let item1 = cx.add_view(window_id, |_| {+ let item1 = window.add_view(cx, |_| {let mut item = TestItem::new();item.tab_descriptions = Some(vec!["c", "b1/c", "a/b1/c"]);item@@ -4128,7 +4130,7 @@ mod tests {// Adding an item that creates ambiguity increases the level of detail on// both tabs.- let item2 = cx.add_view(window_id, |_| {+ let item2 = window.add_view(cx, |_| {let mut item = TestItem::new();item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);item@@ -4142,7 +4144,7 @@ mod tests {// Adding an item that creates ambiguity increases the level of detail only// on the ambiguous tabs. In this case, the ambiguity can't be resolved so// we stop at the highest detail available.- let item3 = cx.add_view(window_id, |_| {+ let item3 = window.add_view(cx, |_| {let mut item = TestItem::new();item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);item@@ -4177,16 +4179,17 @@ mod tests {.await;let project = Project::test(fs, ["root1".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());let worktree_id = project.read_with(cx, |project, cx| {project.worktrees(cx).next().unwrap().read(cx).id()});- let item1 = cx.add_view(window_id, |cx| {+ let item1 = window.add_view(cx, |cx| {TestItem::new().with_project_items(&[TestProjectItem::new(1, "one.txt", cx)])});- let item2 = cx.add_view(window_id, |cx| {+ let item2 = window.add_view(cx, |cx| {TestItem::new().with_project_items(&[TestProjectItem::new(2, "two.txt", cx)])});@@ -4201,14 +4204,14 @@ mod tests {);});assert_eq!(- cx.current_window_title(window_id).as_deref(),+ cx.current_window_title(window.id()).as_deref(),Some("one.txt — root1"));// Add a second item to a non-empty paneworkspace.update(cx, |workspace, cx| workspace.add_item(Box::new(item2), cx));assert_eq!(- cx.current_window_title(window_id).as_deref(),+ cx.current_window_title(window.id()).as_deref(),Some("two.txt — root1"));project.read_with(cx, |project, cx| {@@ -4227,7 +4230,7 @@ mod tests {.await.unwrap();assert_eq!(- cx.current_window_title(window_id).as_deref(),+ cx.current_window_title(window.id()).as_deref(),Some("one.txt — root1"));project.read_with(cx, |project, cx| {@@ -4247,14 +4250,14 @@ mod tests {.await.unwrap();assert_eq!(- cx.current_window_title(window_id).as_deref(),+ cx.current_window_title(window.id()).as_deref(),Some("one.txt — root1, root2"));// Remove a project folderproject.update(cx, |project, cx| project.remove_worktree(worktree_id, cx));assert_eq!(- cx.current_window_title(window_id).as_deref(),+ cx.current_window_title(window.id()).as_deref(),Some("one.txt — root2"));}@@ -4267,18 +4270,19 @@ mod tests {fs.insert_tree("/root", json!({ "one": "" })).await;let project = Project::test(fs, ["root".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = window.root(cx);// When there are no dirty items, there's nothing to do.- let item1 = cx.add_view(window_id, |_| TestItem::new());+ let item1 = window.add_view(cx, |_| TestItem::new());workspace.update(cx, |w, cx| w.add_item(Box::new(item1.clone()), cx));let task = workspace.update(cx, |w, cx| w.prepare_to_close(false, cx));assert!(task.await.unwrap());// When there are dirty untitled items, prompt to save each one. If the user// cancels any prompt, then abort.- let item2 = cx.add_view(window_id, |_| TestItem::new().with_dirty(true));- let item3 = cx.add_view(window_id, |cx| {+ let item2 = window.add_view(cx, |_| TestItem::new().with_dirty(true));+ let item3 = window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])@@ -4289,9 +4293,9 @@ mod tests {});let task = workspace.update(cx, |w, cx| w.prepare_to_close(false, cx));cx.foreground().run_until_parked();- cx.simulate_prompt_answer(window_id, 2 /* cancel */);+ cx.simulate_prompt_answer(window.id(), 2 /* cancel */);cx.foreground().run_until_parked();- assert!(!cx.has_pending_prompt(window_id));+ assert!(!cx.has_pending_prompt(window.id()));assert!(!task.await.unwrap());}@@ -4302,26 +4306,27 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, None, cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);- let item1 = cx.add_view(window_id, |cx| {+ let item1 = window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])});- let item2 = cx.add_view(window_id, |cx| {+ let item2 = window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_conflict(true).with_project_items(&[TestProjectItem::new(2, "2.txt", cx)])});- let item3 = cx.add_view(window_id, |cx| {+ let item3 = window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_conflict(true).with_project_items(&[TestProjectItem::new(3, "3.txt", cx)])});- let item4 = cx.add_view(window_id, |cx| {+ let item4 = window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_project_items(&[TestProjectItem::new_untitled(cx)])@@ -4349,10 +4354,10 @@ mod tests {assert_eq!(pane.items_len(), 4);assert_eq!(pane.active_item().unwrap().id(), item1.id());});- assert!(cx.has_pending_prompt(window_id));+ assert!(cx.has_pending_prompt(window.id()));// Confirm saving item 1.- cx.simulate_prompt_answer(window_id, 0);+ cx.simulate_prompt_answer(window.id(), 0);cx.foreground().run_until_parked();// Item 1 is saved. There's a prompt to save item 3.@@ -4363,10 +4368,10 @@ mod tests {assert_eq!(pane.items_len(), 3);assert_eq!(pane.active_item().unwrap().id(), item3.id());});- assert!(cx.has_pending_prompt(window_id));+ assert!(cx.has_pending_prompt(window.id()));// Cancel saving item 3.- cx.simulate_prompt_answer(window_id, 1);+ cx.simulate_prompt_answer(window.id(), 1);cx.foreground().run_until_parked();// Item 3 is reloaded. There's a prompt to save item 4.@@ -4377,10 +4382,10 @@ mod tests {assert_eq!(pane.items_len(), 2);assert_eq!(pane.active_item().unwrap().id(), item4.id());});- assert!(cx.has_pending_prompt(window_id));+ assert!(cx.has_pending_prompt(window.id()));// Confirm saving item 4.- cx.simulate_prompt_answer(window_id, 0);+ cx.simulate_prompt_answer(window.id(), 0);cx.foreground().run_until_parked();// There's a prompt for a path for item 4.@@ -4404,13 +4409,14 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, [], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);// Create several workspace items with single project entries, and two// workspace items with multiple project entries.let single_entry_items = (0..=4).map(|project_entry_id| {- cx.add_view(window_id, |cx| {+ window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_project_items(&[TestProjectItem::new(@@ -4421,7 +4427,7 @@ mod tests {})}).collect::<Vec<_>>();- let item_2_3 = cx.add_view(window_id, |cx| {+ let item_2_3 = window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_singleton(false)@@ -4430,7 +4436,7 @@ mod tests {single_entry_items[3].read(cx).project_items[0].clone(),])});- let item_3_4 = cx.add_view(window_id, |cx| {+ let item_3_4 = window.add_view(cx, |cx| {TestItem::new().with_dirty(true).with_singleton(false)@@ -4482,7 +4488,7 @@ mod tests {&[ProjectEntryId::from_proto(0)]);});- cx.simulate_prompt_answer(window_id, 0);+ cx.simulate_prompt_answer(window.id(), 0);cx.foreground().run_until_parked();left_pane.read_with(cx, |pane, cx| {@@ -4491,7 +4497,7 @@ mod tests {&[ProjectEntryId::from_proto(2)]);});- cx.simulate_prompt_answer(window_id, 0);+ cx.simulate_prompt_answer(window.id(), 0);cx.foreground().run_until_parked();close.await.unwrap();@@ -4507,10 +4513,11 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, [], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());- let item = cx.add_view(window_id, |cx| {+ let item = window.add_view(cx, |cx| {TestItem::new().with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])});let item_id = item.id();@@ -4550,7 +4557,7 @@ mod tests {item.read_with(cx, |item, _| assert_eq!(item.save_count, 2));// Deactivating the window still saves the file.- cx.simulate_window_activation(Some(window_id));+ cx.simulate_window_activation(Some(window.id()));item.update(cx, |item, cx| {cx.focus_self();item.is_dirty = true;@@ -4592,7 +4599,7 @@ mod tests {pane.update(cx, |pane, cx| pane.close_items(cx, move |id| id == item_id)).await.unwrap();- assert!(!cx.has_pending_prompt(window_id));+ assert!(!cx.has_pending_prompt(window.id()));item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));// Add the item again, ensuring autosave is prevented if the underlying file has been deleted.@@ -4613,7 +4620,7 @@ mod tests {let _close_items =pane.update(cx, |pane, cx| pane.close_items(cx, move |id| id == item_id));deterministic.run_until_parked();- assert!(cx.has_pending_prompt(window_id));+ assert!(cx.has_pending_prompt(window.id()));item.read_with(cx, |item, _| assert_eq!(item.save_count, 5));}@@ -4624,9 +4631,10 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, [], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);- let item = cx.add_view(window_id, |cx| {+ let item = window.add_view(cx, |cx| {TestItem::new().with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])});let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());@@ -4677,7 +4685,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, [], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);let panel = workspace.update(cx, |workspace, cx| {let panel = cx.add_view(|_| TestPanel::new(DockPosition::Right));@@ -4824,7 +4833,8 @@ mod tests {let fs = FakeFs::new(cx.background());let project = Project::test(fs, [], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);let (panel_1, panel_2) = workspace.update(cx, |workspace, cx| {// Add panel_1 on the left, panel_2 on the right.@@ -4979,7 +4989,7 @@ mod tests {// If focus is transferred to another view that's not a panel or another pane, we still show// the panel as zoomed.- let focus_receiver = cx.add_view(window_id, |_| EmptyView);+ let focus_receiver = window.add_view(cx, |_| EmptyView);focus_receiver.update(cx, |_, cx| cx.focus_self());workspace.read_with(cx, |workspace, _| {assert_eq!(workspace.zoomed, Some(panel_1.downgrade().into_any()));diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rsindex 4b0bf1cd4c6..1770c5648e1 100644--- a/crates/zed/src/zed.rs+++ b/crates/zed/src/zed.rs@@ -983,7 +983,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);let entries = cx.read(|cx| workspace.file_project_paths(cx));let file1 = entries[0].clone();@@ -1295,7 +1297,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();// Open a file within an existing worktree.workspace@@ -1336,7 +1340,9 @@ mod tests {let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;project.update(cx, |project, _| project.languages().add(rust_lang()));- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap());// Create a new untitled buffer@@ -1429,7 +1435,9 @@ mod tests {let project = Project::test(app_state.fs.clone(), [], cx).await;project.update(cx, |project, _| project.languages().add(rust_lang()));- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();// Create a new untitled buffercx.dispatch_action(window_id, NewFile);@@ -1480,7 +1488,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let window = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = window.root(cx);+ let window_id = window.id();let entries = cx.read(|cx| workspace.file_project_paths(cx));let file1 = entries[0].clone();@@ -1554,7 +1564,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project.clone(), cx))+ .detach(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());let entries = cx.read(|cx| workspace.file_project_paths(cx));@@ -1831,7 +1843,9 @@ mod tests {.await;let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;- let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ let workspace = cx+ .add_window(|cx| Workspace::test_new(project, cx))+ .detach(cx);let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());let entries = cx.read(|cx| workspace.file_project_paths(cx));@@ -2073,7 +2087,8 @@ mod tests {cx.foreground().run_until_parked();- let (window_id, _view) = cx.add_window(|_| TestView);+ let window = cx.add_window(|_| TestView);+ let window_id = window.id();// Test loading the keymap base at allassert_key_bindings_for(@@ -2243,7 +2258,8 @@ mod tests {cx.foreground().run_until_parked();- let (window_id, _view) = cx.add_window(|_| TestView);+ let window = cx.add_window(|_| TestView);+ let window_id = window.id();// Test loading the keymap base at allassert_key_bindings_for(