From db1cf8f6e1ce028004b974188e39c708a4f2208b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 1 Jan 2024 12:01:29 -0700 Subject: [PATCH] Rename `build_view` to `new_view` and `build_model` to `new_model` The word "new" is shorter and blends in with `new` constructors that are common in Rust. Been meaning to do this for a while. --- .../src/activity_indicator.rs | 8 +- crates/assistant2/src/assistant_panel.rs | 41 ++++--- crates/assistant2/src/codegen.rs | 18 ++-- crates/assistant2/src/prompts.rs | 2 +- crates/auto_update2/src/auto_update.rs | 4 +- crates/call2/src/call2.rs | 2 +- crates/call2/src/room.rs | 4 +- crates/channel2/src/channel_buffer.rs | 4 +- crates/channel2/src/channel_chat.rs | 2 +- crates/channel2/src/channel_store.rs | 2 +- crates/channel2/src/channel_store_tests.rs | 2 +- crates/client2/src/client2.rs | 10 +- crates/client2/src/test.rs | 2 +- crates/collab2/src/tests/test_server.rs | 4 +- crates/collab_ui2/src/channel_view.rs | 6 +- crates/collab_ui2/src/chat_panel.rs | 6 +- .../src/chat_panel/message_editor.rs | 4 +- crates/collab_ui2/src/collab_panel.rs | 8 +- .../src/collab_panel/channel_modal.rs | 2 +- .../src/collab_panel/contact_finder.rs | 2 +- crates/collab_ui2/src/collab_titlebar_item.rs | 2 +- crates/collab_ui2/src/notification_panel.rs | 4 +- .../incoming_call_notification.rs | 2 +- .../project_shared_notification.rs | 2 +- .../command_palette2/src/command_palette.rs | 4 +- crates/copilot2/src/copilot2.rs | 8 +- crates/copilot2/src/sign_in.rs | 2 +- crates/diagnostics2/src/diagnostics.rs | 10 +- crates/editor2/src/display_map.rs | 33 +++--- crates/editor2/src/display_map/wrap_map.rs | 2 +- crates/editor2/src/editor.rs | 32 +++--- crates/editor2/src/editor_tests.rs | 100 ++++++++---------- crates/editor2/src/git.rs | 2 +- crates/editor2/src/inlay_hint_cache.rs | 4 +- crates/editor2/src/items.rs | 8 +- crates/editor2/src/movement.rs | 10 +- crates/editor2/src/rust_analyzer_ext.rs | 4 +- crates/editor2/src/test.rs | 2 +- crates/feedback2/src/feedback_modal.rs | 4 +- crates/file_finder2/src/file_finder.rs | 2 +- crates/go_to_line2/src/go_to_line.rs | 2 +- crates/gpui2/src/app.rs | 2 +- crates/gpui2/src/app/async_context.rs | 13 ++- crates/gpui2/src/app/model_context.rs | 4 +- crates/gpui2/src/app/test_context.rs | 24 ++--- crates/gpui2/src/gpui2.rs | 4 +- crates/gpui2/src/interactive.rs | 2 +- crates/gpui2/src/window.rs | 19 ++-- crates/language2/src/buffer_tests.rs | 68 ++++++------ .../src/language_selector.rs | 2 +- crates/language_tools2/src/lsp_log.rs | 6 +- crates/language_tools2/src/lsp_log_tests.rs | 2 +- .../language_tools2/src/syntax_tree_view.rs | 4 +- crates/multi_buffer2/src/multi_buffer2.rs | 75 +++++++------ .../notifications2/src/notification_store2.rs | 2 +- crates/outline2/src/outline.rs | 2 +- crates/picker2/src/picker2.rs | 2 +- crates/project2/src/project2.rs | 10 +- crates/project2/src/terminals.rs | 2 +- crates/project2/src/worktree.rs | 6 +- crates/project_panel2/src/project_panel.rs | 6 +- .../project_symbols2/src/project_symbols.rs | 2 +- .../recent_projects2/src/recent_projects.rs | 4 +- crates/search2/src/buffer_search.rs | 20 ++-- crates/search2/src/project_search.rs | 32 +++--- crates/semantic_index2/src/semantic_index.rs | 2 +- .../src/stories/auto_height_editor.rs | 4 +- crates/storybook2/src/stories/focus.rs | 2 +- crates/storybook2/src/stories/kitchen_sink.rs | 2 +- crates/storybook2/src/stories/picker.rs | 4 +- crates/storybook2/src/stories/scroll.rs | 2 +- crates/storybook2/src/stories/text.rs | 2 +- crates/storybook2/src/story_selector.rs | 40 ++++--- crates/storybook2/src/storybook2.rs | 2 +- crates/terminal_view2/src/terminal_panel.rs | 6 +- crates/terminal_view2/src/terminal_view.rs | 4 +- crates/theme_selector2/src/theme_selector.rs | 2 +- crates/ui2/src/components/context_menu.rs | 2 +- crates/ui2/src/components/tooltip.rs | 6 +- crates/vcs_menu2/src/lib.rs | 4 +- crates/vim2/src/editor_events.rs | 2 +- crates/vim2/src/test/vim_test_context.rs | 4 +- crates/welcome2/src/base_keymap_picker.rs | 2 +- crates/welcome2/src/welcome.rs | 6 +- crates/workspace2/src/dock.rs | 4 +- crates/workspace2/src/item.rs | 8 +- crates/workspace2/src/modal_layer.rs | 2 +- crates/workspace2/src/notifications.rs | 4 +- crates/workspace2/src/pane.rs | 29 +++-- crates/workspace2/src/shared_screen.rs | 2 +- crates/workspace2/src/workspace2.rs | 72 ++++++------- crates/zed2/src/languages/c.rs | 2 +- crates/zed2/src/languages/python.rs | 2 +- crates/zed2/src/languages/rust.rs | 2 +- crates/zed2/src/languages/typescript.rs | 2 +- crates/zed2/src/main.rs | 4 +- crates/zed2/src/zed2.rs | 48 +++++---- 97 files changed, 470 insertions(+), 494 deletions(-) diff --git a/crates/activity_indicator2/src/activity_indicator.rs b/crates/activity_indicator2/src/activity_indicator.rs index cbb6daca77..ffb11da21d 100644 --- a/crates/activity_indicator2/src/activity_indicator.rs +++ b/crates/activity_indicator2/src/activity_indicator.rs @@ -55,7 +55,7 @@ impl ActivityIndicator { ) -> View { let project = workspace.project().clone(); let auto_updater = AutoUpdater::get(cx); - let this = cx.build_view(|cx: &mut ViewContext| { + let this = cx.new_view(|cx: &mut ViewContext| { let mut status_events = languages.language_server_binary_statuses(); cx.spawn(|this, mut cx| async move { while let Some((language, event)) = status_events.next().await { @@ -101,9 +101,9 @@ impl ActivityIndicator { ); }); workspace.add_item( - Box::new(cx.build_view(|cx| { - Editor::for_buffer(buffer, Some(project.clone()), cx) - })), + Box::new( + cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx)), + ), cx, ); } diff --git a/crates/assistant2/src/assistant_panel.rs b/crates/assistant2/src/assistant_panel.rs index 5318096f57..b158facbd9 100644 --- a/crates/assistant2/src/assistant_panel.rs +++ b/crates/assistant2/src/assistant_panel.rs @@ -126,7 +126,7 @@ impl AssistantPanel { // TODO: deserialize state. let workspace_handle = workspace.clone(); workspace.update(&mut cx, |workspace, cx| { - cx.build_view::(|cx| { + cx.new_view::(|cx| { const CONVERSATION_WATCH_DURATION: Duration = Duration::from_millis(100); let _watch_saved_conversations = cx.spawn(move |this, mut cx| async move { let mut events = fs @@ -147,10 +147,10 @@ impl AssistantPanel { anyhow::Ok(()) }); - let toolbar = cx.build_view(|cx| { + let toolbar = cx.new_view(|cx| { let mut toolbar = Toolbar::new(); toolbar.set_can_navigate(false, cx); - toolbar.add_item(cx.build_view(|cx| BufferSearchBar::new(cx)), cx); + toolbar.add_item(cx.new_view(|cx| BufferSearchBar::new(cx)), cx); toolbar }); @@ -306,7 +306,7 @@ impl AssistantPanel { // Retrieve Credentials Authenticates the Provider provider.retrieve_credentials(cx); - let codegen = cx.build_model(|cx| { + let codegen = cx.new_model(|cx| { Codegen::new(editor.read(cx).buffer().clone(), codegen_kind, provider, cx) }); @@ -332,7 +332,7 @@ impl AssistantPanel { } let measurements = Rc::new(Cell::new(BlockMeasurements::default())); - let inline_assistant = cx.build_view(|cx| { + let inline_assistant = cx.new_view(|cx| { InlineAssistant::new( inline_assist_id, measurements.clone(), @@ -790,7 +790,7 @@ impl AssistantPanel { } fn new_conversation(&mut self, cx: &mut ViewContext) -> View { - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { ConversationEditor::new( self.completion_provider.clone(), self.languages.clone(), @@ -1058,7 +1058,7 @@ impl AssistantPanel { cx.spawn(|this, mut cx| async move { let saved_conversation = fs.load(&path).await?; let saved_conversation = serde_json::from_str(&saved_conversation)?; - let conversation = cx.build_model(|cx| { + let conversation = cx.new_model(|cx| { Conversation::deserialize(saved_conversation, path.clone(), languages, cx) })?; this.update(&mut cx, |this, cx| { @@ -1067,7 +1067,7 @@ impl AssistantPanel { if let Some(ix) = this.editor_index_for_path(&path, cx) { this.set_active_editor_index(Some(ix), cx); } else { - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { ConversationEditor::for_conversation(conversation, fs, workspace, cx) }); this.add_conversation(editor, cx); @@ -1093,7 +1093,7 @@ impl AssistantPanel { } fn build_api_key_editor(cx: &mut ViewContext) -> View { - cx.build_view(|cx| { + cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text("sk-000000000000000000000000000000000000000000000000", cx); editor @@ -1335,7 +1335,7 @@ impl Conversation { completion_provider: Arc, ) -> Self { let markdown = language_registry.language_for_name("Markdown"); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), ""); buffer.set_language_registry(language_registry); cx.spawn(|buffer, mut cx| async move { @@ -1430,7 +1430,7 @@ impl Conversation { let markdown = language_registry.language_for_name("Markdown"); let mut message_anchors = Vec::new(); let mut next_message_id = MessageId(0); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), saved_conversation.text); for message in saved_conversation.messages { message_anchors.push(MessageAnchor { @@ -2081,7 +2081,7 @@ impl ConversationEditor { cx: &mut ViewContext, ) -> Self { let conversation = - cx.build_model(|cx| Conversation::new(language_registry, cx, completion_provider)); + cx.new_model(|cx| Conversation::new(language_registry, cx, completion_provider)); Self::for_conversation(conversation, fs, workspace, cx) } @@ -2091,7 +2091,7 @@ impl ConversationEditor { workspace: WeakView, cx: &mut ViewContext, ) -> Self { - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { let mut editor = Editor::for_buffer(conversation.read(cx).buffer.clone(), None, cx); editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); editor.set_show_gutter(false, cx); @@ -2708,7 +2708,7 @@ impl InlineAssistant { semantic_index: Option>, project: Model, ) -> Self { - let prompt_editor = cx.build_view(|cx| { + let prompt_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); let placeholder = match codegen.read(cx).kind() { CodegenKind::Transform { .. } => "Enter transformation prompt…", @@ -3129,8 +3129,7 @@ mod tests { let registry = Arc::new(LanguageRegistry::test()); let completion_provider = Arc::new(FakeCompletionProvider::new()); - let conversation = - cx.build_model(|cx| Conversation::new(registry, cx, completion_provider)); + let conversation = cx.new_model(|cx| Conversation::new(registry, cx, completion_provider)); let buffer = conversation.read(cx).buffer.clone(); let message_1 = conversation.read(cx).message_anchors[0].clone(); @@ -3261,8 +3260,7 @@ mod tests { let registry = Arc::new(LanguageRegistry::test()); let completion_provider = Arc::new(FakeCompletionProvider::new()); - let conversation = - cx.build_model(|cx| Conversation::new(registry, cx, completion_provider)); + let conversation = cx.new_model(|cx| Conversation::new(registry, cx, completion_provider)); let buffer = conversation.read(cx).buffer.clone(); let message_1 = conversation.read(cx).message_anchors[0].clone(); @@ -3360,8 +3358,7 @@ mod tests { init(cx); let registry = Arc::new(LanguageRegistry::test()); let completion_provider = Arc::new(FakeCompletionProvider::new()); - let conversation = - cx.build_model(|cx| Conversation::new(registry, cx, completion_provider)); + let conversation = cx.new_model(|cx| Conversation::new(registry, cx, completion_provider)); let buffer = conversation.read(cx).buffer.clone(); let message_1 = conversation.read(cx).message_anchors[0].clone(); @@ -3446,7 +3443,7 @@ mod tests { let registry = Arc::new(LanguageRegistry::test()); let completion_provider = Arc::new(FakeCompletionProvider::new()); let conversation = - cx.build_model(|cx| Conversation::new(registry.clone(), cx, completion_provider)); + cx.new_model(|cx| Conversation::new(registry.clone(), cx, completion_provider)); let buffer = conversation.read(cx).buffer.clone(); let message_0 = conversation.read(cx).message_anchors[0].id; let message_1 = conversation.update(cx, |conversation, cx| { @@ -3479,7 +3476,7 @@ mod tests { ] ); - let deserialized_conversation = cx.build_model(|cx| { + let deserialized_conversation = cx.new_model(|cx| { Conversation::deserialize( conversation.read(cx).serialize(cx), Default::default(), diff --git a/crates/assistant2/src/codegen.rs b/crates/assistant2/src/codegen.rs index 2f7b2f0378..8af3010f40 100644 --- a/crates/assistant2/src/codegen.rs +++ b/crates/assistant2/src/codegen.rs @@ -395,14 +395,14 @@ mod tests { } "}; let buffer = - cx.build_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + cx.new_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let range = buffer.read_with(cx, |buffer, cx| { let snapshot = buffer.snapshot(cx); snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(4, 5)) }); let provider = Arc::new(FakeCompletionProvider::new()); - let codegen = cx.build_model(|cx| { + let codegen = cx.new_model(|cx| { Codegen::new( buffer.clone(), CodegenKind::Transform { range }, @@ -461,14 +461,14 @@ mod tests { } "}; let buffer = - cx.build_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + cx.new_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let position = buffer.read_with(cx, |buffer, cx| { let snapshot = buffer.snapshot(cx); snapshot.anchor_before(Point::new(1, 6)) }); let provider = Arc::new(FakeCompletionProvider::new()); - let codegen = cx.build_model(|cx| { + let codegen = cx.new_model(|cx| { Codegen::new( buffer.clone(), CodegenKind::Generate { position }, @@ -526,14 +526,14 @@ mod tests { "}\n" // ); let buffer = - cx.build_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + cx.new_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let position = buffer.read_with(cx, |buffer, cx| { let snapshot = buffer.snapshot(cx); snapshot.anchor_before(Point::new(1, 2)) }); let provider = Arc::new(FakeCompletionProvider::new()); - let codegen = cx.build_model(|cx| { + let codegen = cx.new_model(|cx| { Codegen::new( buffer.clone(), CodegenKind::Generate { position }, diff --git a/crates/assistant2/src/prompts.rs b/crates/assistant2/src/prompts.rs index 06881ad9c2..c88e257295 100644 --- a/crates/assistant2/src/prompts.rs +++ b/crates/assistant2/src/prompts.rs @@ -254,7 +254,7 @@ pub(crate) mod tests { } "}; let buffer = - cx.build_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); + cx.new_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx)); let snapshot = buffer.read(cx).snapshot(); assert_eq!( diff --git a/crates/auto_update2/src/auto_update.rs b/crates/auto_update2/src/auto_update.rs index 79269acc27..691b83479f 100644 --- a/crates/auto_update2/src/auto_update.rs +++ b/crates/auto_update2/src/auto_update.rs @@ -94,7 +94,7 @@ pub fn init(http_client: Arc, server_url: String, cx: &mut AppCo .detach(); if let Some(version) = ZED_APP_VERSION.or_else(|| cx.app_metadata().app_version) { - let auto_updater = cx.build_model(|cx| { + let auto_updater = cx.new_model(|cx| { let updater = AutoUpdater::new(version, http_client, server_url); let mut update_subscription = AutoUpdateSetting::get_global(cx) @@ -160,7 +160,7 @@ pub fn notify_of_any_new_update(cx: &mut ViewContext) -> Option<()> { if should_show_notification { workspace.update(&mut cx, |workspace, cx| { workspace.show_notification(0, cx, |cx| { - cx.build_view(|_| UpdateNotification::new(version)) + cx.new_view(|_| UpdateNotification::new(version)) }); updater .read(cx) diff --git a/crates/call2/src/call2.rs b/crates/call2/src/call2.rs index 14cb28c32d..bc8a0809ca 100644 --- a/crates/call2/src/call2.rs +++ b/crates/call2/src/call2.rs @@ -24,7 +24,7 @@ pub use room::Room; pub fn init(client: Arc, user_store: Model, cx: &mut AppContext) { CallSettings::register(cx); - let active_call = cx.build_model(|cx| ActiveCall::new(client, user_store, cx)); + let active_call = cx.new_model(|cx| ActiveCall::new(client, user_store, cx)); cx.set_global(active_call); } diff --git a/crates/call2/src/room.rs b/crates/call2/src/room.rs index 694966abe9..0dfdb50fc7 100644 --- a/crates/call2/src/room.rs +++ b/crates/call2/src/room.rs @@ -246,7 +246,7 @@ impl Room { cx.spawn(move |mut cx| async move { let response = client.request(proto::CreateRoom {}).await?; let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?; - let room = cx.build_model(|cx| { + let room = cx.new_model(|cx| { Self::new( room_proto.id, None, @@ -343,7 +343,7 @@ impl Room { mut cx: AsyncAppContext, ) -> Result> { let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?; - let room = cx.build_model(|cx| { + let room = cx.new_model(|cx| { Self::new( room_proto.id, response.channel_id, diff --git a/crates/channel2/src/channel_buffer.rs b/crates/channel2/src/channel_buffer.rs index 764f5f7661..62daad0a62 100644 --- a/crates/channel2/src/channel_buffer.rs +++ b/crates/channel2/src/channel_buffer.rs @@ -61,14 +61,14 @@ impl ChannelBuffer { .map(language::proto::deserialize_operation) .collect::, _>>()?; - let buffer = cx.build_model(|_| { + let buffer = cx.new_model(|_| { language::Buffer::remote(response.buffer_id, response.replica_id as u16, base_text) })?; buffer.update(&mut cx, |buffer, cx| buffer.apply_ops(operations, cx))??; let subscription = client.subscribe_to_entity(channel.id)?; - anyhow::Ok(cx.build_model(|cx| { + anyhow::Ok(cx.new_model(|cx| { cx.subscribe(&buffer, Self::on_buffer_update).detach(); cx.on_release(Self::release).detach(); let mut this = Self { diff --git a/crates/channel2/src/channel_chat.rs b/crates/channel2/src/channel_chat.rs index eb92eb18e4..d2250972f3 100644 --- a/crates/channel2/src/channel_chat.rs +++ b/crates/channel2/src/channel_chat.rs @@ -99,7 +99,7 @@ impl ChannelChat { let messages = messages_from_proto(response.messages, &user_store, &mut cx).await?; let loaded_all_messages = response.done; - Ok(cx.build_model(|cx| { + Ok(cx.new_model(|cx| { cx.on_release(Self::release).detach(); let mut this = Self { channel_id: channel.id, diff --git a/crates/channel2/src/channel_store.rs b/crates/channel2/src/channel_store.rs index 1bd987274c..44f527bdfd 100644 --- a/crates/channel2/src/channel_store.rs +++ b/crates/channel2/src/channel_store.rs @@ -20,7 +20,7 @@ use util::{async_maybe, ResultExt}; pub fn init(client: &Arc, user_store: Model, cx: &mut AppContext) { let channel_store = - cx.build_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx)); + cx.new_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx)); cx.set_global(channel_store); } diff --git a/crates/channel2/src/channel_store_tests.rs b/crates/channel2/src/channel_store_tests.rs index 7f392032cd..20413d7a76 100644 --- a/crates/channel2/src/channel_store_tests.rs +++ b/crates/channel2/src/channel_store_tests.rs @@ -345,7 +345,7 @@ async fn test_channel_messages(cx: &mut TestAppContext) { fn init_test(cx: &mut AppContext) -> Model { let http = FakeHttpClient::with_404_response(); let client = Client::new(http.clone(), cx); - let user_store = cx.build_model(|cx| UserStore::new(client.clone(), cx)); + let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); let settings_store = SettingsStore::test(cx); cx.set_global(settings_store); diff --git a/crates/client2/src/client2.rs b/crates/client2/src/client2.rs index 2c97872989..2f1e234b73 100644 --- a/crates/client2/src/client2.rs +++ b/crates/client2/src/client2.rs @@ -1579,15 +1579,15 @@ mod tests { async { Ok(()) } }, ); - let model1 = cx.build_model(|_| TestModel { + let model1 = cx.new_model(|_| TestModel { id: 1, subscription: None, }); - let model2 = cx.build_model(|_| TestModel { + let model2 = cx.new_model(|_| TestModel { id: 2, subscription: None, }); - let model3 = cx.build_model(|_| TestModel { + let model3 = cx.new_model(|_| TestModel { id: 3, subscription: None, }); @@ -1620,7 +1620,7 @@ mod tests { let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let server = FakeServer::for_client(user_id, &client, cx).await; - let model = cx.build_model(|_| TestModel::default()); + let model = cx.new_model(|_| TestModel::default()); let (done_tx1, _done_rx1) = smol::channel::unbounded(); let (done_tx2, mut done_rx2) = smol::channel::unbounded(); let subscription1 = client.add_message_handler( @@ -1648,7 +1648,7 @@ mod tests { let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let server = FakeServer::for_client(user_id, &client, cx).await; - let model = cx.build_model(|_| TestModel::default()); + let model = cx.new_model(|_| TestModel::default()); let (done_tx, mut done_rx) = smol::channel::unbounded(); let subscription = client.add_message_handler( model.clone().downgrade(), diff --git a/crates/client2/src/test.rs b/crates/client2/src/test.rs index ce3ea740b6..9338e8cb91 100644 --- a/crates/client2/src/test.rs +++ b/crates/client2/src/test.rs @@ -194,7 +194,7 @@ impl FakeServer { client: Arc, cx: &mut TestAppContext, ) -> Model { - let user_store = cx.build_model(|cx| UserStore::new(client, cx)); + let user_store = cx.new_model(|cx| UserStore::new(client, cx)); assert_eq!( self.receive::() .await diff --git a/crates/collab2/src/tests/test_server.rs b/crates/collab2/src/tests/test_server.rs index cfecb4880d..f7b7c2811b 100644 --- a/crates/collab2/src/tests/test_server.rs +++ b/crates/collab2/src/tests/test_server.rs @@ -209,8 +209,8 @@ impl TestServer { }); let fs = FakeFs::new(cx.executor()); - let user_store = cx.build_model(|cx| UserStore::new(client.clone(), cx)); - let workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); + let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); + let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx)); let mut language_registry = LanguageRegistry::test(); language_registry.set_executor(cx.executor()); let app_state = Arc::new(workspace::AppState { diff --git a/crates/collab_ui2/src/channel_view.rs b/crates/collab_ui2/src/channel_view.rs index 04ca511905..6674c2f056 100644 --- a/crates/collab_ui2/src/channel_view.rs +++ b/crates/collab_ui2/src/channel_view.rs @@ -105,7 +105,7 @@ impl ChannelView { } } - let view = cx.build_view(|cx| { + let view = cx.new_view(|cx| { let mut this = Self::new(project, channel_store, channel_buffer, cx); this.acknowledge_buffer_version(cx); this @@ -133,7 +133,7 @@ impl ChannelView { cx: &mut ViewContext, ) -> Self { let buffer = channel_buffer.read(cx).buffer(); - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { let mut editor = Editor::for_buffer(buffer, None, cx); editor.set_collaboration_hub(Box::new(ChannelBufferCollaborationHub( channel_buffer.clone(), @@ -274,7 +274,7 @@ impl Item for ChannelView { } fn clone_on_split(&self, _: WorkspaceId, cx: &mut ViewContext) -> Option> { - Some(cx.build_view(|cx| { + Some(cx.new_view(|cx| { Self::new( self.project.clone(), self.channel_store.clone(), diff --git a/crates/collab_ui2/src/chat_panel.rs b/crates/collab_ui2/src/chat_panel.rs index 07460e2620..84bd855754 100644 --- a/crates/collab_ui2/src/chat_panel.rs +++ b/crates/collab_ui2/src/chat_panel.rs @@ -81,18 +81,18 @@ impl ChatPanel { let channel_store = ChannelStore::global(cx); let languages = workspace.app_state().languages.clone(); - let input_editor = cx.build_view(|cx| { + let input_editor = cx.new_view(|cx| { MessageEditor::new( languages.clone(), channel_store.clone(), - cx.build_view(|cx| Editor::auto_height(4, cx)), + cx.new_view(|cx| Editor::auto_height(4, cx)), cx, ) }); let workspace_handle = workspace.weak_handle(); - cx.build_view(|cx: &mut ViewContext| { + cx.new_view(|cx: &mut ViewContext| { let view = cx.view().downgrade(); let message_list = ListState::new(0, gpui::ListAlignment::Bottom, px(1000.), move |ix, cx| { diff --git a/crates/collab_ui2/src/chat_panel/message_editor.rs b/crates/collab_ui2/src/chat_panel/message_editor.rs index d30a1009b6..1b52d6eed9 100644 --- a/crates/collab_ui2/src/chat_panel/message_editor.rs +++ b/crates/collab_ui2/src/chat_panel/message_editor.rs @@ -219,7 +219,7 @@ mod tests { MessageEditor::new( language_registry, ChannelStore::global(cx), - cx.build_view(|cx| Editor::auto_height(4, cx)), + cx.new_view(|cx| Editor::auto_height(4, cx)), cx, ) }); @@ -273,7 +273,7 @@ mod tests { cx.update(|cx| { let http = FakeHttpClient::with_404_response(); let client = Client::new(http.clone(), cx); - let user_store = cx.build_model(|cx| UserStore::new(client.clone(), cx)); + let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); let settings = SettingsStore::test(cx); cx.set_global(settings); theme::init(theme::LoadThemes::JustBase, cx); diff --git a/crates/collab_ui2/src/collab_panel.rs b/crates/collab_ui2/src/collab_panel.rs index 1fb2f94f0a..5aecc37541 100644 --- a/crates/collab_ui2/src/collab_panel.rs +++ b/crates/collab_ui2/src/collab_panel.rs @@ -177,8 +177,8 @@ enum ListEntry { impl CollabPanel { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext) -> View { - cx.build_view(|cx| { - let filter_editor = cx.build_view(|cx| { + cx.new_view(|cx| { + let filter_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text("Filter...", cx); editor @@ -201,7 +201,7 @@ impl CollabPanel { }) .detach(); - let channel_name_editor = cx.build_view(|cx| Editor::single_line(cx)); + let channel_name_editor = cx.new_view(|cx| Editor::single_line(cx)); cx.subscribe(&channel_name_editor, |this: &mut Self, _, event, cx| { if let editor::EditorEvent::Blurred = event { @@ -2118,7 +2118,7 @@ impl CollabPanel { .flex() .w_full() .on_drag(channel.clone(), move |channel, cx| { - cx.build_view(|_| DraggedChannelView { + cx.new_view(|_| DraggedChannelView { channel: channel.clone(), width, }) diff --git a/crates/collab_ui2/src/collab_panel/channel_modal.rs b/crates/collab_ui2/src/collab_panel/channel_modal.rs index 30fbe6cd55..2c659a55d0 100644 --- a/crates/collab_ui2/src/collab_panel/channel_modal.rs +++ b/crates/collab_ui2/src/collab_panel/channel_modal.rs @@ -42,7 +42,7 @@ impl ChannelModal { ) -> Self { cx.observe(&channel_store, |_, _, cx| cx.notify()).detach(); let channel_modal = cx.view().downgrade(); - let picker = cx.build_view(|cx| { + let picker = cx.new_view(|cx| { Picker::new( ChannelModalDelegate { channel_modal, diff --git a/crates/collab_ui2/src/collab_panel/contact_finder.rs b/crates/collab_ui2/src/collab_panel/contact_finder.rs index da91feafe1..cb916ba961 100644 --- a/crates/collab_ui2/src/collab_panel/contact_finder.rs +++ b/crates/collab_ui2/src/collab_panel/contact_finder.rs @@ -22,7 +22,7 @@ impl ContactFinder { potential_contacts: Arc::from([]), selected_index: 0, }; - let picker = cx.build_view(|cx| Picker::new(delegate, cx).modal(false)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx).modal(false)); Self { picker } } diff --git a/crates/collab_ui2/src/collab_titlebar_item.rs b/crates/collab_ui2/src/collab_titlebar_item.rs index 4d2362c419..8d6f495ad5 100644 --- a/crates/collab_ui2/src/collab_titlebar_item.rs +++ b/crates/collab_ui2/src/collab_titlebar_item.rs @@ -36,7 +36,7 @@ actions!( pub fn init(cx: &mut AppContext) { cx.observe_new_views(|workspace: &mut Workspace, cx| { - let titlebar_item = cx.build_view(|cx| CollabTitlebarItem::new(workspace, cx)); + let titlebar_item = cx.new_view(|cx| CollabTitlebarItem::new(workspace, cx)); workspace.set_titlebar_item(titlebar_item.into(), cx) }) .detach(); diff --git a/crates/collab_ui2/src/notification_panel.rs b/crates/collab_ui2/src/notification_panel.rs index f661318dc6..68df41697f 100644 --- a/crates/collab_ui2/src/notification_panel.rs +++ b/crates/collab_ui2/src/notification_panel.rs @@ -87,7 +87,7 @@ impl NotificationPanel { let user_store = workspace.app_state().user_store.clone(); let workspace_handle = workspace.weak_handle(); - cx.build_view(|cx: &mut ViewContext| { + cx.new_view(|cx: &mut ViewContext| { let mut status = client.status(); cx.spawn(|this, mut cx| async move { while let Some(_) = status.next().await { @@ -503,7 +503,7 @@ impl NotificationPanel { workspace.dismiss_notification::(0, cx); workspace.show_notification(0, cx, |cx| { let workspace = cx.view().downgrade(); - cx.build_view(|_| NotificationToast { + cx.new_view(|_| NotificationToast { notification_id, actor, text, diff --git a/crates/collab_ui2/src/notifications/incoming_call_notification.rs b/crates/collab_ui2/src/notifications/incoming_call_notification.rs index b7c7309414..dab33328cd 100644 --- a/crates/collab_ui2/src/notifications/incoming_call_notification.rs +++ b/crates/collab_ui2/src/notifications/incoming_call_notification.rs @@ -39,7 +39,7 @@ pub fn init(app_state: &Arc, cx: &mut AppContext) { let options = notification_window_options(screen, window_size); let window = cx .open_window(options, |cx| { - cx.build_view(|_| { + cx.new_view(|_| { IncomingCallNotification::new( incoming_call.clone(), app_state.clone(), diff --git a/crates/collab_ui2/src/notifications/project_shared_notification.rs b/crates/collab_ui2/src/notifications/project_shared_notification.rs index baeade6ee5..3be50515e8 100644 --- a/crates/collab_ui2/src/notifications/project_shared_notification.rs +++ b/crates/collab_ui2/src/notifications/project_shared_notification.rs @@ -27,7 +27,7 @@ pub fn init(app_state: &Arc, cx: &mut AppContext) { for screen in cx.displays() { let options = notification_window_options(screen, window_size); let window = cx.open_window(options, |cx| { - cx.build_view(|_| { + cx.new_view(|_| { ProjectSharedNotification::new( owner.clone(), *project_id, diff --git a/crates/command_palette2/src/command_palette.rs b/crates/command_palette2/src/command_palette.rs index 1a16af2b11..5d069967ba 100644 --- a/crates/command_palette2/src/command_palette.rs +++ b/crates/command_palette2/src/command_palette.rs @@ -69,7 +69,7 @@ impl CommandPalette { let delegate = CommandPaletteDelegate::new(cx.view().downgrade(), commands, previous_focus_handle); - let picker = cx.build_view(|cx| Picker::new(delegate, cx)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx)); Self { picker } } } @@ -394,7 +394,7 @@ mod tests { let project = Project::test(app_state.fs.clone(), [], cx).await; let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx)); - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_text("abc", cx); editor diff --git a/crates/copilot2/src/copilot2.rs b/crates/copilot2/src/copilot2.rs index 4fd05a9c08..a6395fb174 100644 --- a/crates/copilot2/src/copilot2.rs +++ b/crates/copilot2/src/copilot2.rs @@ -51,7 +51,7 @@ pub fn init( node_runtime: Arc, cx: &mut AppContext, ) { - let copilot = cx.build_model({ + let copilot = cx.new_model({ let node_runtime = node_runtime.clone(); move |cx| Copilot::start(new_server_id, http, node_runtime, cx) }); @@ -382,7 +382,7 @@ impl Copilot { LanguageServer::fake("copilot".into(), Default::default(), cx.to_async()); let http = util::http::FakeHttpClient::create(|_| async { unreachable!() }); let node_runtime = FakeNodeRuntime::new(); - let this = cx.build_model(|cx| Self { + let this = cx.new_model(|cx| Self { server_id: LanguageServerId(0), http: http.clone(), node_runtime, @@ -1034,7 +1034,7 @@ mod tests { async fn test_buffer_management(cx: &mut TestAppContext) { let (copilot, mut lsp) = Copilot::fake(cx); - let buffer_1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "Hello")); + let buffer_1 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "Hello")); let buffer_1_uri: lsp::Url = format!("buffer://{}", buffer_1.entity_id().as_u64()) .parse() .unwrap(); @@ -1052,7 +1052,7 @@ mod tests { } ); - let buffer_2 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "Goodbye")); + let buffer_2 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "Goodbye")); let buffer_2_uri: lsp::Url = format!("buffer://{}", buffer_2.entity_id().as_u64()) .parse() .unwrap(); diff --git a/crates/copilot2/src/sign_in.rs b/crates/copilot2/src/sign_in.rs index cee049a706..cef87d63a1 100644 --- a/crates/copilot2/src/sign_in.rs +++ b/crates/copilot2/src/sign_in.rs @@ -71,7 +71,7 @@ fn create_copilot_auth_window( display_id: None, }; let window = cx.open_window(window_options, |cx| { - cx.build_view(|_| CopilotCodeVerification::new(status.clone())) + cx.new_view(|_| CopilotCodeVerification::new(status.clone())) }); window } diff --git a/crates/diagnostics2/src/diagnostics.rs b/crates/diagnostics2/src/diagnostics.rs index c7ed7f84fb..bd262e8bbf 100644 --- a/crates/diagnostics2/src/diagnostics.rs +++ b/crates/diagnostics2/src/diagnostics.rs @@ -151,8 +151,8 @@ impl ProjectDiagnosticsEditor { let focus_in_subscription = cx.on_focus_in(&focus_handle, |diagnostics, cx| diagnostics.focus_in(cx)); - let excerpts = cx.build_model(|cx| MultiBuffer::new(project_handle.read(cx).replica_id())); - let editor = cx.build_view(|cx| { + let excerpts = cx.new_model(|cx| MultiBuffer::new(project_handle.read(cx).replica_id())); + let editor = cx.new_view(|cx| { let mut editor = Editor::for_multibuffer(excerpts.clone(), Some(project_handle.clone()), cx); editor.set_vertical_scroll_margin(5, cx); @@ -194,7 +194,7 @@ impl ProjectDiagnosticsEditor { workspace.activate_item(&existing, cx); } else { let workspace_handle = cx.view().downgrade(); - let diagnostics = cx.build_view(|cx| { + let diagnostics = cx.new_view(|cx| { ProjectDiagnosticsEditor::new(workspace.project().clone(), workspace_handle, cx) }); workspace.add_item(Box::new(diagnostics), cx); @@ -705,7 +705,7 @@ impl Item for ProjectDiagnosticsEditor { where Self: Sized, { - Some(cx.build_view(|cx| { + Some(cx.new_view(|cx| { ProjectDiagnosticsEditor::new(self.project.clone(), self.workspace.clone(), cx) })) } @@ -778,7 +778,7 @@ impl Item for ProjectDiagnosticsEditor { _item_id: workspace::ItemId, cx: &mut ViewContext, ) -> Task>> { - Task::ready(Ok(cx.build_view(|cx| Self::new(project, workspace, cx)))) + Task::ready(Ok(cx.new_view(|cx| Self::new(project, workspace, cx)))) } } diff --git a/crates/editor2/src/display_map.rs b/crates/editor2/src/display_map.rs index 6298c80d2f..74daf8ba89 100644 --- a/crates/editor2/src/display_map.rs +++ b/crates/editor2/src/display_map.rs @@ -1046,7 +1046,7 @@ pub mod tests { } }); - let map = cx.build_model(|cx| { + let map = cx.new_model(|cx| { DisplayMap::new( buffer.clone(), font("Helvetica"), @@ -1286,7 +1286,7 @@ pub mod tests { let text = "one two three four five\nsix seven eight"; let buffer = MultiBuffer::build_simple(text, cx); - let map = cx.build_model(|cx| { + let map = cx.new_model(|cx| { DisplayMap::new( buffer.clone(), font("Helvetica"), @@ -1393,7 +1393,7 @@ pub mod tests { let buffer = MultiBuffer::build_simple(&text, cx); let font_size = px(14.0); - let map = cx.build_model(|cx| { + let map = cx.new_model(|cx| { DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx) }); @@ -1464,17 +1464,16 @@ pub mod tests { cx.update(|cx| init_test(cx, |s| s.defaults.tab_size = Some(2.try_into().unwrap()))); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) }); cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let font_size = px(14.0); - let map = cx.build_model(|cx| { - DisplayMap::new(buffer, font("Helvetica"), font_size, None, 1, 1, cx) - }); + let map = cx + .new_model(|cx| DisplayMap::new(buffer, font("Helvetica"), font_size, None, 1, 1, cx)); assert_eq!( cx.update(|cx| syntax_chunks(0..5, &map, &theme, cx)), vec![ @@ -1551,15 +1550,15 @@ pub mod tests { cx.update(|cx| init_test(cx, |_| {})); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) }); cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let font_size = px(16.0); - let map = cx.build_model(|cx| { + let map = cx.new_model(|cx| { DisplayMap::new(buffer, font("Courier"), font_size, Some(px(40.0)), 1, 1, cx) }); assert_eq!( @@ -1618,17 +1617,17 @@ pub mod tests { let (text, highlighted_ranges) = marked_text_ranges(r#"constˇ «a»: B = "c «d»""#, false); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) }); cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let buffer_snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx)); let font_size = px(16.0); - let map = cx - .build_model(|cx| DisplayMap::new(buffer, font("Courier"), font_size, None, 1, 1, cx)); + let map = + cx.new_model(|cx| DisplayMap::new(buffer, font("Courier"), font_size, None, 1, 1, cx)); enum MyType {} @@ -1742,7 +1741,7 @@ pub mod tests { let buffer = MultiBuffer::build_simple(text, cx); let font_size = px(14.0); - let map = cx.build_model(|cx| { + let map = cx.new_model(|cx| { DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx) }); let map = map.update(cx, |map, cx| map.snapshot(cx)); @@ -1796,7 +1795,7 @@ pub mod tests { let buffer = MultiBuffer::build_simple("aaa\n\t\tbbb", cx); let font_size = px(14.0); - let map = cx.build_model(|cx| { + let map = cx.new_model(|cx| { DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx) }); assert_eq!( diff --git a/crates/editor2/src/display_map/wrap_map.rs b/crates/editor2/src/display_map/wrap_map.rs index 4ef6a13c69..05aa381627 100644 --- a/crates/editor2/src/display_map/wrap_map.rs +++ b/crates/editor2/src/display_map/wrap_map.rs @@ -74,7 +74,7 @@ impl WrapMap { wrap_width: Option, cx: &mut AppContext, ) -> (Model, WrapSnapshot) { - let handle = cx.build_model(|cx| { + let handle = cx.new_model(|cx| { let mut this = Self { font_with_size: (font, font_size), wrap_width: None, diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 7ddcbce273..dac291b468 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -1637,20 +1637,20 @@ impl InlayHintRefreshReason { impl Editor { pub fn single_line(cx: &mut ViewContext) -> Self { - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); Self::new(EditorMode::SingleLine, buffer, None, cx) } pub fn multi_line(cx: &mut ViewContext) -> Self { - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); Self::new(EditorMode::Full, buffer, None, cx) } pub fn auto_height(max_lines: usize, cx: &mut ViewContext) -> Self { - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); Self::new(EditorMode::AutoHeight { max_lines }, buffer, None, cx) } @@ -1659,7 +1659,7 @@ impl Editor { project: Option>, cx: &mut ViewContext, ) -> Self { - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); Self::new(EditorMode::Full, buffer, project, cx) } @@ -1693,13 +1693,13 @@ impl Editor { ) -> Self { let style = cx.text_style(); let font_size = style.font_size.to_pixels(cx.rem_size()); - let display_map = cx.build_model(|cx| { + let display_map = cx.new_model(|cx| { DisplayMap::new(buffer.clone(), style.font(), font_size, None, 2, 1, cx) }); let selections = SelectionsCollection::new(display_map.clone(), buffer.clone()); - let blink_manager = cx.build_model(|cx| BlinkManager::new(CURSOR_BLINK_INTERVAL, cx)); + let blink_manager = cx.new_model(|cx| BlinkManager::new(CURSOR_BLINK_INTERVAL, cx)); let soft_wrap_mode_override = (mode == EditorMode::SingleLine).then(|| language_settings::SoftWrap::None); @@ -1881,7 +1881,7 @@ impl Editor { .log_err() { workspace.add_item( - Box::new(cx.build_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))), + Box::new(cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))), cx, ); } @@ -1901,7 +1901,7 @@ impl Editor { { workspace.split_item( action.0, - Box::new(cx.build_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))), + Box::new(cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))), cx, ); } @@ -3787,7 +3787,7 @@ impl Editor { } let mut ranges_to_highlight = Vec::new(); - let excerpt_buffer = cx.build_model(|cx| { + let excerpt_buffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(replica_id).with_title(title); for (buffer_handle, transaction) in &entries { let buffer = buffer_handle.read(cx); @@ -3809,7 +3809,7 @@ impl Editor { workspace.update(&mut cx, |workspace, cx| { let project = workspace.project().clone(); let editor = - cx.build_view(|cx| Editor::for_multibuffer(excerpt_buffer, Some(project), cx)); + cx.new_view(|cx| Editor::for_multibuffer(excerpt_buffer, Some(project), cx)); workspace.add_item(Box::new(editor.clone()), cx); editor.update(cx, |editor, cx| { editor.highlight_background::( @@ -7494,7 +7494,7 @@ impl Editor { let mut locations = locations.into_iter().peekable(); let mut ranges_to_highlight = Vec::new(); - let excerpt_buffer = cx.build_model(|cx| { + let excerpt_buffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(replica_id); while let Some(location) = locations.next() { let buffer = location.buffer.read(cx); @@ -7523,7 +7523,7 @@ impl Editor { multibuffer.with_title(title) }); - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { Editor::for_multibuffer(excerpt_buffer, Some(workspace.project().clone()), cx) }); editor.update(cx, |editor, cx| { @@ -7608,7 +7608,7 @@ impl Editor { // Position the selection in the rename editor so that it matches the current selection. this.show_local_selections = false; - let rename_editor = cx.build_view(|cx| { + let rename_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.buffer.update(cx, |buffer, cx| { buffer.edit([(0..0, old_name.clone())], None, cx) diff --git a/crates/editor2/src/editor_tests.rs b/crates/editor2/src/editor_tests.rs index 563913bbe1..4d507e0d37 100644 --- a/crates/editor2/src/editor_tests.rs +++ b/crates/editor2/src/editor_tests.rs @@ -40,7 +40,7 @@ use workspace::{ fn test_edit_events(cx: &mut TestAppContext) { init_test(cx, |_| {}); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { let mut buffer = language::Buffer::new(0, cx.entity_id().as_u64(), "123456"); buffer.set_group_interval(Duration::from_secs(1)); buffer @@ -156,9 +156,9 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) { init_test(cx, |_| {}); let mut now = Instant::now(); - let buffer = cx.build_model(|cx| language::Buffer::new(0, cx.entity_id().as_u64(), "123456")); + let buffer = cx.new_model(|cx| language::Buffer::new(0, cx.entity_id().as_u64(), "123456")); let group_interval = buffer.update(cx, |buffer, _| buffer.transaction_group_interval()); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let editor = cx.add_window(|cx| build_editor(buffer.clone(), cx)); _ = editor.update(cx, |editor, cx| { @@ -226,14 +226,14 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) { fn test_ime_composition(cx: &mut TestAppContext) { init_test(cx, |_| {}); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { let mut buffer = language::Buffer::new(0, cx.entity_id().as_u64(), "abcde"); // Ensure automatic grouping doesn't occur. buffer.set_group_interval(Duration::ZERO); buffer }); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); cx.add_window(|cx| { let mut editor = build_editor(buffer.clone(), cx); @@ -504,9 +504,7 @@ fn test_clone(cx: &mut TestAppContext) { let cloned_editor = editor .update(cx, |editor, cx| { - cx.open_window(Default::default(), |cx| { - cx.build_view(|cx| editor.clone(cx)) - }) + cx.open_window(Default::default(), |cx| cx.new_view(|cx| editor.clone(cx))) }) .unwrap(); @@ -558,7 +556,7 @@ async fn test_navigation_history(cx: &mut TestAppContext) { .unwrap(); _ = workspace.update(cx, |_v, cx| { - cx.build_view(|cx| { + cx.new_view(|cx| { let buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx); let mut editor = build_editor(buffer.clone(), cx); let handle = cx.view(); @@ -2349,14 +2347,14 @@ fn test_indent_outdent_with_excerpts(cx: &mut TestAppContext) { None, )); - let toml_buffer = cx.build_model(|cx| { + let toml_buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), "a = 1\nb = 2\n").with_language(toml_language, cx) }); - let rust_buffer = cx.build_model(|cx| { + let rust_buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), "const c: usize = 3;\n") .with_language(rust_language, cx) }); - let multibuffer = cx.build_model(|cx| { + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( toml_buffer.clone(), @@ -3907,10 +3905,9 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) { "# .unindent(); - let buffer = cx.build_model(|cx| { - Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) - }); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx + .new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); view.condition::(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) @@ -4073,10 +4070,9 @@ async fn test_autoindent_selections(cx: &mut gpui::TestAppContext) { let text = "fn a() {}"; - let buffer = cx.build_model(|cx| { - Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) - }); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx + .new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); editor .condition::(cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx)) @@ -4638,10 +4634,9 @@ async fn test_surround_with_pair(cx: &mut gpui::TestAppContext) { "# .unindent(); - let buffer = cx.build_model(|cx| { - Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) - }); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx + .new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); view.condition::(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) .await; @@ -4788,10 +4783,9 @@ async fn test_delete_autoclose_pair(cx: &mut gpui::TestAppContext) { "# .unindent(); - let buffer = cx.build_model(|cx| { - Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) - }); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx + .new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); editor .condition::(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) @@ -5012,7 +5006,7 @@ async fn test_document_format_during_save(cx: &mut gpui::TestAppContext) { cx.executor().start_waiting(); let fake_server = fake_servers.next().await.unwrap(); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); _ = editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx)); assert!(cx.read(|cx| editor.is_dirty(cx))); @@ -5131,7 +5125,7 @@ async fn test_range_format_during_save(cx: &mut gpui::TestAppContext) { cx.executor().start_waiting(); let fake_server = fake_servers.next().await.unwrap(); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); _ = editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx)); assert!(cx.read(|cx| editor.is_dirty(cx))); @@ -5258,7 +5252,7 @@ async fn test_document_format_manual_trigger(cx: &mut gpui::TestAppContext) { cx.executor().start_waiting(); let fake_server = fake_servers.next().await.unwrap(); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); _ = editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx)); @@ -6023,9 +6017,8 @@ async fn test_toggle_block_comment(cx: &mut gpui::TestAppContext) { fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) { init_test(cx, |_| {}); - let buffer = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a'))); - let multibuffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a'))); + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( buffer.clone(), @@ -6108,8 +6101,8 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) { primary: None, } }); - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), initial_text)); - let multibuffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), initial_text)); + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts(buffer, excerpt_ranges, cx); multibuffer @@ -6166,10 +6159,9 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) { fn test_refresh_selections(cx: &mut TestAppContext) { init_test(cx, |_| {}); - let buffer = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a'))); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a'))); let mut excerpt1_id = None; - let multibuffer = cx.build_model(|cx| { + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); excerpt1_id = multibuffer .push_excerpts( @@ -6252,10 +6244,9 @@ fn test_refresh_selections(cx: &mut TestAppContext) { fn test_refresh_selections_while_selecting_with_mouse(cx: &mut TestAppContext) { init_test(cx, |_| {}); - let buffer = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a'))); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a'))); let mut excerpt1_id = None; - let multibuffer = cx.build_model(|cx| { + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); excerpt1_id = multibuffer .push_excerpts( @@ -6348,10 +6339,9 @@ async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) { "{{} }\n", // ); - let buffer = cx.build_model(|cx| { - Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) - }); - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx + .new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); view.condition::(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) .await; @@ -6479,7 +6469,7 @@ async fn test_following(cx: &mut gpui::TestAppContext) { let buffer = project .create_buffer(&sample_text(16, 8, 'a'), None, cx) .unwrap(); - cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)) + cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)) }); let leader = cx.add_window(|cx| build_editor(buffer.clone(), cx)); let follower = cx.update(|cx| { @@ -6491,7 +6481,7 @@ async fn test_following(cx: &mut gpui::TestAppContext) { )), ..Default::default() }, - |cx| cx.build_view(|cx| build_editor(buffer.clone(), cx)), + |cx| cx.new_view(|cx| build_editor(buffer.clone(), cx)), ) }); @@ -6646,8 +6636,8 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) { let cx = &mut VisualTestContext::from_window(*workspace.deref(), cx); let leader = pane.update(cx, |_, cx| { - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); - cx.build_view(|cx| build_editor(multibuffer.clone(), cx)) + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); + cx.new_view(|cx| build_editor(multibuffer.clone(), cx)) }); // Start following the editor when it has no excerpts. @@ -7432,9 +7422,9 @@ async fn test_copilot_multibuffer(executor: BackgroundExecutor, cx: &mut gpui::T let (copilot, copilot_lsp) = Copilot::fake(cx); _ = cx.update(|cx| cx.set_global(copilot)); - let buffer_1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "a = 1\nb = 2\n")); - let buffer_2 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "c = 3\nd = 4\n")); - let multibuffer = cx.build_model(|cx| { + let buffer_1 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "a = 1\nb = 2\n")); + let buffer_2 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "c = 3\nd = 4\n")); + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( buffer_1.clone(), @@ -7561,7 +7551,7 @@ async fn test_copilot_disabled_globs(executor: BackgroundExecutor, cx: &mut gpui .await .unwrap(); - let multibuffer = cx.build_model(|cx| { + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( private_buffer.clone(), @@ -8091,7 +8081,7 @@ async fn test_document_format_with_prettier(cx: &mut gpui::TestAppContext) { .unwrap(); let buffer_text = "one\ntwo\nthree\n"; - let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); _ = editor.update(cx, |editor, cx| editor.set_text(buffer_text, cx)); diff --git a/crates/editor2/src/git.rs b/crates/editor2/src/git.rs index f798ab9fb6..e1715aa3b2 100644 --- a/crates/editor2/src/git.rs +++ b/crates/editor2/src/git.rs @@ -182,7 +182,7 @@ mod tests { cx.background_executor.run_until_parked(); - let multibuffer = cx.build_model(|cx| { + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( buffer_1.clone(), diff --git a/crates/editor2/src/inlay_hint_cache.rs b/crates/editor2/src/inlay_hint_cache.rs index aac9e54cf3..d7dfa01b21 100644 --- a/crates/editor2/src/inlay_hint_cache.rs +++ b/crates/editor2/src/inlay_hint_cache.rs @@ -2458,7 +2458,7 @@ pub mod tests { }) .await .unwrap(); - let multibuffer = cx.build_model(|cx| { + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( buffer_1.clone(), @@ -2798,7 +2798,7 @@ pub mod tests { }) .await .unwrap(); - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let (buffer_1_excerpts, buffer_2_excerpts) = multibuffer.update(cx, |multibuffer, cx| { let buffer_1_excerpts = multibuffer.push_excerpts( buffer_1.clone(), diff --git a/crates/editor2/src/items.rs b/crates/editor2/src/items.rs index f1969ff93c..f72915492f 100644 --- a/crates/editor2/src/items.rs +++ b/crates/editor2/src/items.rs @@ -96,7 +96,7 @@ impl FollowableItem for Editor { editor } else { pane.update(&mut cx, |_, cx| { - let multibuffer = cx.build_model(|cx| { + let multibuffer = cx.new_model(|cx| { let mut multibuffer; if state.singleton && buffers.len() == 1 { multibuffer = MultiBuffer::singleton(buffers.pop().unwrap(), cx) @@ -129,7 +129,7 @@ impl FollowableItem for Editor { multibuffer }); - cx.build_view(|cx| { + cx.new_view(|cx| { let mut editor = Editor::for_multibuffer(multibuffer, Some(project.clone()), cx); editor.remote_id = Some(remote_id); @@ -632,7 +632,7 @@ impl Item for Editor { where Self: Sized, { - Some(cx.build_view(|cx| self.clone(cx))) + Some(cx.new_view(|cx| self.clone(cx))) } fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext) { @@ -911,7 +911,7 @@ impl Item for Editor { .downcast::() .map_err(|_| anyhow!("Project item at stored path was not a buffer"))?; Ok(pane.update(&mut cx, |_, cx| { - cx.build_view(|cx| { + cx.new_view(|cx| { let mut editor = Editor::for_buffer(buffer, Some(project), cx); editor.read_scroll_position_from_db(item_id, workspace_id, cx); diff --git a/crates/editor2/src/movement.rs b/crates/editor2/src/movement.rs index 8190586968..cfccec253f 100644 --- a/crates/editor2/src/movement.rs +++ b/crates/editor2/src/movement.rs @@ -576,7 +576,7 @@ mod tests { let buffer = MultiBuffer::build_simple(input_text, cx); let buffer_snapshot = buffer.read(cx).snapshot(cx); let display_map = - cx.build_model(|cx| DisplayMap::new(buffer, font, font_size, None, 1, 1, cx)); + cx.new_model(|cx| DisplayMap::new(buffer, font, font_size, None, 1, 1, cx)); // add all kinds of inlays between two word boundaries: we should be able to cross them all, when looking for another boundary let mut id = 0; @@ -763,9 +763,9 @@ mod tests { let font = font("Helvetica"); - let buffer = cx - .build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abc\ndefg\nhijkl\nmn")); - let multibuffer = cx.build_model(|cx| { + let buffer = + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abc\ndefg\nhijkl\nmn")); + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( buffer.clone(), @@ -784,7 +784,7 @@ mod tests { multibuffer }); let display_map = - cx.build_model(|cx| DisplayMap::new(multibuffer, font, px(14.0), None, 2, 2, cx)); + cx.new_model(|cx| DisplayMap::new(multibuffer, font, px(14.0), None, 2, 2, cx)); let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx)); assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\nhijkl\nmn"); diff --git a/crates/editor2/src/rust_analyzer_ext.rs b/crates/editor2/src/rust_analyzer_ext.rs index a4e68ff837..067d09d9ce 100644 --- a/crates/editor2/src/rust_analyzer_ext.rs +++ b/crates/editor2/src/rust_analyzer_ext.rs @@ -102,11 +102,11 @@ pub fn expand_macro_recursively( project.create_buffer(¯o_expansion.expansion, Some(rust_language), cx) })??; workspace.update(&mut cx, |workspace, cx| { - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { MultiBuffer::singleton(buffer, cx).with_title(macro_expansion.name) }); workspace.add_item( - Box::new(cx.build_view(|cx| Editor::for_multibuffer(buffer, Some(project), cx))), + Box::new(cx.new_view(|cx| Editor::for_multibuffer(buffer, Some(project), cx))), cx, ); }) diff --git a/crates/editor2/src/test.rs b/crates/editor2/src/test.rs index 4f6e157e4e..4ce539ad79 100644 --- a/crates/editor2/src/test.rs +++ b/crates/editor2/src/test.rs @@ -30,7 +30,7 @@ pub fn marked_display_snapshot( let font_size: Pixels = 14usize.into(); let buffer = MultiBuffer::build_simple(&unmarked_text, cx); - let display_map = cx.build_model(|cx| DisplayMap::new(buffer, font, font_size, None, 1, 1, cx)); + let display_map = cx.new_model(|cx| DisplayMap::new(buffer, font, font_size, None, 1, 1, cx)); let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx)); let markers = markers .into_iter() diff --git a/crates/feedback2/src/feedback_modal.rs b/crates/feedback2/src/feedback_modal.rs index 1f701df8ed..c8bb7b8667 100644 --- a/crates/feedback2/src/feedback_modal.rs +++ b/crates/feedback2/src/feedback_modal.rs @@ -154,7 +154,7 @@ impl FeedbackModal { buffer: Model, cx: &mut ViewContext, ) -> Self { - let email_address_editor = cx.build_view(|cx| { + let email_address_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text("Email address (optional)", cx); @@ -169,7 +169,7 @@ impl FeedbackModal { let placeholder_text = "You can use markdown to organize your feedback with code and links."; - let feedback_editor = cx.build_view(|cx| { + let feedback_editor = cx.new_view(|cx| { let mut editor = Editor::for_buffer(buffer, Some(project.clone()), cx); editor.set_placeholder_text(placeholder_text, cx); // editor.set_show_gutter(false, cx); diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rs index 8999a41dde..88ebd6331c 100644 --- a/crates/file_finder2/src/file_finder.rs +++ b/crates/file_finder2/src/file_finder.rs @@ -106,7 +106,7 @@ impl FileFinder { fn new(delegate: FileFinderDelegate, cx: &mut ViewContext) -> Self { Self { - picker: cx.build_view(|cx| Picker::new(delegate, cx)), + picker: cx.new_view(|cx| Picker::new(delegate, cx)), } } } diff --git a/crates/go_to_line2/src/go_to_line.rs b/crates/go_to_line2/src/go_to_line.rs index 66a454f5f2..4845c93068 100644 --- a/crates/go_to_line2/src/go_to_line.rs +++ b/crates/go_to_line2/src/go_to_line.rs @@ -49,7 +49,7 @@ impl GoToLine { } pub fn new(active_editor: View, cx: &mut ViewContext) -> Self { - let line_editor = cx.build_view(|cx| Editor::single_line(cx)); + let line_editor = cx.new_view(|cx| Editor::single_line(cx)); let line_editor_change = cx.subscribe(&line_editor, Self::on_line_editor_event); let editor = active_editor.read(cx); diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 8748a60249..fd03d886b8 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -1105,7 +1105,7 @@ impl Context for AppContext { /// Build an entity that is owned by the application. The given function will be invoked with /// a `ModelContext` and must return an object representing the entity. A `Model` will be returned /// which can be used to access the entity in a context. - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, ) -> Model { diff --git a/crates/gpui2/src/app/async_context.rs b/crates/gpui2/src/app/async_context.rs index 92ccc118f1..d60393ccc8 100644 --- a/crates/gpui2/src/app/async_context.rs +++ b/crates/gpui2/src/app/async_context.rs @@ -17,7 +17,7 @@ pub struct AsyncAppContext { impl Context for AsyncAppContext { type Result = Result; - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, ) -> Self::Result> @@ -29,7 +29,7 @@ impl Context for AsyncAppContext { .upgrade() .ok_or_else(|| anyhow!("app was released"))?; let mut app = app.borrow_mut(); - Ok(app.build_model(build_model)) + Ok(app.new_model(build_model)) } fn update_model( @@ -230,15 +230,14 @@ impl AsyncWindowContext { impl Context for AsyncWindowContext { type Result = Result; - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, ) -> Result> where T: 'static, { - self.window - .update(self, |_, cx| cx.build_model(build_model)) + self.window.update(self, |_, cx| cx.new_model(build_model)) } fn update_model( @@ -281,7 +280,7 @@ impl Context for AsyncWindowContext { } impl VisualContext for AsyncWindowContext { - fn build_view( + fn new_view( &mut self, build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V, ) -> Self::Result> @@ -289,7 +288,7 @@ impl VisualContext for AsyncWindowContext { V: 'static + Render, { self.window - .update(self, |_, cx| cx.build_view(build_view_state)) + .update(self, |_, cx| cx.new_view(build_view_state)) } fn update_view( diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs index 26feb2fd1b..1aee20b598 100644 --- a/crates/gpui2/src/app/model_context.rs +++ b/crates/gpui2/src/app/model_context.rs @@ -215,11 +215,11 @@ impl<'a, T> ModelContext<'a, T> { impl<'a, T> Context for ModelContext<'a, T> { type Result = U; - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, U>) -> U, ) -> Model { - self.app.build_model(build_model) + self.app.new_model(build_model) } fn update_model( diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rs index 55d493b87c..e5bb6e73e1 100644 --- a/crates/gpui2/src/app/test_context.rs +++ b/crates/gpui2/src/app/test_context.rs @@ -23,7 +23,7 @@ pub struct TestAppContext { impl Context for TestAppContext { type Result = T; - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, ) -> Self::Result> @@ -31,7 +31,7 @@ impl Context for TestAppContext { T: 'static, { let mut app = self.app.borrow_mut(); - app.build_model(build_model) + app.new_model(build_model) } fn update_model( @@ -134,15 +134,13 @@ impl TestAppContext { V: 'static + Render, { let mut cx = self.app.borrow_mut(); - cx.open_window(WindowOptions::default(), |cx| cx.build_view(build_window)) + cx.open_window(WindowOptions::default(), |cx| cx.new_view(build_window)) } pub fn add_empty_window(&mut self) -> AnyWindowHandle { let mut cx = self.app.borrow_mut(); - cx.open_window(WindowOptions::default(), |cx| { - cx.build_view(|_| EmptyView {}) - }) - .any_handle + cx.open_window(WindowOptions::default(), |cx| cx.new_view(|_| EmptyView {})) + .any_handle } pub fn add_window_view(&mut self, build_window: F) -> (View, &mut VisualTestContext) @@ -151,7 +149,7 @@ impl TestAppContext { V: 'static + Render, { let mut cx = self.app.borrow_mut(); - let window = cx.open_window(WindowOptions::default(), |cx| cx.build_view(build_window)); + let window = cx.open_window(WindowOptions::default(), |cx| cx.new_view(build_window)); drop(cx); let view = window.root_view(self).unwrap(); let cx = Box::new(VisualTestContext::from_window(*window.deref(), self)); @@ -617,11 +615,11 @@ impl<'a> VisualTestContext<'a> { impl<'a> Context for VisualTestContext<'a> { type Result = ::Result; - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, ) -> Self::Result> { - self.cx.build_model(build_model) + self.cx.new_model(build_model) } fn update_model( @@ -666,7 +664,7 @@ impl<'a> Context for VisualTestContext<'a> { } impl<'a> VisualContext for VisualTestContext<'a> { - fn build_view( + fn new_view( &mut self, build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V, ) -> Self::Result> @@ -674,7 +672,7 @@ impl<'a> VisualContext for VisualTestContext<'a> { V: 'static + Render, { self.window - .update(self.cx, |_, cx| cx.build_view(build_view)) + .update(self.cx, |_, cx| cx.new_view(build_view)) .unwrap() } @@ -726,7 +724,7 @@ impl AnyWindowHandle { cx: &mut TestAppContext, build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V, ) -> View { - self.update(cx, |_, cx| cx.build_view(build_view)).unwrap() + self.update(cx, |_, cx| cx.new_view(build_view)).unwrap() } } diff --git a/crates/gpui2/src/gpui2.rs b/crates/gpui2/src/gpui2.rs index 6af274ef5d..d595771e50 100644 --- a/crates/gpui2/src/gpui2.rs +++ b/crates/gpui2/src/gpui2.rs @@ -85,7 +85,7 @@ use taffy::TaffyLayoutEngine; pub trait Context { type Result; - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, ) -> Self::Result>; @@ -120,7 +120,7 @@ pub trait Context { } pub trait VisualContext: Context { - fn build_view( + fn new_view( &mut self, build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V, ) -> Self::Result> diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 4f4c163077..263b5658cd 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -327,7 +327,7 @@ mod test { fn test_on_events(cx: &mut TestAppContext) { let window = cx.update(|cx| { cx.open_window(Default::default(), |cx| { - cx.build_view(|cx| TestView { + cx.new_view(|cx| TestView { saw_key_down: false, saw_action: false, focus_handle: cx.focus_handle(), diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index c20e2f7b94..9fdcd87139 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -1463,7 +1463,7 @@ impl<'a> WindowContext<'a> { if self.active_drag.is_none() { self.active_drag = Some(AnyDrag { value: Box::new(files.clone()), - view: self.build_view(|_| files).into(), + view: self.new_view(|_| files).into(), cursor_offset: position, }); } @@ -1842,10 +1842,7 @@ impl<'a> WindowContext<'a> { impl Context for WindowContext<'_> { type Result = T; - fn build_model( - &mut self, - build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, - ) -> Model + fn new_model(&mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T) -> Model where T: 'static, { @@ -1916,7 +1913,7 @@ impl Context for WindowContext<'_> { } impl VisualContext for WindowContext<'_> { - fn build_view( + fn new_view( &mut self, build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V, ) -> Self::Result> @@ -1962,7 +1959,7 @@ impl VisualContext for WindowContext<'_> { where V: 'static + Render, { - let view = self.build_view(build_view); + let view = self.new_view(build_view); self.window.root_view = Some(view.clone().into()); self.notify(); view @@ -2728,11 +2725,11 @@ impl<'a, V: 'static> ViewContext<'a, V> { impl Context for ViewContext<'_, V> { type Result = U; - fn build_model( + fn new_model( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, ) -> Model { - self.window_cx.build_model(build_model) + self.window_cx.new_model(build_model) } fn update_model( @@ -2774,11 +2771,11 @@ impl Context for ViewContext<'_, V> { } impl VisualContext for ViewContext<'_, V> { - fn build_view( + fn new_view( &mut self, build_view_state: impl FnOnce(&mut ViewContext<'_, W>) -> W, ) -> Self::Result> { - self.window_cx.build_view(build_view_state) + self.window_cx.new_view(build_view_state) } fn update_view( diff --git a/crates/language2/src/buffer_tests.rs b/crates/language2/src/buffer_tests.rs index ba26e7fc55..af959b13e5 100644 --- a/crates/language2/src/buffer_tests.rs +++ b/crates/language2/src/buffer_tests.rs @@ -42,7 +42,7 @@ fn init_logger() { fn test_line_endings(cx: &mut gpui::AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "one\r\ntwo\rthree") .with_language(Arc::new(rust_lang()), cx); assert_eq!(buffer.text(), "one\ntwo\nthree"); @@ -138,8 +138,8 @@ fn test_edit_events(cx: &mut gpui::AppContext) { let buffer_1_events = Arc::new(Mutex::new(Vec::new())); let buffer_2_events = Arc::new(Mutex::new(Vec::new())); - let buffer1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcdef")); - let buffer2 = cx.build_model(|cx| Buffer::new(1, cx.entity_id().as_u64(), "abcdef")); + let buffer1 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcdef")); + let buffer2 = cx.new_model(|cx| Buffer::new(1, cx.entity_id().as_u64(), "abcdef")); let buffer1_ops = Arc::new(Mutex::new(Vec::new())); buffer1.update(cx, { let buffer1_ops = buffer1_ops.clone(); @@ -218,7 +218,7 @@ fn test_edit_events(cx: &mut gpui::AppContext) { #[gpui::test] async fn test_apply_diff(cx: &mut TestAppContext) { let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n"; - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); let anchor = buffer.update(cx, |buffer, _| buffer.anchor_before(Point::new(3, 3))); let text = "a\nccc\ndddd\nffffff\n"; @@ -250,7 +250,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) { ] .join("\n"); - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); // Spawn a task to format the buffer's whitespace. // Pause so that the foratting task starts running. @@ -314,7 +314,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) { #[gpui::test] async fn test_reparse(cx: &mut gpui::TestAppContext) { let text = "fn a() {}"; - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx) }); @@ -442,7 +442,7 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) { #[gpui::test] async fn test_resetting_language(cx: &mut gpui::TestAppContext) { - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "{}").with_language(Arc::new(rust_lang()), cx); buffer.set_sync_parse_timeout(Duration::ZERO); @@ -492,7 +492,7 @@ async fn test_outline(cx: &mut gpui::TestAppContext) { "# .unindent(); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx) }); let outline = buffer @@ -578,7 +578,7 @@ async fn test_outline_nodes_with_newlines(cx: &mut gpui::TestAppContext) { "# .unindent(); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx) }); let outline = buffer @@ -616,7 +616,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) { "# .unindent(); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(language), cx) }); let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot()); @@ -660,7 +660,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) { "# .unindent(); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx) }); let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot()); @@ -881,7 +881,7 @@ fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: & #[gpui::test] fn test_range_for_syntax_ancestor(cx: &mut AppContext) { - cx.build_model(|cx| { + cx.new_model(|cx| { let text = "fn a() { b(|c| {}) }"; let buffer = Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); @@ -922,7 +922,7 @@ fn test_range_for_syntax_ancestor(cx: &mut AppContext) { fn test_autoindent_with_soft_tabs(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = "fn a() {}"; let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); @@ -965,7 +965,7 @@ fn test_autoindent_with_hard_tabs(cx: &mut AppContext) { settings.defaults.hard_tabs = Some(true); }); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = "fn a() {}"; let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); @@ -1006,7 +1006,7 @@ fn test_autoindent_with_hard_tabs(cx: &mut AppContext) { fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let entity_id = cx.entity_id(); let mut buffer = Buffer::new( 0, @@ -1080,7 +1080,7 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppC buffer }); - cx.build_model(|cx| { + cx.new_model(|cx| { eprintln!("second buffer: {:?}", cx.entity_id()); let mut buffer = Buffer::new( @@ -1147,7 +1147,7 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppC fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let mut buffer = Buffer::new( 0, cx.entity_id().as_u64(), @@ -1209,7 +1209,7 @@ fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut Ap fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let mut buffer = Buffer::new( 0, cx.entity_id().as_u64(), @@ -1266,7 +1266,7 @@ fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut AppContext) { fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = "a\nb"; let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); @@ -1284,7 +1284,7 @@ fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut AppContext) { fn test_autoindent_multi_line_insertion(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = " const a: usize = 1; fn b() { @@ -1326,7 +1326,7 @@ fn test_autoindent_multi_line_insertion(cx: &mut AppContext) { fn test_autoindent_block_mode(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = r#" fn a() { b(); @@ -1410,7 +1410,7 @@ fn test_autoindent_block_mode(cx: &mut AppContext) { fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = r#" fn a() { if b() { @@ -1490,7 +1490,7 @@ fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut AppContex fn test_autoindent_language_without_indents_query(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = " * one - a @@ -1559,7 +1559,7 @@ fn test_autoindent_with_injected_languages(cx: &mut AppContext) { language_registry.add(html_language.clone()); language_registry.add(javascript_language.clone()); - cx.build_model(|cx| { + cx.new_model(|cx| { let (text, ranges) = marked_text_ranges( &"
ˇ @@ -1610,7 +1610,7 @@ fn test_autoindent_query_with_outdent_captures(cx: &mut AppContext) { settings.defaults.tab_size = Some(2.try_into().unwrap()); }); - cx.build_model(|cx| { + cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "").with_language(Arc::new(ruby_lang()), cx); @@ -1653,7 +1653,7 @@ fn test_autoindent_query_with_outdent_captures(cx: &mut AppContext) { fn test_language_scope_at_with_javascript(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let language = Language::new( LanguageConfig { name: "JavaScript".into(), @@ -1786,7 +1786,7 @@ fn test_language_scope_at_with_javascript(cx: &mut AppContext) { fn test_language_scope_at_with_rust(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let language = Language::new( LanguageConfig { name: "Rust".into(), @@ -1854,7 +1854,7 @@ fn test_language_scope_at_with_rust(cx: &mut AppContext) { fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) { init_settings(cx, |_| {}); - cx.build_model(|cx| { + cx.new_model(|cx| { let text = r#"
    <% people.each do |person| %> @@ -1902,7 +1902,7 @@ fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) { fn test_serialization(cx: &mut gpui::AppContext) { let mut now = Instant::now(); - let buffer1 = cx.build_model(|cx| { + let buffer1 = cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "abc"); buffer.edit([(3..3, "D")], None, cx); @@ -1925,7 +1925,7 @@ fn test_serialization(cx: &mut gpui::AppContext) { let ops = cx .background_executor() .block(buffer1.read(cx).serialize_ops(None, cx)); - let buffer2 = cx.build_model(|cx| { + let buffer2 = cx.new_model(|cx| { let mut buffer = Buffer::from_proto(1, state, None).unwrap(); buffer .apply_ops( @@ -1959,10 +1959,10 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) { let mut buffers = Vec::new(); let network = Arc::new(Mutex::new(Network::new(rng.clone()))); let base_buffer = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), base_text.as_str())); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), base_text.as_str())); for i in 0..rng.gen_range(min_peers..=max_peers) { - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { let state = base_buffer.read(cx).to_proto(); let ops = cx .background_executor() @@ -2082,7 +2082,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) { new_replica_id, replica_id ); - new_buffer = Some(cx.build_model(|cx| { + new_buffer = Some(cx.new_model(|cx| { let mut new_buffer = Buffer::from_proto(new_replica_id, old_buffer_state, None).unwrap(); new_buffer @@ -2460,7 +2460,7 @@ fn assert_bracket_pairs( cx: &mut AppContext, ) { let (expected_text, selection_ranges) = marked_text_ranges(selection_text, false); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(0, cx.entity_id().as_u64(), expected_text.clone()) .with_language(Arc::new(language), cx) }); diff --git a/crates/language_selector2/src/language_selector.rs b/crates/language_selector2/src/language_selector.rs index 7c0e5f9467..8343cef03f 100644 --- a/crates/language_selector2/src/language_selector.rs +++ b/crates/language_selector2/src/language_selector.rs @@ -61,7 +61,7 @@ impl LanguageSelector { language_registry, ); - let picker = cx.build_view(|cx| Picker::new(delegate, cx)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx)); Self { picker } } } diff --git a/crates/language_tools2/src/lsp_log.rs b/crates/language_tools2/src/lsp_log.rs index 1be0d2780a..13a2eab30c 100644 --- a/crates/language_tools2/src/lsp_log.rs +++ b/crates/language_tools2/src/lsp_log.rs @@ -78,7 +78,7 @@ pub(crate) struct LogMenuItem { actions!(debug, [OpenLanguageServerLogs]); pub fn init(cx: &mut AppContext) { - let log_store = cx.build_model(|cx| LogStore::new(cx)); + let log_store = cx.new_model(|cx| LogStore::new(cx)); cx.observe_new_views(move |workspace: &mut Workspace, cx| { let project = workspace.project(); @@ -93,7 +93,7 @@ pub fn init(cx: &mut AppContext) { let project = workspace.project().read(cx); if project.is_local() { workspace.add_item( - Box::new(cx.build_view(|cx| { + Box::new(cx.new_view(|cx| { LspLogView::new(workspace.project().clone(), log_store.clone(), cx) })), cx, @@ -444,7 +444,7 @@ impl LspLogView { log_contents: String, cx: &mut ViewContext, ) -> (View, Subscription) { - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { let mut editor = Editor::multi_line(cx); editor.set_text(log_contents, cx); editor.move_to_end(&MoveToEnd, cx); diff --git a/crates/language_tools2/src/lsp_log_tests.rs b/crates/language_tools2/src/lsp_log_tests.rs index 93e869369a..194b6d1ae8 100644 --- a/crates/language_tools2/src/lsp_log_tests.rs +++ b/crates/language_tools2/src/lsp_log_tests.rs @@ -46,7 +46,7 @@ async fn test_lsp_logs(cx: &mut TestAppContext) { project.languages().add(Arc::new(rust_language)); }); - let log_store = cx.build_model(|cx| LogStore::new(cx)); + let log_store = cx.new_model(|cx| LogStore::new(cx)); log_store.update(cx, |store, cx| store.add_project(&project, cx)); let _rust_buffer = project diff --git a/crates/language_tools2/src/syntax_tree_view.rs b/crates/language_tools2/src/syntax_tree_view.rs index 3b14b77582..20d6b6c82a 100644 --- a/crates/language_tools2/src/syntax_tree_view.rs +++ b/crates/language_tools2/src/syntax_tree_view.rs @@ -24,7 +24,7 @@ pub fn init(cx: &mut AppContext) { let active_item = workspace.active_item(cx); let workspace_handle = workspace.weak_handle(); let syntax_tree_view = - cx.build_view(|cx| SyntaxTreeView::new(workspace_handle, active_item, cx)); + cx.new_view(|cx| SyntaxTreeView::new(workspace_handle, active_item, cx)); workspace.split_item(SplitDirection::Right, Box::new(syntax_tree_view), cx) }); }) @@ -417,7 +417,7 @@ impl Item for SyntaxTreeView { where Self: Sized, { - Some(cx.build_view(|cx| { + Some(cx.new_view(|cx| { let mut clone = Self::new(self.workspace_handle.clone(), None, cx); if let Some(editor) = &self.editor { clone.set_editor(editor.editor.clone(), cx) diff --git a/crates/multi_buffer2/src/multi_buffer2.rs b/crates/multi_buffer2/src/multi_buffer2.rs index a38d36f02f..49ec284a99 100644 --- a/crates/multi_buffer2/src/multi_buffer2.rs +++ b/crates/multi_buffer2/src/multi_buffer2.rs @@ -1649,17 +1649,17 @@ impl MultiBuffer { #[cfg(any(test, feature = "test-support"))] impl MultiBuffer { pub fn build_simple(text: &str, cx: &mut gpui::AppContext) -> Model { - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); - cx.build_model(|cx| Self::singleton(buffer, cx)) + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); + cx.new_model(|cx| Self::singleton(buffer, cx)) } pub fn build_multi( excerpts: [(&str, Vec>); COUNT], cx: &mut gpui::AppContext, ) -> Model { - let multi = cx.build_model(|_| Self::new(0)); + let multi = cx.new_model(|_| Self::new(0)); for (text, ranges) in excerpts { - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); let excerpt_ranges = ranges.into_iter().map(|range| ExcerptRange { context: range, primary: None, @@ -1673,11 +1673,11 @@ impl MultiBuffer { } pub fn build_from_buffer(buffer: Model, cx: &mut gpui::AppContext) -> Model { - cx.build_model(|cx| Self::singleton(buffer, cx)) + cx.new_model(|cx| Self::singleton(buffer, cx)) } pub fn build_random(rng: &mut impl rand::Rng, cx: &mut gpui::AppContext) -> Model { - cx.build_model(|cx| { + cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); let mutation_count = rng.gen_range(1..=5); multibuffer.randomly_edit_excerpts(rng, mutation_count, cx); @@ -1748,8 +1748,7 @@ impl MultiBuffer { if excerpt_ids.is_empty() || (rng.gen() && excerpt_ids.len() < max_excerpts) { let buffer_handle = if rng.gen() || self.buffers.borrow().is_empty() { let text = RandomCharIter::new(&mut *rng).take(10).collect::(); - buffers - .push(cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text))); + buffers.push(cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text))); let buffer = buffers.last().unwrap().read(cx); log::info!( "Creating new buffer {} with text: {:?}", @@ -4144,8 +4143,8 @@ mod tests { #[gpui::test] fn test_singleton(cx: &mut AppContext) { let buffer = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'a'))); - let multibuffer = cx.build_model(|cx| MultiBuffer::singleton(buffer.clone(), cx)); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'a'))); + let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx)); let snapshot = multibuffer.read(cx).snapshot(cx); assert_eq!(snapshot.text(), buffer.read(cx).text()); @@ -4171,8 +4170,8 @@ mod tests { #[gpui::test] fn test_remote(cx: &mut AppContext) { - let host_buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "a")); - let guest_buffer = cx.build_model(|cx| { + let host_buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "a")); + let guest_buffer = cx.new_model(|cx| { let state = host_buffer.read(cx).to_proto(); let ops = cx .background_executor() @@ -4187,7 +4186,7 @@ mod tests { .unwrap(); buffer }); - let multibuffer = cx.build_model(|cx| MultiBuffer::singleton(guest_buffer.clone(), cx)); + let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(guest_buffer.clone(), cx)); let snapshot = multibuffer.read(cx).snapshot(cx); assert_eq!(snapshot.text(), "a"); @@ -4203,10 +4202,10 @@ mod tests { #[gpui::test] fn test_excerpt_boundaries_and_clipping(cx: &mut AppContext) { let buffer_1 = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'a'))); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'a'))); let buffer_2 = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'g'))); - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'g'))); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let events = Arc::new(RwLock::new(Vec::::new())); multibuffer.update(cx, |_, cx| { @@ -4439,12 +4438,12 @@ mod tests { #[gpui::test] fn test_excerpt_events(cx: &mut AppContext) { let buffer_1 = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(10, 3, 'a'))); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(10, 3, 'a'))); let buffer_2 = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(10, 3, 'm'))); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(10, 3, 'm'))); - let leader_multibuffer = cx.build_model(|_| MultiBuffer::new(0)); - let follower_multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + let leader_multibuffer = cx.new_model(|_| MultiBuffer::new(0)); + let follower_multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let follower_edit_event_count = Arc::new(RwLock::new(0)); follower_multibuffer.update(cx, |_, cx| { @@ -4547,8 +4546,8 @@ mod tests { #[gpui::test] fn test_push_excerpts_with_context_lines(cx: &mut AppContext) { let buffer = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a'))); - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a'))); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| { multibuffer.push_excerpts_with_context_lines( buffer.clone(), @@ -4584,8 +4583,8 @@ mod tests { #[gpui::test] async fn test_stream_excerpts_with_context_lines(cx: &mut TestAppContext) { let buffer = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a'))); - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a'))); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| { let snapshot = buffer.read(cx); let ranges = vec![ @@ -4620,7 +4619,7 @@ mod tests { #[gpui::test] fn test_empty_multibuffer(cx: &mut AppContext) { - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let snapshot = multibuffer.read(cx).snapshot(cx); assert_eq!(snapshot.text(), ""); @@ -4630,8 +4629,8 @@ mod tests { #[gpui::test] fn test_singleton_multibuffer_anchors(cx: &mut AppContext) { - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd")); - let multibuffer = cx.build_model(|cx| MultiBuffer::singleton(buffer.clone(), cx)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd")); + let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx)); let old_snapshot = multibuffer.read(cx).snapshot(cx); buffer.update(cx, |buffer, cx| { buffer.edit([(0..0, "X")], None, cx); @@ -4650,9 +4649,9 @@ mod tests { #[gpui::test] fn test_multibuffer_anchors(cx: &mut AppContext) { - let buffer_1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd")); - let buffer_2 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "efghi")); - let multibuffer = cx.build_model(|cx| { + let buffer_1 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd")); + let buffer_2 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "efghi")); + let multibuffer = cx.new_model(|cx| { let mut multibuffer = MultiBuffer::new(0); multibuffer.push_excerpts( buffer_1.clone(), @@ -4708,10 +4707,10 @@ mod tests { #[gpui::test] fn test_resolving_anchors_after_replacing_their_excerpts(cx: &mut AppContext) { - let buffer_1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd")); + let buffer_1 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd")); let buffer_2 = - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "ABCDEFGHIJKLMNOP")); - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "ABCDEFGHIJKLMNOP")); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); // Create an insertion id in buffer 1 that doesn't exist in buffer 2. // Add an excerpt from buffer 1 that spans this new insertion. @@ -4845,7 +4844,7 @@ mod tests { .unwrap_or(10); let mut buffers: Vec> = Vec::new(); - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let mut excerpt_ids = Vec::::new(); let mut expected_excerpts = Vec::<(Model, Range)>::new(); let mut anchors = Vec::new(); @@ -4922,7 +4921,7 @@ mod tests { .take(10) .collect::(); buffers.push( - cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), base_text)), + cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), base_text)), ); buffers.last().unwrap() } else { @@ -5265,9 +5264,9 @@ mod tests { let test_settings = SettingsStore::test(cx); cx.set_global(test_settings); - let buffer_1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "1234")); - let buffer_2 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "5678")); - let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); + let buffer_1 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "1234")); + let buffer_2 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "5678")); + let multibuffer = cx.new_model(|_| MultiBuffer::new(0)); let group_interval = multibuffer.read(cx).history.group_interval; multibuffer.update(cx, |multibuffer, cx| { multibuffer.push_excerpts( diff --git a/crates/notifications2/src/notification_store2.rs b/crates/notifications2/src/notification_store2.rs index ca474cd0c4..77c1d247ca 100644 --- a/crates/notifications2/src/notification_store2.rs +++ b/crates/notifications2/src/notification_store2.rs @@ -11,7 +11,7 @@ use time::OffsetDateTime; use util::ResultExt; pub fn init(client: Arc, user_store: Model, cx: &mut AppContext) { - let notification_store = cx.build_model(|cx| NotificationStore::new(client, user_store, cx)); + let notification_store = cx.new_model(|cx| NotificationStore::new(client, user_store, cx)); cx.set_global(notification_store); } diff --git a/crates/outline2/src/outline.rs b/crates/outline2/src/outline.rs index e9af96c1e5..0446f42798 100644 --- a/crates/outline2/src/outline.rs +++ b/crates/outline2/src/outline.rs @@ -80,7 +80,7 @@ impl OutlineView { cx: &mut ViewContext, ) -> OutlineView { let delegate = OutlineViewDelegate::new(cx.view().downgrade(), outline, editor, cx); - let picker = cx.build_view(|cx| Picker::new(delegate, cx)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx)); OutlineView { picker } } } diff --git a/crates/picker2/src/picker2.rs b/crates/picker2/src/picker2.rs index e95c9af003..546791a671 100644 --- a/crates/picker2/src/picker2.rs +++ b/crates/picker2/src/picker2.rs @@ -59,7 +59,7 @@ impl FocusableView for Picker { impl Picker { pub fn new(delegate: D, cx: &mut ViewContext) -> Self { - let editor = cx.build_view(|cx| { + let editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text(delegate.placeholder_text(), cx); editor diff --git a/crates/project2/src/project2.rs b/crates/project2/src/project2.rs index e598bad3a0..b9c73ae677 100644 --- a/crates/project2/src/project2.rs +++ b/crates/project2/src/project2.rs @@ -636,7 +636,7 @@ impl Project { fs: Arc, cx: &mut AppContext, ) -> Model { - cx.build_model(|cx: &mut ModelContext| { + cx.new_model(|cx: &mut ModelContext| { let (tx, rx) = mpsc::unbounded(); cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx)) .detach(); @@ -712,7 +712,7 @@ impl Project { project_id: remote_id, }) .await?; - let this = cx.build_model(|cx| { + let this = cx.new_model(|cx| { let replica_id = response.payload.replica_id as ReplicaId; let mut worktrees = Vec::new(); @@ -868,7 +868,7 @@ impl Project { languages.set_executor(cx.executor()); let http_client = util::http::FakeHttpClient::with_404_response(); let client = cx.update(|cx| client::Client::new(http_client.clone(), cx)); - let user_store = cx.build_model(|cx| UserStore::new(client.clone(), cx)); + let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); let project = cx.update(|cx| { Project::local( client, @@ -1690,7 +1690,7 @@ impl Project { return Err(anyhow!("creating buffers as a guest is not supported yet")); } let id = post_inc(&mut self.next_buffer_id); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new(self.replica_id(), id, text) .with_language(language.unwrap_or_else(|| language::PLAIN_TEXT.clone()), cx) }); @@ -7193,7 +7193,7 @@ impl Project { } let buffer_id = state.id; - let buffer = cx.build_model(|_| { + let buffer = cx.new_model(|_| { Buffer::from_proto(this.replica_id(), state, buffer_file).unwrap() }); this.incomplete_remote_buffers diff --git a/crates/project2/src/terminals.rs b/crates/project2/src/terminals.rs index a816c0ddb2..3184a428c9 100644 --- a/crates/project2/src/terminals.rs +++ b/crates/project2/src/terminals.rs @@ -39,7 +39,7 @@ impl Project { window, ) .map(|builder| { - let terminal_handle = cx.build_model(|cx| builder.subscribe(cx)); + let terminal_handle = cx.new_model(|cx| builder.subscribe(cx)); self.terminals .local_handles diff --git a/crates/project2/src/worktree.rs b/crates/project2/src/worktree.rs index 22b3cd8c65..6f7d2046d6 100644 --- a/crates/project2/src/worktree.rs +++ b/crates/project2/src/worktree.rs @@ -312,7 +312,7 @@ impl Worktree { let closure_fs = Arc::clone(&fs); let closure_next_entry_id = Arc::clone(&next_entry_id); let closure_abs_path = abs_path.to_path_buf(); - cx.build_model(move |cx: &mut ModelContext| { + cx.new_model(move |cx: &mut ModelContext| { cx.observe_global::(move |this, cx| { if let Self::Local(this) = this { let new_file_scan_exclusions = @@ -415,7 +415,7 @@ impl Worktree { client: Arc, cx: &mut AppContext, ) -> Model { - cx.build_model(|cx: &mut ModelContext| { + cx.new_model(|cx: &mut ModelContext| { let snapshot = Snapshot { id: WorktreeId(worktree.id as usize), abs_path: Arc::from(PathBuf::from(worktree.abs_path)), @@ -682,7 +682,7 @@ impl LocalWorktree { .background_executor() .spawn(async move { text::Buffer::new(0, id, contents) }) .await; - cx.build_model(|_| Buffer::build(text_buffer, diff_base, Some(Arc::new(file)))) + cx.new_model(|_| Buffer::build(text_buffer, diff_base, Some(Arc::new(file)))) }) } diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index 6a2e98ce5e..7f743015f1 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -168,7 +168,7 @@ struct DraggedProjectEntryView { impl ProjectPanel { fn new(workspace: &mut Workspace, cx: &mut ViewContext) -> View { let project = workspace.project().clone(); - let project_panel = cx.build_view(|cx: &mut ViewContext| { + let project_panel = cx.new_view(|cx: &mut ViewContext| { cx.observe(&project, |this, _, cx| { this.update_visible_entries(None, cx); cx.notify(); @@ -200,7 +200,7 @@ impl ProjectPanel { }) .detach(); - let filename_editor = cx.build_view(|cx| Editor::single_line(cx)); + let filename_editor = cx.new_view(|cx| Editor::single_line(cx)); cx.subscribe(&filename_editor, |this, _, event, cx| match event { editor::EditorEvent::BufferEdited @@ -1384,7 +1384,7 @@ impl ProjectPanel { div() .id(entry_id.to_proto() as usize) .on_drag(entry_id, move |entry_id, cx| { - cx.build_view(|_| DraggedProjectEntryView { + cx.new_view(|_| DraggedProjectEntryView { details: details.clone(), width, entry_id: *entry_id, diff --git a/crates/project_symbols2/src/project_symbols.rs b/crates/project_symbols2/src/project_symbols.rs index d9bdd41b6e..578a47f95a 100644 --- a/crates/project_symbols2/src/project_symbols.rs +++ b/crates/project_symbols2/src/project_symbols.rs @@ -340,7 +340,7 @@ mod tests { let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx)); // Create the project symbols view. - let symbols = cx.build_view(|cx| { + let symbols = cx.new_view(|cx| { Picker::new( ProjectSymbolsDelegate::new(workspace.downgrade(), project.clone()), cx, diff --git a/crates/recent_projects2/src/recent_projects.rs b/crates/recent_projects2/src/recent_projects.rs index 5178c1d9d8..4aded62ddf 100644 --- a/crates/recent_projects2/src/recent_projects.rs +++ b/crates/recent_projects2/src/recent_projects.rs @@ -30,7 +30,7 @@ impl ModalView for RecentProjects {} impl RecentProjects { fn new(delegate: RecentProjectsDelegate, rem_width: f32, cx: &mut ViewContext) -> Self { - let picker = cx.build_view(|cx| Picker::new(delegate, cx)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx)); let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent)); // We do not want to block the UI on a potentially lenghty call to DB, so we're gonna swap // out workspace locations once the future runs to completion. @@ -90,7 +90,7 @@ impl RecentProjects { })) } pub fn open_popover(workspace: WeakView, cx: &mut WindowContext<'_>) -> View { - cx.build_view(|cx| Self::new(RecentProjectsDelegate::new(workspace, false), 20., cx)) + cx.new_view(|cx| Self::new(RecentProjectsDelegate::new(workspace, false), 20., cx)) } } diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 02e664a109..1fb66934ab 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -430,7 +430,7 @@ impl BufferSearchBar { }); return; } - let view = cx.build_view(|cx| BufferSearchBar::new(cx)); + let view = cx.new_view(|cx| BufferSearchBar::new(cx)); this.add_item(view.clone(), cx); view.update(cx, |this, cx| this.deploy(deploy, cx)); cx.notify(); @@ -502,10 +502,10 @@ impl BufferSearchBar { }); } pub fn new(cx: &mut ViewContext) -> Self { - let query_editor = cx.build_view(|cx| Editor::single_line(cx)); + let query_editor = cx.new_view(|cx| Editor::single_line(cx)); cx.subscribe(&query_editor, Self::on_query_editor_event) .detach(); - let replacement_editor = cx.build_view(|cx| Editor::single_line(cx)); + let replacement_editor = cx.new_view(|cx| Editor::single_line(cx)); cx.subscribe(&replacement_editor, Self::on_query_editor_event) .detach(); Self { @@ -1038,7 +1038,7 @@ mod tests { &mut VisualTestContext<'_>, ) { init_globals(cx); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { Buffer::new( 0, cx.entity_id().as_u64(), @@ -1052,9 +1052,9 @@ mod tests { ) }); let (_, cx) = cx.add_window_view(|_| EmptyView {}); - let editor = cx.build_view(|cx| Editor::for_buffer(buffer.clone(), None, cx)); + let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx)); - let search_bar = cx.build_view(|cx| { + let search_bar = cx.new_view(|cx| { let mut search_bar = BufferSearchBar::new(cx); search_bar.set_active_pane_item(Some(&editor), cx); search_bar.show(cx); @@ -1399,7 +1399,7 @@ mod tests { expected_query_matches_count > 1, "Should pick a query with multiple results" ); - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text)); let window = cx.add_window(|_| EmptyView {}); let editor = window.build_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx)); @@ -1596,12 +1596,12 @@ mod tests { for "find" or "find and replace" operations on strings, or for input validation. "# .unindent(); - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text)); + let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text)); let (_, cx) = cx.add_window_view(|_| EmptyView {}); - let editor = cx.build_view(|cx| Editor::for_buffer(buffer.clone(), None, cx)); + let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx)); - let search_bar = cx.build_view(|cx| { + let search_bar = cx.new_view(|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/search2/src/project_search.rs b/crates/search2/src/project_search.rs index efb60c414c..ba4bda4be5 100644 --- a/crates/search2/src/project_search.rs +++ b/crates/search2/src/project_search.rs @@ -134,7 +134,7 @@ impl ProjectSearch { let replica_id = project.read(cx).replica_id(); Self { project, - excerpts: cx.build_model(|_| MultiBuffer::new(replica_id)), + excerpts: cx.new_model(|_| MultiBuffer::new(replica_id)), pending_search: Default::default(), match_ranges: Default::default(), active_query: None, @@ -145,11 +145,11 @@ impl ProjectSearch { } fn clone(&self, cx: &mut ModelContext) -> Model { - cx.build_model(|cx| Self { + cx.new_model(|cx| Self { project: self.project.clone(), excerpts: self .excerpts - .update(cx, |excerpts, cx| cx.build_model(|cx| excerpts.clone(cx))), + .update(cx, |excerpts, cx| cx.new_model(|cx| excerpts.clone(cx))), pending_search: Default::default(), match_ranges: self.match_ranges.clone(), active_query: self.active_query.clone(), @@ -504,7 +504,7 @@ impl Item for ProjectSearchView { Self: Sized, { let model = self.model.update(cx, |model, cx| model.clone(cx)); - Some(cx.build_view(|cx| Self::new(model, cx, None))) + Some(cx.new_view(|cx| Self::new(model, cx, None))) } fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext) { @@ -805,7 +805,7 @@ impl ProjectSearchView { } subscriptions.push(cx.observe(&model, |this, _, cx| this.model_changed(cx))); - let query_editor = cx.build_view(|cx| { + let query_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text("Text search all files", cx); editor.set_text(query_text, cx); @@ -817,7 +817,7 @@ impl ProjectSearchView { cx.emit(ViewEvent::EditorEvent(event.clone())) }), ); - let replacement_editor = cx.build_view(|cx| { + let replacement_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text("Replace in project..", cx); if let Some(text) = replacement_text { @@ -825,7 +825,7 @@ impl ProjectSearchView { } editor }); - let results_editor = cx.build_view(|cx| { + let results_editor = cx.new_view(|cx| { let mut editor = Editor::for_multibuffer(excerpts, Some(project.clone()), cx); editor.set_searchable(false); editor @@ -842,7 +842,7 @@ impl ProjectSearchView { }), ); - let included_files_editor = cx.build_view(|cx| { + let included_files_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text("Include: crates/**/*.toml", cx); @@ -855,7 +855,7 @@ impl ProjectSearchView { }), ); - let excluded_files_editor = cx.build_view(|cx| { + let excluded_files_editor = cx.new_view(|cx| { let mut editor = Editor::single_line(cx); editor.set_placeholder_text("Exclude: vendor/*, *.lock", cx); @@ -929,8 +929,8 @@ impl ProjectSearchView { return; }; - let model = cx.build_model(|cx| ProjectSearch::new(workspace.project().clone(), cx)); - let search = cx.build_view(|cx| ProjectSearchView::new(model, cx, None)); + let model = cx.new_model(|cx| ProjectSearch::new(workspace.project().clone(), cx)); + let search = cx.new_view(|cx| ProjectSearchView::new(model, cx, None)); workspace.add_item(Box::new(search.clone()), cx); search.update(cx, |search, cx| { search @@ -973,8 +973,8 @@ impl ProjectSearchView { None }; - let model = cx.build_model(|cx| ProjectSearch::new(workspace.project().clone(), cx)); - let search = cx.build_view(|cx| ProjectSearchView::new(model, cx, settings)); + let model = cx.new_model(|cx| ProjectSearch::new(workspace.project().clone(), cx)); + let search = cx.new_view(|cx| ProjectSearchView::new(model, cx, settings)); workspace.add_item(Box::new(search.clone()), cx); @@ -1246,13 +1246,13 @@ impl ProjectSearchBar { new_query }); if let Some(new_query) = new_query { - let model = cx.build_model(|cx| { + let model = cx.new_model(|cx| { let mut model = ProjectSearch::new(workspace.project().clone(), cx); model.search(new_query, cx); model }); workspace.add_item( - Box::new(cx.build_view(|cx| ProjectSearchView::new(model, cx, None))), + Box::new(cx.new_view(|cx| ProjectSearchView::new(model, cx, None))), cx, ); } @@ -1886,7 +1886,7 @@ pub mod tests { ) .await; let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await; - let search = cx.build_model(|cx| ProjectSearch::new(project, cx)); + let search = cx.new_model(|cx| ProjectSearch::new(project, cx)); let search_view = cx.add_window(|cx| ProjectSearchView::new(search.clone(), cx, None)); search_view diff --git a/crates/semantic_index2/src/semantic_index.rs b/crates/semantic_index2/src/semantic_index.rs index 0b207b0bf6..dbcdeee5ed 100644 --- a/crates/semantic_index2/src/semantic_index.rs +++ b/crates/semantic_index2/src/semantic_index.rs @@ -341,7 +341,7 @@ impl SemanticIndex { t0.elapsed().as_millis() ); - cx.build_model(|cx| { + cx.new_model(|cx| { let t0 = Instant::now(); let embedding_queue = EmbeddingQueue::new(embedding_provider.clone(), cx.background_executor().clone()); diff --git a/crates/storybook2/src/stories/auto_height_editor.rs b/crates/storybook2/src/stories/auto_height_editor.rs index e6d449008d..a98050230b 100644 --- a/crates/storybook2/src/stories/auto_height_editor.rs +++ b/crates/storybook2/src/stories/auto_height_editor.rs @@ -11,8 +11,8 @@ pub struct AutoHeightEditorStory { impl AutoHeightEditorStory { pub fn new(cx: &mut WindowContext) -> View { cx.bind_keys([KeyBinding::new("enter", editor::Newline, Some("Editor"))]); - cx.build_view(|cx| Self { - editor: cx.build_view(|cx| { + cx.new_view(|cx| Self { + editor: cx.new_view(|cx| { let mut editor = Editor::auto_height(3, cx); editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx); editor diff --git a/crates/storybook2/src/stories/focus.rs b/crates/storybook2/src/stories/focus.rs index a622a55192..ead6f701f9 100644 --- a/crates/storybook2/src/stories/focus.rs +++ b/crates/storybook2/src/stories/focus.rs @@ -20,7 +20,7 @@ impl FocusStory { KeyBinding::new("cmd-c", ActionC, None), ]); - cx.build_view(move |cx| { + cx.new_view(move |cx| { let parent_focus = cx.focus_handle(); let child_1_focus = cx.focus_handle(); let child_2_focus = cx.focus_handle(); diff --git a/crates/storybook2/src/stories/kitchen_sink.rs b/crates/storybook2/src/stories/kitchen_sink.rs index efc3540458..97d46a2a74 100644 --- a/crates/storybook2/src/stories/kitchen_sink.rs +++ b/crates/storybook2/src/stories/kitchen_sink.rs @@ -9,7 +9,7 @@ pub struct KitchenSinkStory; impl KitchenSinkStory { pub fn view(cx: &mut WindowContext) -> View { - cx.build_view(|_cx| Self) + cx.new_view(|_cx| Self) } } diff --git a/crates/storybook2/src/stories/picker.rs b/crates/storybook2/src/stories/picker.rs index 571e01af30..3ad04002b8 100644 --- a/crates/storybook2/src/stories/picker.rs +++ b/crates/storybook2/src/stories/picker.rs @@ -116,7 +116,7 @@ impl PickerDelegate for Delegate { impl PickerStory { pub fn new(cx: &mut WindowContext) -> View { - cx.build_view(|cx| { + cx.new_view(|cx| { cx.bind_keys([ KeyBinding::new("up", menu::SelectPrev, Some("picker")), KeyBinding::new("pageup", menu::SelectFirst, Some("picker")), @@ -136,7 +136,7 @@ impl PickerStory { ]); PickerStory { - picker: cx.build_view(|cx| { + picker: cx.new_view(|cx| { let mut delegate = Delegate::new(&[ "Baguette (France)", "Baklava (Turkey)", diff --git a/crates/storybook2/src/stories/scroll.rs b/crates/storybook2/src/stories/scroll.rs index 0ea1582e0b..a5f6c484c9 100644 --- a/crates/storybook2/src/stories/scroll.rs +++ b/crates/storybook2/src/stories/scroll.rs @@ -6,7 +6,7 @@ pub struct ScrollStory; impl ScrollStory { pub fn view(cx: &mut WindowContext) -> View { - cx.build_view(|_cx| ScrollStory) + cx.new_view(|_cx| ScrollStory) } } diff --git a/crates/storybook2/src/stories/text.rs b/crates/storybook2/src/stories/text.rs index cc25b8336b..49c10d6729 100644 --- a/crates/storybook2/src/stories/text.rs +++ b/crates/storybook2/src/stories/text.rs @@ -9,7 +9,7 @@ pub struct TextStory; impl TextStory { pub fn view(cx: &mut WindowContext) -> View { - cx.build_view(|_cx| Self) + cx.new_view(|_cx| Self) } } diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rs index 82dffd42fd..27ddfe26ac 100644 --- a/crates/storybook2/src/story_selector.rs +++ b/crates/storybook2/src/story_selector.rs @@ -42,30 +42,28 @@ impl ComponentStory { pub fn story(&self, cx: &mut WindowContext) -> AnyView { match self { Self::AutoHeightEditor => AutoHeightEditorStory::new(cx).into(), - Self::Avatar => cx.build_view(|_| ui::AvatarStory).into(), - Self::Button => cx.build_view(|_| ui::ButtonStory).into(), - Self::Checkbox => cx.build_view(|_| ui::CheckboxStory).into(), - Self::ContextMenu => cx.build_view(|_| ui::ContextMenuStory).into(), - Self::Cursor => cx.build_view(|_| crate::stories::CursorStory).into(), - Self::Disclosure => cx.build_view(|_| ui::DisclosureStory).into(), + Self::Avatar => cx.new_view(|_| ui::AvatarStory).into(), + Self::Button => cx.new_view(|_| ui::ButtonStory).into(), + Self::Checkbox => cx.new_view(|_| ui::CheckboxStory).into(), + Self::ContextMenu => cx.new_view(|_| ui::ContextMenuStory).into(), + Self::Cursor => cx.new_view(|_| crate::stories::CursorStory).into(), + Self::Disclosure => cx.new_view(|_| ui::DisclosureStory).into(), Self::Focus => FocusStory::view(cx).into(), - Self::Icon => cx.build_view(|_| ui::IconStory).into(), - Self::IconButton => cx.build_view(|_| ui::IconButtonStory).into(), - Self::Keybinding => cx.build_view(|_| ui::KeybindingStory).into(), - Self::Label => cx.build_view(|_| ui::LabelStory).into(), - Self::List => cx.build_view(|_| ui::ListStory).into(), - Self::ListHeader => cx.build_view(|_| ui::ListHeaderStory).into(), - Self::ListItem => cx.build_view(|_| ui::ListItemStory).into(), - Self::OverflowScroll => cx - .build_view(|_| crate::stories::OverflowScrollStory) - .into(), + Self::Icon => cx.new_view(|_| ui::IconStory).into(), + Self::IconButton => cx.new_view(|_| ui::IconButtonStory).into(), + Self::Keybinding => cx.new_view(|_| ui::KeybindingStory).into(), + Self::Label => cx.new_view(|_| ui::LabelStory).into(), + Self::List => cx.new_view(|_| ui::ListStory).into(), + Self::ListHeader => cx.new_view(|_| ui::ListHeaderStory).into(), + Self::ListItem => cx.new_view(|_| ui::ListItemStory).into(), + Self::OverflowScroll => cx.new_view(|_| crate::stories::OverflowScrollStory).into(), Self::Scroll => ScrollStory::view(cx).into(), Self::Text => TextStory::view(cx).into(), - Self::Tab => cx.build_view(|_| ui::TabStory).into(), - Self::TabBar => cx.build_view(|_| ui::TabBarStory).into(), - Self::ToggleButton => cx.build_view(|_| ui::ToggleButtonStory).into(), - Self::ViewportUnits => cx.build_view(|_| crate::stories::ViewportUnitsStory).into(), - Self::ZIndex => cx.build_view(|_| ZIndexStory).into(), + Self::Tab => cx.new_view(|_| ui::TabStory).into(), + Self::TabBar => cx.new_view(|_| ui::TabBarStory).into(), + Self::ToggleButton => cx.new_view(|_| ui::ToggleButtonStory).into(), + Self::ViewportUnits => cx.new_view(|_| crate::stories::ViewportUnitsStory).into(), + Self::ZIndex => cx.new_view(|_| ZIndexStory).into(), Self::Picker => PickerStory::new(cx).into(), } } diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index dec1aa6d5c..1b9ddd4b96 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -93,7 +93,7 @@ fn main() { let ui_font_size = ThemeSettings::get_global(cx).ui_font_size; cx.set_rem_size(ui_font_size); - cx.build_view(|cx| StoryWrapper::new(selector.story(cx))) + cx.new_view(|cx| StoryWrapper::new(selector.story(cx))) }, ); diff --git a/crates/terminal_view2/src/terminal_panel.rs b/crates/terminal_view2/src/terminal_panel.rs index a5be8a01ff..d228e9e48d 100644 --- a/crates/terminal_view2/src/terminal_panel.rs +++ b/crates/terminal_view2/src/terminal_panel.rs @@ -53,7 +53,7 @@ pub struct TerminalPanel { impl TerminalPanel { fn new(workspace: &Workspace, cx: &mut ViewContext) -> Self { let terminal_panel = cx.view().clone(); - let pane = cx.build_view(|cx| { + let pane = cx.new_view(|cx| { let mut pane = Pane::new( workspace.weak_handle(), workspace.project().clone(), @@ -147,7 +147,7 @@ impl TerminalPanel { .flatten(); let (panel, pane, items) = workspace.update(&mut cx, |workspace, cx| { - let panel = cx.build_view(|cx| TerminalPanel::new(workspace, cx)); + let panel = cx.new_view(|cx| TerminalPanel::new(workspace, cx)); let items = if let Some(serialized_panel) = serialized_panel.as_ref() { panel.update(cx, |panel, cx| { cx.notify(); @@ -272,7 +272,7 @@ impl TerminalPanel { .create_terminal(working_directory, window, cx) .log_err() }) { - let terminal = Box::new(cx.build_view(|cx| { + let terminal = Box::new(cx.new_view(|cx| { TerminalView::new( terminal, workspace.weak_handle(), diff --git a/crates/terminal_view2/src/terminal_view.rs b/crates/terminal_view2/src/terminal_view.rs index ad45a2ba3d..46409d1102 100644 --- a/crates/terminal_view2/src/terminal_view.rs +++ b/crates/terminal_view2/src/terminal_view.rs @@ -118,7 +118,7 @@ impl TerminalView { .notify_err(workspace, cx); if let Some(terminal) = terminal { - let view = cx.build_view(|cx| { + let view = cx.new_view(|cx| { TerminalView::new( terminal, workspace.weak_handle(), @@ -765,7 +765,7 @@ impl Item for TerminalView { project.create_terminal(cwd, window, cx) })??; pane.update(&mut cx, |_, cx| { - cx.build_view(|cx| TerminalView::new(terminal, workspace, workspace_id, cx)) + cx.new_view(|cx| TerminalView::new(terminal, workspace, workspace_id, cx)) }) }) } diff --git a/crates/theme_selector2/src/theme_selector.rs b/crates/theme_selector2/src/theme_selector.rs index ac3a52f2b9..075b12fc18 100644 --- a/crates/theme_selector2/src/theme_selector.rs +++ b/crates/theme_selector2/src/theme_selector.rs @@ -74,7 +74,7 @@ impl Render for ThemeSelector { impl ThemeSelector { pub fn new(delegate: ThemeSelectorDelegate, cx: &mut ViewContext) -> Self { - let picker = cx.build_view(|cx| Picker::new(delegate, cx)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx)); Self { picker } } } diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index 52ba2cedb2..a529dd1995 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -46,7 +46,7 @@ impl ContextMenu { cx: &mut WindowContext, f: impl FnOnce(Self, &mut WindowContext) -> Self, ) -> View { - cx.build_view(|cx| { + cx.new_view(|cx| { let focus_handle = cx.focus_handle(); let _on_blur_subscription = cx.on_blur(&focus_handle, |this: &mut ContextMenu, cx| { this.cancel(&menu::Cancel, cx) diff --git a/crates/ui2/src/components/tooltip.rs b/crates/ui2/src/components/tooltip.rs index 40fb28ba6c..56098718d8 100644 --- a/crates/ui2/src/components/tooltip.rs +++ b/crates/ui2/src/components/tooltip.rs @@ -13,7 +13,7 @@ pub struct Tooltip { impl Tooltip { pub fn text(title: impl Into, cx: &mut WindowContext) -> AnyView { - cx.build_view(|_cx| Self { + cx.new_view(|_cx| Self { title: title.into(), meta: None, key_binding: None, @@ -26,7 +26,7 @@ impl Tooltip { action: &dyn Action, cx: &mut WindowContext, ) -> AnyView { - cx.build_view(|cx| Self { + cx.new_view(|cx| Self { title: title.into(), meta: None, key_binding: KeyBinding::for_action(action, cx), @@ -40,7 +40,7 @@ impl Tooltip { meta: impl Into, cx: &mut WindowContext, ) -> AnyView { - cx.build_view(|cx| Self { + cx.new_view(|cx| Self { title: title.into(), meta: Some(meta.into()), key_binding: action.and_then(|action| KeyBinding::for_action(action, cx)), diff --git a/crates/vcs_menu2/src/lib.rs b/crates/vcs_menu2/src/lib.rs index a9cd0e820f..3ef82ee413 100644 --- a/crates/vcs_menu2/src/lib.rs +++ b/crates/vcs_menu2/src/lib.rs @@ -35,7 +35,7 @@ pub struct BranchList { impl BranchList { fn new(delegate: BranchListDelegate, rem_width: f32, cx: &mut ViewContext) -> Self { - let picker = cx.build_view(|cx| Picker::new(delegate, cx)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx)); let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent)); Self { picker, @@ -84,7 +84,7 @@ pub fn build_branch_list( let delegate = workspace.update(cx, |workspace, cx| { BranchListDelegate::new(workspace, cx.view().clone(), 29, cx) })?; - Ok(cx.build_view(move |cx| BranchList::new(delegate, 20., cx))) + Ok(cx.new_view(move |cx| BranchList::new(delegate, 20., cx))) } pub struct BranchListDelegate { diff --git a/crates/vim2/src/editor_events.rs b/crates/vim2/src/editor_events.rs index 70f486f298..3c2f373f94 100644 --- a/crates/vim2/src/editor_events.rs +++ b/crates/vim2/src/editor_events.rs @@ -77,7 +77,7 @@ mod test { async fn test_blur_focus(cx: &mut gpui::TestAppContext) { let mut cx = VimTestContext::new(cx, true).await; - let buffer = cx.build_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); + let buffer = cx.new_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx)); let editor2 = cx .update(|cx| { diff --git a/crates/vim2/src/test/vim_test_context.rs b/crates/vim2/src/test/vim_test_context.rs index 47afc20785..21b041b245 100644 --- a/crates/vim2/src/test/vim_test_context.rs +++ b/crates/vim2/src/test/vim_test_context.rs @@ -57,7 +57,7 @@ impl<'a> VimTestContext<'a> { observe_keystrokes(cx); workspace.active_pane().update(cx, |pane, cx| { pane.toolbar().update(cx, |toolbar, cx| { - let buffer_search_bar = cx.build_view(BufferSearchBar::new); + let buffer_search_bar = cx.new_view(BufferSearchBar::new); toolbar.add_item(buffer_search_bar, cx); // todo!(); // let project_search_bar = cx.add_view(|_| ProjectSearchBar::new()); @@ -65,7 +65,7 @@ impl<'a> VimTestContext<'a> { }) }); workspace.status_bar().update(cx, |status_bar, cx| { - let vim_mode_indicator = cx.build_view(ModeIndicator::new); + let vim_mode_indicator = cx.new_view(ModeIndicator::new); status_bar.add_right_item(vim_mode_indicator, cx); }); }); diff --git a/crates/welcome2/src/base_keymap_picker.rs b/crates/welcome2/src/base_keymap_picker.rs index aec7932aa3..82b997547c 100644 --- a/crates/welcome2/src/base_keymap_picker.rs +++ b/crates/welcome2/src/base_keymap_picker.rs @@ -54,7 +54,7 @@ impl BaseKeymapSelector { delegate: BaseKeymapSelectorDelegate, cx: &mut ViewContext, ) -> Self { - let picker = cx.build_view(|cx| Picker::new(delegate, cx)); + let picker = cx.new_view(|cx| Picker::new(delegate, cx)); let focus_handle = cx.focus_handle(); Self { focus_handle, diff --git a/crates/welcome2/src/welcome.rs b/crates/welcome2/src/welcome.rs index 56f3ae68b0..5abb807f42 100644 --- a/crates/welcome2/src/welcome.rs +++ b/crates/welcome2/src/welcome.rs @@ -27,7 +27,7 @@ pub fn init(cx: &mut AppContext) { cx.observe_new_views(|workspace: &mut Workspace, _cx| { workspace.register_action(|workspace, _: &Welcome, cx| { - let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx)); + let welcome_page = cx.new_view(|cx| WelcomePage::new(workspace, cx)); workspace.add_item(Box::new(welcome_page), cx) }); }) @@ -39,7 +39,7 @@ pub fn init(cx: &mut AppContext) { pub fn show_welcome_view(app_state: &Arc, cx: &mut AppContext) { open_new(&app_state, cx, |workspace, cx| { workspace.toggle_dock(DockPosition::Left, cx); - let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx)); + let welcome_page = cx.new_view(|cx| WelcomePage::new(workspace, cx)); workspace.add_item_to_center(Box::new(welcome_page.clone()), cx); cx.focus_view(&welcome_page); cx.notify(); @@ -270,7 +270,7 @@ impl Item for WelcomePage { _workspace_id: WorkspaceId, cx: &mut ViewContext, ) -> Option> { - Some(cx.build_view(|cx| WelcomePage { + Some(cx.new_view(|cx| WelcomePage { focus_handle: cx.focus_handle(), workspace: self.workspace.clone(), _settings_subscription: cx.observe_global::(move |_, cx| cx.notify()), diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rs index f3c857ada4..3d853cdee1 100644 --- a/crates/workspace2/src/dock.rs +++ b/crates/workspace2/src/dock.rs @@ -195,7 +195,7 @@ impl Dock { pub fn new(position: DockPosition, cx: &mut ViewContext) -> View { let focus_handle = cx.focus_handle(); - let dock = cx.build_view(|cx: &mut ViewContext| { + let dock = cx.new_view(|cx: &mut ViewContext| { let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| { if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) { active_entry.panel.focus_handle(cx).focus(cx) @@ -514,7 +514,7 @@ impl Render for Dock { .id("resize-handle") .on_drag(DraggedDock(position), |dock, cx| { cx.stop_propagation(); - cx.build_view(|_| dock.clone()) + cx.new_view(|_| dock.clone()) }) .on_click(cx.listener(|v, e: &ClickEvent, cx| { if e.down.button == MouseButton::Left && e.down.click_count == 2 { diff --git a/crates/workspace2/src/item.rs b/crates/workspace2/src/item.rs index 60be7eb65a..1b6582d515 100644 --- a/crates/workspace2/src/item.rs +++ b/crates/workspace2/src/item.rs @@ -831,14 +831,14 @@ pub mod test { worktree_id: WorktreeId::from_usize(0), path: Path::new(path).into(), }); - cx.build_model(|_| Self { + cx.new_model(|_| Self { entry_id, project_path, }) } pub fn new_untitled(cx: &mut AppContext) -> Model { - cx.build_model(|_| Self { + cx.new_model(|_| Self { project_path: None, entry_id: None, }) @@ -987,7 +987,7 @@ pub mod test { where Self: Sized, { - Some(cx.build_view(|cx| Self { + Some(cx.new_view(|cx| Self { state: self.state.clone(), label: self.label.clone(), save_count: self.save_count, @@ -1063,7 +1063,7 @@ pub mod test { _item_id: ItemId, cx: &mut ViewContext, ) -> Task>> { - let view = cx.build_view(|cx| Self::new_deserialized(workspace_id, cx)); + let view = cx.new_view(|cx| Self::new_deserialized(workspace_id, cx)); Task::Ready(Some(anyhow::Ok(view))) } } diff --git a/crates/workspace2/src/modal_layer.rs b/crates/workspace2/src/modal_layer.rs index d9c50a7a56..01c17b9ed1 100644 --- a/crates/workspace2/src/modal_layer.rs +++ b/crates/workspace2/src/modal_layer.rs @@ -53,7 +53,7 @@ impl ModalLayer { return; } } - let new_modal = cx.build_view(build_view); + let new_modal = cx.new_view(build_view); self.show_modal(new_modal, cx); } diff --git a/crates/workspace2/src/notifications.rs b/crates/workspace2/src/notifications.rs index 645e0913a9..44fc9c29ce 100644 --- a/crates/workspace2/src/notifications.rs +++ b/crates/workspace2/src/notifications.rs @@ -119,7 +119,7 @@ impl Workspace { E: std::fmt::Debug, { self.show_notification(0, cx, |cx| { - cx.build_view(|_cx| { + cx.new_view(|_cx| { simple_message_notification::MessageNotification::new(format!("Error: {err:?}")) }) }); @@ -134,7 +134,7 @@ impl Workspace { pub fn show_toast(&mut self, toast: Toast, cx: &mut ViewContext) { self.dismiss_notification::(toast.id, cx); self.show_notification(toast.id, cx, |cx| { - cx.build_view(|_cx| match toast.on_click.as_ref() { + cx.new_view(|_cx| match toast.on_click.as_ref() { Some((click_msg, on_click)) => { let on_click = on_click.clone(); simple_message_notification::MessageNotification::new(toast.msg.clone()) diff --git a/crates/workspace2/src/pane.rs b/crates/workspace2/src/pane.rs index 91d7fa30a0..9e620d993a 100644 --- a/crates/workspace2/src/pane.rs +++ b/crates/workspace2/src/pane.rs @@ -361,7 +361,7 @@ impl Pane { pane: handle.clone(), next_timestamp, }))), - toolbar: cx.build_view(|_| Toolbar::new()), + toolbar: cx.new_view(|_| Toolbar::new()), new_item_menu: None, split_item_menu: None, tab_bar_scroll_handle: ScrollHandle::new(), @@ -1540,7 +1540,7 @@ impl Pane { is_active, ix, }, - |tab, cx| cx.build_view(|_| tab.clone()), + |tab, cx| cx.new_view(|_| tab.clone()), ) .drag_over::(|tab| tab.bg(cx.theme().colors().drop_target_background)) .drag_over::(|tab| tab.bg(cx.theme().colors().drop_target_background)) @@ -2241,7 +2241,7 @@ mod tests { set_labeled_items(&pane, ["A", "B*", "C"], cx); pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| TestItem::new(cx).with_label("D"))), + Box::new(cx.new_view(|cx| TestItem::new(cx).with_label("D"))), false, false, Some(0), @@ -2254,7 +2254,7 @@ mod tests { set_labeled_items(&pane, ["A", "B*", "C"], cx); pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| TestItem::new(cx).with_label("D"))), + Box::new(cx.new_view(|cx| TestItem::new(cx).with_label("D"))), false, false, Some(2), @@ -2267,7 +2267,7 @@ mod tests { set_labeled_items(&pane, ["A", "B*", "C"], cx); pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| TestItem::new(cx).with_label("D"))), + Box::new(cx.new_view(|cx| TestItem::new(cx).with_label("D"))), false, false, Some(5), @@ -2281,7 +2281,7 @@ mod tests { set_labeled_items(&pane, ["A*", "B", "C"], cx); pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| TestItem::new(cx).with_label("D"))), + Box::new(cx.new_view(|cx| TestItem::new(cx).with_label("D"))), false, false, None, @@ -2294,7 +2294,7 @@ mod tests { set_labeled_items(&pane, ["A", "B", "C*"], cx); pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| TestItem::new(cx).with_label("D"))), + Box::new(cx.new_view(|cx| TestItem::new(cx).with_label("D"))), false, false, None, @@ -2391,7 +2391,7 @@ mod tests { // singleton view pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| { + Box::new(cx.new_view(|cx| { TestItem::new(cx) .with_singleton(true) .with_label("buffer 1") @@ -2408,7 +2408,7 @@ mod tests { // new singleton view with the same project entry pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| { + Box::new(cx.new_view(|cx| { TestItem::new(cx) .with_singleton(true) .with_label("buffer 1") @@ -2425,7 +2425,7 @@ mod tests { // new singleton view with different project entry pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| { + Box::new(cx.new_view(|cx| { TestItem::new(cx) .with_singleton(true) .with_label("buffer 2") @@ -2442,7 +2442,7 @@ mod tests { // new multibuffer view with the same project entry pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| { + Box::new(cx.new_view(|cx| { TestItem::new(cx) .with_singleton(false) .with_label("multibuffer 1") @@ -2459,7 +2459,7 @@ mod tests { // another multibuffer view with the same project entry pane.update(cx, |pane, cx| { pane.add_item( - Box::new(cx.build_view(|cx| { + Box::new(cx.new_view(|cx| { TestItem::new(cx) .with_singleton(false) .with_label("multibuffer 1b") @@ -2673,7 +2673,7 @@ mod tests { ) -> Box> { pane.update(cx, |pane, cx| { let labeled_item = Box::new( - cx.build_view(|cx| TestItem::new(cx).with_label(label).with_dirty(is_dirty)), + cx.new_view(|cx| TestItem::new(cx).with_label(label).with_dirty(is_dirty)), ); pane.add_item(labeled_item.clone(), false, false, None, cx); labeled_item @@ -2696,8 +2696,7 @@ mod tests { active_item_index = index; } - let labeled_item = - Box::new(cx.build_view(|cx| TestItem::new(cx).with_label(label))); + let labeled_item = Box::new(cx.new_view(|cx| TestItem::new(cx).with_label(label))); pane.add_item(labeled_item.clone(), false, false, None, cx); index += 1; labeled_item diff --git a/crates/workspace2/src/shared_screen.rs b/crates/workspace2/src/shared_screen.rs index e4f0a0bf63..af38d48892 100644 --- a/crates/workspace2/src/shared_screen.rs +++ b/crates/workspace2/src/shared_screen.rs @@ -117,7 +117,7 @@ impl Item for SharedScreen { cx: &mut ViewContext, ) -> Option> { let track = self.track.upgrade()?; - Some(cx.build_view(|cx| Self::new(&track, self.peer_id, self.user.clone(), cx))) + Some(cx.new_view(|cx| Self::new(&track, self.peer_id, self.user.clone(), cx))) } fn to_item_events(event: &Self::Event, mut f: impl FnMut(ItemEvent)) { diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index f98d6a7bb2..897f700dd0 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -261,7 +261,7 @@ pub fn register_project_item(cx: &mut AppContext) { let builders = cx.default_global::(); builders.insert(TypeId::of::(), |project, model, cx| { let item = model.downcast::().unwrap(); - Box::new(cx.build_view(|cx| I::for_project_item(project, item, cx))) + Box::new(cx.new_view(|cx| I::for_project_item(project, item, cx))) }); } @@ -358,8 +358,8 @@ impl AppState { let languages = Arc::new(LanguageRegistry::test()); let http_client = util::http::FakeHttpClient::with_404_response(); let client = Client::new(http_client.clone(), cx); - let user_store = cx.build_model(|cx| UserStore::new(client.clone(), cx)); - let workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); + let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); + let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx)); theme::init(theme::LoadThemes::JustBase, cx); client::init(&client, cx); @@ -519,7 +519,7 @@ impl Workspace { } project::Event::Notification(message) => this.show_notification(0, cx, |cx| { - cx.build_view(|_| MessageNotification::new(message.clone())) + cx.new_view(|_| MessageNotification::new(message.clone())) }), _ => {} @@ -537,7 +537,7 @@ impl Workspace { let weak_handle = cx.view().downgrade(); let pane_history_timestamp = Arc::new(AtomicUsize::new(0)); - let center_pane = cx.build_view(|cx| { + let center_pane = cx.new_view(|cx| { Pane::new( weak_handle.clone(), project.clone(), @@ -589,10 +589,10 @@ impl Workspace { let left_dock = Dock::new(DockPosition::Left, cx); let bottom_dock = Dock::new(DockPosition::Bottom, cx); let right_dock = Dock::new(DockPosition::Right, cx); - let left_dock_buttons = cx.build_view(|cx| PanelButtons::new(left_dock.clone(), cx)); - let bottom_dock_buttons = cx.build_view(|cx| PanelButtons::new(bottom_dock.clone(), cx)); - let right_dock_buttons = cx.build_view(|cx| PanelButtons::new(right_dock.clone(), cx)); - let status_bar = cx.build_view(|cx| { + let left_dock_buttons = cx.new_view(|cx| PanelButtons::new(left_dock.clone(), cx)); + let bottom_dock_buttons = cx.new_view(|cx| PanelButtons::new(bottom_dock.clone(), cx)); + let right_dock_buttons = cx.new_view(|cx| PanelButtons::new(right_dock.clone(), cx)); + let status_bar = cx.new_view(|cx| { let mut status_bar = StatusBar::new(¢er_pane.clone(), cx); status_bar.add_left_item(left_dock_buttons, cx); status_bar.add_right_item(right_dock_buttons, cx); @@ -600,7 +600,7 @@ impl Workspace { status_bar }); - let modal_layer = cx.build_view(|_| ModalLayer::new()); + let modal_layer = cx.new_view(|_| ModalLayer::new()); let mut active_call = None; if cx.has_global::>() { @@ -800,7 +800,7 @@ impl Workspace { let workspace_id = workspace_id.clone(); let project_handle = project_handle.clone(); move |cx| { - cx.build_view(|cx| { + cx.new_view(|cx| { Workspace::new(workspace_id, project_handle, app_state, cx) }) } @@ -1718,7 +1718,7 @@ impl Workspace { } fn add_pane(&mut self, cx: &mut ViewContext) -> View { - let pane = cx.build_view(|cx| { + let pane = cx.new_view(|cx| { Pane::new( self.weak_handle(), self.project.clone(), @@ -1915,8 +1915,7 @@ impl Workspace { return item; } - let item = - cx.build_view(|cx| T::for_project_item(self.project().clone(), project_item, cx)); + let item = cx.new_view(|cx| T::for_project_item(self.project().clone(), project_item, cx)); self.add_item(Box::new(item.clone()), cx); item } @@ -1940,8 +1939,7 @@ impl Workspace { return item; } - let item = - cx.build_view(|cx| T::for_project_item(self.project().clone(), project_item, cx)); + let item = cx.new_view(|cx| T::for_project_item(self.project().clone(), project_item, cx)); self.split_item(SplitDirection::Right, Box::new(item.clone()), cx); item } @@ -2852,7 +2850,7 @@ impl Workspace { } } - Some(cx.build_view(|cx| SharedScreen::new(&track, peer_id, user.clone(), cx))) + Some(cx.new_view(|cx| SharedScreen::new(&track, peer_id, user.clone(), cx))) } pub fn on_window_activation_changed(&mut self, cx: &mut ViewContext) { @@ -3265,7 +3263,7 @@ impl Workspace { let client = project.read(cx).client(); let user_store = project.read(cx).user_store(); - let workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); + let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx)); let app_state = Arc::new(AppState { languages: project.read(cx).languages().clone(), workspace_store, @@ -3468,7 +3466,7 @@ fn notify_if_database_failed(workspace: WindowHandle, cx: &mut AsyncA .update(cx, |workspace, cx| { if (*db::ALL_FILE_DB_FAILED).load(std::sync::atomic::Ordering::Acquire) { workspace.show_notification_once(0, cx, |cx| { - cx.build_view(|_| { + cx.new_view(|_| { MessageNotification::new("Failed to load the database file.") .with_click_message("Click to let us know about this error") .on_click(|cx| cx.open_url(REPORT_ISSUE_URL)) @@ -4180,7 +4178,7 @@ pub fn join_remote_project( cx.update(|cx| { let options = (app_state.build_window_options)(window_bounds_override, None, cx); cx.open_window(options, |cx| { - cx.build_view(|cx| Workspace::new(0, project, app_state.clone(), cx)) + cx.new_view(|cx| Workspace::new(0, project, app_state.clone(), cx)) }) })? }; @@ -4354,7 +4352,7 @@ mod tests { let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx)); // Adding an item with no ambiguity renders the tab without detail. - let item1 = cx.build_view(|cx| { + let item1 = cx.new_view(|cx| { let mut item = TestItem::new(cx); item.tab_descriptions = Some(vec!["c", "b1/c", "a/b1/c"]); item @@ -4366,7 +4364,7 @@ mod tests { // Adding an item that creates ambiguity increases the level of detail on // both tabs. - let item2 = cx.build_view(|cx| { + let item2 = cx.new_view(|cx| { let mut item = TestItem::new(cx); item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]); item @@ -4380,7 +4378,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.build_view(|cx| { + let item3 = cx.new_view(|cx| { let mut item = TestItem::new(cx); item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]); item @@ -4421,10 +4419,10 @@ mod tests { project.worktrees().next().unwrap().read(cx).id() }); - let item1 = cx.build_view(|cx| { + let item1 = cx.new_view(|cx| { TestItem::new(cx).with_project_items(&[TestProjectItem::new(1, "one.txt", cx)]) }); - let item2 = cx.build_view(|cx| { + let item2 = cx.new_view(|cx| { TestItem::new(cx).with_project_items(&[TestProjectItem::new(2, "two.txt", cx)]) }); @@ -4493,15 +4491,15 @@ mod tests { let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx)); // When there are no dirty items, there's nothing to do. - let item1 = cx.build_view(|cx| TestItem::new(cx)); + let item1 = cx.new_view(|cx| TestItem::new(cx)); 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.build_view(|cx| TestItem::new(cx).with_dirty(true)); - let item3 = cx.build_view(|cx| { + let item2 = cx.new_view(|cx| TestItem::new(cx).with_dirty(true)); + let item3 = cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_project_items(&[TestProjectItem::new(1, "1.txt", cx)]) @@ -4529,24 +4527,24 @@ mod tests { let project = Project::test(fs, None, cx).await; let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); - let item1 = cx.build_view(|cx| { + let item1 = cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_project_items(&[TestProjectItem::new(1, "1.txt", cx)]) }); - let item2 = cx.build_view(|cx| { + let item2 = cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_conflict(true) .with_project_items(&[TestProjectItem::new(2, "2.txt", cx)]) }); - let item3 = cx.build_view(|cx| { + let item3 = cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_conflict(true) .with_project_items(&[TestProjectItem::new(3, "3.txt", cx)]) }); - let item4 = cx.build_view(|cx| { + let item4 = cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_project_items(&[TestProjectItem::new_untitled(cx)]) @@ -4638,7 +4636,7 @@ mod tests { // workspace items with multiple project entries. let single_entry_items = (0..=4) .map(|project_entry_id| { - cx.build_view(|cx| { + cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_project_items(&[TestProjectItem::new( @@ -4649,7 +4647,7 @@ mod tests { }) }) .collect::>(); - let item_2_3 = cx.build_view(|cx| { + let item_2_3 = cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_singleton(false) @@ -4658,7 +4656,7 @@ mod tests { single_entry_items[3].read(cx).project_items[0].clone(), ]) }); - let item_3_4 = cx.build_view(|cx| { + let item_3_4 = cx.new_view(|cx| { TestItem::new(cx) .with_dirty(true) .with_singleton(false) @@ -4745,7 +4743,7 @@ mod tests { let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone()); - let item = cx.build_view(|cx| { + let item = cx.new_view(|cx| { TestItem::new(cx).with_project_items(&[TestProjectItem::new(1, "1.txt", cx)]) }); let item_id = item.entity_id(); @@ -4864,7 +4862,7 @@ mod tests { let project = Project::test(fs, [], cx).await; let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); - let item = cx.build_view(|cx| { + let item = cx.new_view(|cx| { TestItem::new(cx).with_project_items(&[TestProjectItem::new(1, "1.txt", cx)]) }); let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone()); diff --git a/crates/zed2/src/languages/c.rs b/crates/zed2/src/languages/c.rs index 280d9dd921..a0b00d7797 100644 --- a/crates/zed2/src/languages/c.rs +++ b/crates/zed2/src/languages/c.rs @@ -293,7 +293,7 @@ mod tests { }); let language = crate::languages::language("c", tree_sitter_c::language(), None).await; - cx.build_model(|cx| { + cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx); diff --git a/crates/zed2/src/languages/python.rs b/crates/zed2/src/languages/python.rs index 3666237e69..d28cd9f6e4 100644 --- a/crates/zed2/src/languages/python.rs +++ b/crates/zed2/src/languages/python.rs @@ -198,7 +198,7 @@ mod tests { }); }); - cx.build_model(|cx| { + cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx); let append = |buffer: &mut Buffer, text: &str, cx: &mut ModelContext| { diff --git a/crates/zed2/src/languages/rust.rs b/crates/zed2/src/languages/rust.rs index 961e6fe7f0..6f6ffa4188 100644 --- a/crates/zed2/src/languages/rust.rs +++ b/crates/zed2/src/languages/rust.rs @@ -508,7 +508,7 @@ mod tests { let language = crate::languages::language("rust", tree_sitter_rust::language(), None).await; - cx.build_model(|cx| { + cx.new_model(|cx| { let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx); diff --git a/crates/zed2/src/languages/typescript.rs b/crates/zed2/src/languages/typescript.rs index 26ad337920..de25f2ead8 100644 --- a/crates/zed2/src/languages/typescript.rs +++ b/crates/zed2/src/languages/typescript.rs @@ -378,7 +378,7 @@ mod tests { "# .unindent(); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { language::Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) }); let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None).unwrap()); diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 2fbb9c101d..a801f0ec18 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -139,8 +139,8 @@ fn main() { language::init(cx); languages::init(languages.clone(), node_runtime.clone(), cx); - let user_store = cx.build_model(|cx| UserStore::new(client.clone(), cx)); - let workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); + let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx)); + let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx)); cx.set_global(client.clone()); diff --git a/crates/zed2/src/zed2.rs b/crates/zed2/src/zed2.rs index 4abc81cf37..bcfdb848ab 100644 --- a/crates/zed2/src/zed2.rs +++ b/crates/zed2/src/zed2.rs @@ -115,17 +115,17 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { // workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx); let copilot = - cx.build_view(|cx| copilot_button::CopilotButton::new(app_state.fs.clone(), cx)); + cx.new_view(|cx| copilot_button::CopilotButton::new(app_state.fs.clone(), cx)); let diagnostic_summary = - cx.build_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx)); + cx.new_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx)); let activity_indicator = activity_indicator::ActivityIndicator::new(workspace, app_state.languages.clone(), cx); let active_buffer_language = - cx.build_view(|_| language_selector::ActiveBufferLanguage::new(workspace)); - let vim_mode_indicator = cx.build_view(|cx| vim::ModeIndicator::new(cx)); - let feedback_button = cx - .build_view(|_| feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace)); - let cursor_position = cx.build_view(|_| editor::items::CursorPosition::new()); + cx.new_view(|_| language_selector::ActiveBufferLanguage::new(workspace)); + let vim_mode_indicator = cx.new_view(|cx| vim::ModeIndicator::new(cx)); + let feedback_button = + cx.new_view(|_| feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace)); + let cursor_position = cx.new_view(|_| editor::items::CursorPosition::new()); workspace.status_bar().update(cx, |status_bar, cx| { status_bar.add_left_item(diagnostic_summary, cx); status_bar.add_left_item(activity_indicator, cx); @@ -412,22 +412,22 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { fn initialize_pane(workspace: &mut Workspace, pane: &View, cx: &mut ViewContext) { pane.update(cx, |pane, cx| { pane.toolbar().update(cx, |toolbar, cx| { - let breadcrumbs = cx.build_view(|_| Breadcrumbs::new()); + let breadcrumbs = cx.new_view(|_| Breadcrumbs::new()); toolbar.add_item(breadcrumbs, cx); - let buffer_search_bar = cx.build_view(search::BufferSearchBar::new); + let buffer_search_bar = cx.new_view(search::BufferSearchBar::new); toolbar.add_item(buffer_search_bar.clone(), cx); let quick_action_bar = - cx.build_view(|_| QuickActionBar::new(buffer_search_bar, workspace)); + cx.new_view(|_| QuickActionBar::new(buffer_search_bar, workspace)); toolbar.add_item(quick_action_bar, cx); - let diagnostic_editor_controls = cx.build_view(|_| diagnostics::ToolbarControls::new()); + let diagnostic_editor_controls = cx.new_view(|_| diagnostics::ToolbarControls::new()); toolbar.add_item(diagnostic_editor_controls, cx); - let project_search_bar = cx.build_view(|_| ProjectSearchBar::new()); + let project_search_bar = cx.new_view(|_| ProjectSearchBar::new()); toolbar.add_item(project_search_bar, cx); - let lsp_log_item = cx.build_view(|_| language_tools::LspLogToolbarItemView::new()); + let lsp_log_item = cx.new_view(|_| language_tools::LspLogToolbarItemView::new()); toolbar.add_item(lsp_log_item, cx); let syntax_tree_item = - cx.build_view(|_| language_tools::SyntaxTreeToolbarItemView::new()); + cx.new_view(|_| language_tools::SyntaxTreeToolbarItemView::new()); toolbar.add_item(syntax_tree_item, cx); }) }); @@ -541,13 +541,15 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext) { .expect("creating buffers on a local workspace always succeeds"); buffer.update(cx, |buffer, cx| buffer.edit([(0..0, log)], None, cx)); - let buffer = cx.build_model(|cx| { + let buffer = cx.new_model(|cx| { MultiBuffer::singleton(buffer, cx).with_title("Log".into()) }); workspace.add_item( - Box::new(cx.build_view(|cx| { - Editor::for_multibuffer(buffer, Some(project), cx) - })), + Box::new( + cx.new_view(|cx| { + Editor::for_multibuffer(buffer, Some(project), cx) + }), + ), cx, ); }) @@ -655,7 +657,7 @@ fn open_local_settings_file( .detach(); } else { workspace.show_notification(0, cx, |cx| { - cx.build_view(|_| MessageNotification::new("This project has no folders open.")) + cx.new_view(|_| MessageNotification::new("This project has no folders open.")) }) } } @@ -702,11 +704,11 @@ fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext