Rename build_view to new_view and build_model to new_model (#3823)

The word "new" is shorter and blends in with `new` constructors that are
common in Rust. Been meaning to do this for a while.

Release Notes:

- N/A
This commit is contained in:
Nathan Sobo 2024-01-02 08:11:53 -07:00 committed by GitHub
commit 6b14f2fd08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
97 changed files with 470 additions and 494 deletions

View file

@ -55,7 +55,7 @@ impl ActivityIndicator {
) -> View<ActivityIndicator> { ) -> View<ActivityIndicator> {
let project = workspace.project().clone(); let project = workspace.project().clone();
let auto_updater = AutoUpdater::get(cx); let auto_updater = AutoUpdater::get(cx);
let this = cx.build_view(|cx: &mut ViewContext<Self>| { let this = cx.new_view(|cx: &mut ViewContext<Self>| {
let mut status_events = languages.language_server_binary_statuses(); let mut status_events = languages.language_server_binary_statuses();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
while let Some((language, event)) = status_events.next().await { while let Some((language, event)) = status_events.next().await {
@ -101,9 +101,9 @@ impl ActivityIndicator {
); );
}); });
workspace.add_item( workspace.add_item(
Box::new(cx.build_view(|cx| { Box::new(
Editor::for_buffer(buffer, Some(project.clone()), cx) cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx)),
})), ),
cx, cx,
); );
} }

View file

@ -126,7 +126,7 @@ impl AssistantPanel {
// TODO: deserialize state. // TODO: deserialize state.
let workspace_handle = workspace.clone(); let workspace_handle = workspace.clone();
workspace.update(&mut cx, |workspace, cx| { workspace.update(&mut cx, |workspace, cx| {
cx.build_view::<Self>(|cx| { cx.new_view::<Self>(|cx| {
const CONVERSATION_WATCH_DURATION: Duration = Duration::from_millis(100); const CONVERSATION_WATCH_DURATION: Duration = Duration::from_millis(100);
let _watch_saved_conversations = cx.spawn(move |this, mut cx| async move { let _watch_saved_conversations = cx.spawn(move |this, mut cx| async move {
let mut events = fs let mut events = fs
@ -147,10 +147,10 @@ impl AssistantPanel {
anyhow::Ok(()) anyhow::Ok(())
}); });
let toolbar = cx.build_view(|cx| { let toolbar = cx.new_view(|cx| {
let mut toolbar = Toolbar::new(); let mut toolbar = Toolbar::new();
toolbar.set_can_navigate(false, cx); 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 toolbar
}); });
@ -306,7 +306,7 @@ impl AssistantPanel {
// Retrieve Credentials Authenticates the Provider // Retrieve Credentials Authenticates the Provider
provider.retrieve_credentials(cx); 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) 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 measurements = Rc::new(Cell::new(BlockMeasurements::default()));
let inline_assistant = cx.build_view(|cx| { let inline_assistant = cx.new_view(|cx| {
InlineAssistant::new( InlineAssistant::new(
inline_assist_id, inline_assist_id,
measurements.clone(), measurements.clone(),
@ -790,7 +790,7 @@ impl AssistantPanel {
} }
fn new_conversation(&mut self, cx: &mut ViewContext<Self>) -> View<ConversationEditor> { fn new_conversation(&mut self, cx: &mut ViewContext<Self>) -> View<ConversationEditor> {
let editor = cx.build_view(|cx| { let editor = cx.new_view(|cx| {
ConversationEditor::new( ConversationEditor::new(
self.completion_provider.clone(), self.completion_provider.clone(),
self.languages.clone(), self.languages.clone(),
@ -1058,7 +1058,7 @@ impl AssistantPanel {
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
let saved_conversation = fs.load(&path).await?; let saved_conversation = fs.load(&path).await?;
let saved_conversation = serde_json::from_str(&saved_conversation)?; 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) Conversation::deserialize(saved_conversation, path.clone(), languages, cx)
})?; })?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
@ -1067,7 +1067,7 @@ impl AssistantPanel {
if let Some(ix) = this.editor_index_for_path(&path, cx) { if let Some(ix) = this.editor_index_for_path(&path, cx) {
this.set_active_editor_index(Some(ix), cx); this.set_active_editor_index(Some(ix), cx);
} else { } else {
let editor = cx.build_view(|cx| { let editor = cx.new_view(|cx| {
ConversationEditor::for_conversation(conversation, fs, workspace, cx) ConversationEditor::for_conversation(conversation, fs, workspace, cx)
}); });
this.add_conversation(editor, cx); this.add_conversation(editor, cx);
@ -1093,7 +1093,7 @@ impl AssistantPanel {
} }
fn build_api_key_editor(cx: &mut ViewContext<AssistantPanel>) -> View<Editor> { fn build_api_key_editor(cx: &mut ViewContext<AssistantPanel>) -> View<Editor> {
cx.build_view(|cx| { cx.new_view(|cx| {
let mut editor = Editor::single_line(cx); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("sk-000000000000000000000000000000000000000000000000", cx); editor.set_placeholder_text("sk-000000000000000000000000000000000000000000000000", cx);
editor editor
@ -1335,7 +1335,7 @@ impl Conversation {
completion_provider: Arc<dyn CompletionProvider>, completion_provider: Arc<dyn CompletionProvider>,
) -> Self { ) -> Self {
let markdown = language_registry.language_for_name("Markdown"); 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(), ""); let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "");
buffer.set_language_registry(language_registry); buffer.set_language_registry(language_registry);
cx.spawn(|buffer, mut cx| async move { cx.spawn(|buffer, mut cx| async move {
@ -1430,7 +1430,7 @@ impl Conversation {
let markdown = language_registry.language_for_name("Markdown"); let markdown = language_registry.language_for_name("Markdown");
let mut message_anchors = Vec::new(); let mut message_anchors = Vec::new();
let mut next_message_id = MessageId(0); 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); let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), saved_conversation.text);
for message in saved_conversation.messages { for message in saved_conversation.messages {
message_anchors.push(MessageAnchor { message_anchors.push(MessageAnchor {
@ -2081,7 +2081,7 @@ impl ConversationEditor {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> Self {
let conversation = 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) Self::for_conversation(conversation, fs, workspace, cx)
} }
@ -2091,7 +2091,7 @@ impl ConversationEditor {
workspace: WeakView<Workspace>, workspace: WeakView<Workspace>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> 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); let mut editor = Editor::for_buffer(conversation.read(cx).buffer.clone(), None, cx);
editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx);
editor.set_show_gutter(false, cx); editor.set_show_gutter(false, cx);
@ -2708,7 +2708,7 @@ impl InlineAssistant {
semantic_index: Option<Model<SemanticIndex>>, semantic_index: Option<Model<SemanticIndex>>,
project: Model<Project>, project: Model<Project>,
) -> Self { ) -> Self {
let prompt_editor = cx.build_view(|cx| { let prompt_editor = cx.new_view(|cx| {
let mut editor = Editor::single_line(cx); let mut editor = Editor::single_line(cx);
let placeholder = match codegen.read(cx).kind() { let placeholder = match codegen.read(cx).kind() {
CodegenKind::Transform { .. } => "Enter transformation prompt…", CodegenKind::Transform { .. } => "Enter transformation prompt…",
@ -3129,8 +3129,7 @@ mod tests {
let registry = Arc::new(LanguageRegistry::test()); let registry = Arc::new(LanguageRegistry::test());
let completion_provider = Arc::new(FakeCompletionProvider::new()); let completion_provider = Arc::new(FakeCompletionProvider::new());
let conversation = let conversation = cx.new_model(|cx| Conversation::new(registry, cx, completion_provider));
cx.build_model(|cx| Conversation::new(registry, cx, completion_provider));
let buffer = conversation.read(cx).buffer.clone(); let buffer = conversation.read(cx).buffer.clone();
let message_1 = conversation.read(cx).message_anchors[0].clone(); let message_1 = conversation.read(cx).message_anchors[0].clone();
@ -3261,8 +3260,7 @@ mod tests {
let registry = Arc::new(LanguageRegistry::test()); let registry = Arc::new(LanguageRegistry::test());
let completion_provider = Arc::new(FakeCompletionProvider::new()); let completion_provider = Arc::new(FakeCompletionProvider::new());
let conversation = let conversation = cx.new_model(|cx| Conversation::new(registry, cx, completion_provider));
cx.build_model(|cx| Conversation::new(registry, cx, completion_provider));
let buffer = conversation.read(cx).buffer.clone(); let buffer = conversation.read(cx).buffer.clone();
let message_1 = conversation.read(cx).message_anchors[0].clone(); let message_1 = conversation.read(cx).message_anchors[0].clone();
@ -3360,8 +3358,7 @@ mod tests {
init(cx); init(cx);
let registry = Arc::new(LanguageRegistry::test()); let registry = Arc::new(LanguageRegistry::test());
let completion_provider = Arc::new(FakeCompletionProvider::new()); let completion_provider = Arc::new(FakeCompletionProvider::new());
let conversation = let conversation = cx.new_model(|cx| Conversation::new(registry, cx, completion_provider));
cx.build_model(|cx| Conversation::new(registry, cx, completion_provider));
let buffer = conversation.read(cx).buffer.clone(); let buffer = conversation.read(cx).buffer.clone();
let message_1 = conversation.read(cx).message_anchors[0].clone(); let message_1 = conversation.read(cx).message_anchors[0].clone();
@ -3446,7 +3443,7 @@ mod tests {
let registry = Arc::new(LanguageRegistry::test()); let registry = Arc::new(LanguageRegistry::test());
let completion_provider = Arc::new(FakeCompletionProvider::new()); let completion_provider = Arc::new(FakeCompletionProvider::new());
let conversation = 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 buffer = conversation.read(cx).buffer.clone();
let message_0 = conversation.read(cx).message_anchors[0].id; let message_0 = conversation.read(cx).message_anchors[0].id;
let message_1 = conversation.update(cx, |conversation, cx| { 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::deserialize(
conversation.read(cx).serialize(cx), conversation.read(cx).serialize(cx),
Default::default(), Default::default(),

View file

@ -395,14 +395,14 @@ mod tests {
} }
"}; "};
let buffer = 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx));
let range = buffer.read_with(cx, |buffer, cx| { let range = buffer.read_with(cx, |buffer, cx| {
let snapshot = buffer.snapshot(cx); let snapshot = buffer.snapshot(cx);
snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(4, 5)) snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(4, 5))
}); });
let provider = Arc::new(FakeCompletionProvider::new()); let provider = Arc::new(FakeCompletionProvider::new());
let codegen = cx.build_model(|cx| { let codegen = cx.new_model(|cx| {
Codegen::new( Codegen::new(
buffer.clone(), buffer.clone(),
CodegenKind::Transform { range }, CodegenKind::Transform { range },
@ -461,14 +461,14 @@ mod tests {
} }
"}; "};
let buffer = 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx));
let position = buffer.read_with(cx, |buffer, cx| { let position = buffer.read_with(cx, |buffer, cx| {
let snapshot = buffer.snapshot(cx); let snapshot = buffer.snapshot(cx);
snapshot.anchor_before(Point::new(1, 6)) snapshot.anchor_before(Point::new(1, 6))
}); });
let provider = Arc::new(FakeCompletionProvider::new()); let provider = Arc::new(FakeCompletionProvider::new());
let codegen = cx.build_model(|cx| { let codegen = cx.new_model(|cx| {
Codegen::new( Codegen::new(
buffer.clone(), buffer.clone(),
CodegenKind::Generate { position }, CodegenKind::Generate { position },
@ -526,14 +526,14 @@ mod tests {
"}\n" // "}\n" //
); );
let buffer = 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx));
let position = buffer.read_with(cx, |buffer, cx| { let position = buffer.read_with(cx, |buffer, cx| {
let snapshot = buffer.snapshot(cx); let snapshot = buffer.snapshot(cx);
snapshot.anchor_before(Point::new(1, 2)) snapshot.anchor_before(Point::new(1, 2))
}); });
let provider = Arc::new(FakeCompletionProvider::new()); let provider = Arc::new(FakeCompletionProvider::new());
let codegen = cx.build_model(|cx| { let codegen = cx.new_model(|cx| {
Codegen::new( Codegen::new(
buffer.clone(), buffer.clone(),
CodegenKind::Generate { position }, CodegenKind::Generate { position },

View file

@ -254,7 +254,7 @@ pub(crate) mod tests {
} }
"}; "};
let buffer = 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(); let snapshot = buffer.read(cx).snapshot();
assert_eq!( assert_eq!(

View file

@ -94,7 +94,7 @@ pub fn init(http_client: Arc<dyn HttpClient>, server_url: String, cx: &mut AppCo
.detach(); .detach();
if let Some(version) = ZED_APP_VERSION.or_else(|| cx.app_metadata().app_version) { 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 updater = AutoUpdater::new(version, http_client, server_url);
let mut update_subscription = AutoUpdateSetting::get_global(cx) let mut update_subscription = AutoUpdateSetting::get_global(cx)
@ -160,7 +160,7 @@ pub fn notify_of_any_new_update(cx: &mut ViewContext<Workspace>) -> Option<()> {
if should_show_notification { if should_show_notification {
workspace.update(&mut cx, |workspace, cx| { workspace.update(&mut cx, |workspace, cx| {
workspace.show_notification(0, cx, |cx| { workspace.show_notification(0, cx, |cx| {
cx.build_view(|_| UpdateNotification::new(version)) cx.new_view(|_| UpdateNotification::new(version))
}); });
updater updater
.read(cx) .read(cx)

View file

@ -24,7 +24,7 @@ pub use room::Room;
pub fn init(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut AppContext) { pub fn init(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut AppContext) {
CallSettings::register(cx); 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); cx.set_global(active_call);
} }

View file

@ -246,7 +246,7 @@ impl Room {
cx.spawn(move |mut cx| async move { cx.spawn(move |mut cx| async move {
let response = client.request(proto::CreateRoom {}).await?; let response = client.request(proto::CreateRoom {}).await?;
let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?; 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( Self::new(
room_proto.id, room_proto.id,
None, None,
@ -343,7 +343,7 @@ impl Room {
mut cx: AsyncAppContext, mut cx: AsyncAppContext,
) -> Result<Model<Self>> { ) -> Result<Model<Self>> {
let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?; 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( Self::new(
room_proto.id, room_proto.id,
response.channel_id, response.channel_id,

View file

@ -61,14 +61,14 @@ impl ChannelBuffer {
.map(language::proto::deserialize_operation) .map(language::proto::deserialize_operation)
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
let buffer = cx.build_model(|_| { let buffer = cx.new_model(|_| {
language::Buffer::remote(response.buffer_id, response.replica_id as u16, base_text) language::Buffer::remote(response.buffer_id, response.replica_id as u16, base_text)
})?; })?;
buffer.update(&mut cx, |buffer, cx| buffer.apply_ops(operations, cx))??; buffer.update(&mut cx, |buffer, cx| buffer.apply_ops(operations, cx))??;
let subscription = client.subscribe_to_entity(channel.id)?; 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.subscribe(&buffer, Self::on_buffer_update).detach();
cx.on_release(Self::release).detach(); cx.on_release(Self::release).detach();
let mut this = Self { let mut this = Self {

View file

@ -99,7 +99,7 @@ impl ChannelChat {
let messages = messages_from_proto(response.messages, &user_store, &mut cx).await?; let messages = messages_from_proto(response.messages, &user_store, &mut cx).await?;
let loaded_all_messages = response.done; let loaded_all_messages = response.done;
Ok(cx.build_model(|cx| { Ok(cx.new_model(|cx| {
cx.on_release(Self::release).detach(); cx.on_release(Self::release).detach();
let mut this = Self { let mut this = Self {
channel_id: channel.id, channel_id: channel.id,

View file

@ -20,7 +20,7 @@ use util::{async_maybe, ResultExt};
pub fn init(client: &Arc<Client>, user_store: Model<UserStore>, cx: &mut AppContext) { pub fn init(client: &Arc<Client>, user_store: Model<UserStore>, cx: &mut AppContext) {
let channel_store = 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); cx.set_global(channel_store);
} }

View file

@ -345,7 +345,7 @@ async fn test_channel_messages(cx: &mut TestAppContext) {
fn init_test(cx: &mut AppContext) -> Model<ChannelStore> { fn init_test(cx: &mut AppContext) -> Model<ChannelStore> {
let http = FakeHttpClient::with_404_response(); let http = FakeHttpClient::with_404_response();
let client = Client::new(http.clone(), cx); 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); let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store); cx.set_global(settings_store);

View file

@ -1579,15 +1579,15 @@ mod tests {
async { Ok(()) } async { Ok(()) }
}, },
); );
let model1 = cx.build_model(|_| TestModel { let model1 = cx.new_model(|_| TestModel {
id: 1, id: 1,
subscription: None, subscription: None,
}); });
let model2 = cx.build_model(|_| TestModel { let model2 = cx.new_model(|_| TestModel {
id: 2, id: 2,
subscription: None, subscription: None,
}); });
let model3 = cx.build_model(|_| TestModel { let model3 = cx.new_model(|_| TestModel {
id: 3, id: 3,
subscription: None, subscription: None,
}); });
@ -1620,7 +1620,7 @@ mod tests {
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx)); let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await; 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_tx1, _done_rx1) = smol::channel::unbounded();
let (done_tx2, mut done_rx2) = smol::channel::unbounded(); let (done_tx2, mut done_rx2) = smol::channel::unbounded();
let subscription1 = client.add_message_handler( 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 client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await; 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 (done_tx, mut done_rx) = smol::channel::unbounded();
let subscription = client.add_message_handler( let subscription = client.add_message_handler(
model.clone().downgrade(), model.clone().downgrade(),

View file

@ -194,7 +194,7 @@ impl FakeServer {
client: Arc<Client>, client: Arc<Client>,
cx: &mut TestAppContext, cx: &mut TestAppContext,
) -> Model<UserStore> { ) -> Model<UserStore> {
let user_store = cx.build_model(|cx| UserStore::new(client, cx)); let user_store = cx.new_model(|cx| UserStore::new(client, cx));
assert_eq!( assert_eq!(
self.receive::<proto::GetUsers>() self.receive::<proto::GetUsers>()
.await .await

View file

@ -209,8 +209,8 @@ impl TestServer {
}); });
let fs = FakeFs::new(cx.executor()); let fs = FakeFs::new(cx.executor());
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 workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
let mut language_registry = LanguageRegistry::test(); let mut language_registry = LanguageRegistry::test();
language_registry.set_executor(cx.executor()); language_registry.set_executor(cx.executor());
let app_state = Arc::new(workspace::AppState { let app_state = Arc::new(workspace::AppState {

View file

@ -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); let mut this = Self::new(project, channel_store, channel_buffer, cx);
this.acknowledge_buffer_version(cx); this.acknowledge_buffer_version(cx);
this this
@ -133,7 +133,7 @@ impl ChannelView {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> Self {
let buffer = channel_buffer.read(cx).buffer(); 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); let mut editor = Editor::for_buffer(buffer, None, cx);
editor.set_collaboration_hub(Box::new(ChannelBufferCollaborationHub( editor.set_collaboration_hub(Box::new(ChannelBufferCollaborationHub(
channel_buffer.clone(), channel_buffer.clone(),
@ -274,7 +274,7 @@ impl Item for ChannelView {
} }
fn clone_on_split(&self, _: WorkspaceId, cx: &mut ViewContext<Self>) -> Option<View<Self>> { fn clone_on_split(&self, _: WorkspaceId, cx: &mut ViewContext<Self>) -> Option<View<Self>> {
Some(cx.build_view(|cx| { Some(cx.new_view(|cx| {
Self::new( Self::new(
self.project.clone(), self.project.clone(),
self.channel_store.clone(), self.channel_store.clone(),

View file

@ -81,18 +81,18 @@ impl ChatPanel {
let channel_store = ChannelStore::global(cx); let channel_store = ChannelStore::global(cx);
let languages = workspace.app_state().languages.clone(); let languages = workspace.app_state().languages.clone();
let input_editor = cx.build_view(|cx| { let input_editor = cx.new_view(|cx| {
MessageEditor::new( MessageEditor::new(
languages.clone(), languages.clone(),
channel_store.clone(), channel_store.clone(),
cx.build_view(|cx| Editor::auto_height(4, cx)), cx.new_view(|cx| Editor::auto_height(4, cx)),
cx, cx,
) )
}); });
let workspace_handle = workspace.weak_handle(); let workspace_handle = workspace.weak_handle();
cx.build_view(|cx: &mut ViewContext<Self>| { cx.new_view(|cx: &mut ViewContext<Self>| {
let view = cx.view().downgrade(); let view = cx.view().downgrade();
let message_list = let message_list =
ListState::new(0, gpui::ListAlignment::Bottom, px(1000.), move |ix, cx| { ListState::new(0, gpui::ListAlignment::Bottom, px(1000.), move |ix, cx| {

View file

@ -219,7 +219,7 @@ mod tests {
MessageEditor::new( MessageEditor::new(
language_registry, language_registry,
ChannelStore::global(cx), ChannelStore::global(cx),
cx.build_view(|cx| Editor::auto_height(4, cx)), cx.new_view(|cx| Editor::auto_height(4, cx)),
cx, cx,
) )
}); });
@ -273,7 +273,7 @@ mod tests {
cx.update(|cx| { cx.update(|cx| {
let http = FakeHttpClient::with_404_response(); let http = FakeHttpClient::with_404_response();
let client = Client::new(http.clone(), cx); 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); let settings = SettingsStore::test(cx);
cx.set_global(settings); cx.set_global(settings);
theme::init(theme::LoadThemes::JustBase, cx); theme::init(theme::LoadThemes::JustBase, cx);

View file

@ -177,8 +177,8 @@ enum ListEntry {
impl CollabPanel { impl CollabPanel {
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
cx.build_view(|cx| { cx.new_view(|cx| {
let filter_editor = cx.build_view(|cx| { let filter_editor = cx.new_view(|cx| {
let mut editor = Editor::single_line(cx); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("Filter...", cx); editor.set_placeholder_text("Filter...", cx);
editor editor
@ -201,7 +201,7 @@ impl CollabPanel {
}) })
.detach(); .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| { cx.subscribe(&channel_name_editor, |this: &mut Self, _, event, cx| {
if let editor::EditorEvent::Blurred = event { if let editor::EditorEvent::Blurred = event {
@ -2118,7 +2118,7 @@ impl CollabPanel {
.flex() .flex()
.w_full() .w_full()
.on_drag(channel.clone(), move |channel, cx| { .on_drag(channel.clone(), move |channel, cx| {
cx.build_view(|_| DraggedChannelView { cx.new_view(|_| DraggedChannelView {
channel: channel.clone(), channel: channel.clone(),
width, width,
}) })

View file

@ -42,7 +42,7 @@ impl ChannelModal {
) -> Self { ) -> Self {
cx.observe(&channel_store, |_, _, cx| cx.notify()).detach(); cx.observe(&channel_store, |_, _, cx| cx.notify()).detach();
let channel_modal = cx.view().downgrade(); let channel_modal = cx.view().downgrade();
let picker = cx.build_view(|cx| { let picker = cx.new_view(|cx| {
Picker::new( Picker::new(
ChannelModalDelegate { ChannelModalDelegate {
channel_modal, channel_modal,

View file

@ -22,7 +22,7 @@ impl ContactFinder {
potential_contacts: Arc::from([]), potential_contacts: Arc::from([]),
selected_index: 0, 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 } Self { picker }
} }

View file

@ -36,7 +36,7 @@ actions!(
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(|workspace: &mut Workspace, cx| { 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) workspace.set_titlebar_item(titlebar_item.into(), cx)
}) })
.detach(); .detach();

View file

@ -87,7 +87,7 @@ impl NotificationPanel {
let user_store = workspace.app_state().user_store.clone(); let user_store = workspace.app_state().user_store.clone();
let workspace_handle = workspace.weak_handle(); let workspace_handle = workspace.weak_handle();
cx.build_view(|cx: &mut ViewContext<Self>| { cx.new_view(|cx: &mut ViewContext<Self>| {
let mut status = client.status(); let mut status = client.status();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
while let Some(_) = status.next().await { while let Some(_) = status.next().await {
@ -503,7 +503,7 @@ impl NotificationPanel {
workspace.dismiss_notification::<NotificationToast>(0, cx); workspace.dismiss_notification::<NotificationToast>(0, cx);
workspace.show_notification(0, cx, |cx| { workspace.show_notification(0, cx, |cx| {
let workspace = cx.view().downgrade(); let workspace = cx.view().downgrade();
cx.build_view(|_| NotificationToast { cx.new_view(|_| NotificationToast {
notification_id, notification_id,
actor, actor,
text, text,

View file

@ -39,7 +39,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
let options = notification_window_options(screen, window_size); let options = notification_window_options(screen, window_size);
let window = cx let window = cx
.open_window(options, |cx| { .open_window(options, |cx| {
cx.build_view(|_| { cx.new_view(|_| {
IncomingCallNotification::new( IncomingCallNotification::new(
incoming_call.clone(), incoming_call.clone(),
app_state.clone(), app_state.clone(),

View file

@ -27,7 +27,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
for screen in cx.displays() { for screen in cx.displays() {
let options = notification_window_options(screen, window_size); let options = notification_window_options(screen, window_size);
let window = cx.open_window(options, |cx| { let window = cx.open_window(options, |cx| {
cx.build_view(|_| { cx.new_view(|_| {
ProjectSharedNotification::new( ProjectSharedNotification::new(
owner.clone(), owner.clone(),
*project_id, *project_id,

View file

@ -69,7 +69,7 @@ impl CommandPalette {
let delegate = let delegate =
CommandPaletteDelegate::new(cx.view().downgrade(), commands, previous_focus_handle); 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 } Self { picker }
} }
} }
@ -394,7 +394,7 @@ mod tests {
let project = Project::test(app_state.fs.clone(), [], cx).await; 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 (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); let mut editor = Editor::single_line(cx);
editor.set_text("abc", cx); editor.set_text("abc", cx);
editor editor

View file

@ -51,7 +51,7 @@ pub fn init(
node_runtime: Arc<dyn NodeRuntime>, node_runtime: Arc<dyn NodeRuntime>,
cx: &mut AppContext, cx: &mut AppContext,
) { ) {
let copilot = cx.build_model({ let copilot = cx.new_model({
let node_runtime = node_runtime.clone(); let node_runtime = node_runtime.clone();
move |cx| Copilot::start(new_server_id, http, node_runtime, cx) 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()); LanguageServer::fake("copilot".into(), Default::default(), cx.to_async());
let http = util::http::FakeHttpClient::create(|_| async { unreachable!() }); let http = util::http::FakeHttpClient::create(|_| async { unreachable!() });
let node_runtime = FakeNodeRuntime::new(); let node_runtime = FakeNodeRuntime::new();
let this = cx.build_model(|cx| Self { let this = cx.new_model(|cx| Self {
server_id: LanguageServerId(0), server_id: LanguageServerId(0),
http: http.clone(), http: http.clone(),
node_runtime, node_runtime,
@ -1033,7 +1033,7 @@ mod tests {
async fn test_buffer_management(cx: &mut TestAppContext) { async fn test_buffer_management(cx: &mut TestAppContext) {
let (copilot, mut lsp) = Copilot::fake(cx); 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()) let buffer_1_uri: lsp::Url = format!("buffer://{}", buffer_1.entity_id().as_u64())
.parse() .parse()
.unwrap(); .unwrap();
@ -1051,7 +1051,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()) let buffer_2_uri: lsp::Url = format!("buffer://{}", buffer_2.entity_id().as_u64())
.parse() .parse()
.unwrap(); .unwrap();

View file

@ -71,7 +71,7 @@ fn create_copilot_auth_window(
display_id: None, display_id: None,
}; };
let window = cx.open_window(window_options, |cx| { let window = cx.open_window(window_options, |cx| {
cx.build_view(|_| CopilotCodeVerification::new(status.clone())) cx.new_view(|_| CopilotCodeVerification::new(status.clone()))
}); });
window window
} }

View file

@ -151,8 +151,8 @@ impl ProjectDiagnosticsEditor {
let focus_in_subscription = let focus_in_subscription =
cx.on_focus_in(&focus_handle, |diagnostics, cx| diagnostics.focus_in(cx)); 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 excerpts = cx.new_model(|cx| MultiBuffer::new(project_handle.read(cx).replica_id()));
let editor = cx.build_view(|cx| { let editor = cx.new_view(|cx| {
let mut editor = let mut editor =
Editor::for_multibuffer(excerpts.clone(), Some(project_handle.clone()), cx); Editor::for_multibuffer(excerpts.clone(), Some(project_handle.clone()), cx);
editor.set_vertical_scroll_margin(5, cx); editor.set_vertical_scroll_margin(5, cx);
@ -194,7 +194,7 @@ impl ProjectDiagnosticsEditor {
workspace.activate_item(&existing, cx); workspace.activate_item(&existing, cx);
} else { } else {
let workspace_handle = cx.view().downgrade(); 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) ProjectDiagnosticsEditor::new(workspace.project().clone(), workspace_handle, cx)
}); });
workspace.add_item(Box::new(diagnostics), cx); workspace.add_item(Box::new(diagnostics), cx);
@ -705,7 +705,7 @@ impl Item for ProjectDiagnosticsEditor {
where where
Self: Sized, Self: Sized,
{ {
Some(cx.build_view(|cx| { Some(cx.new_view(|cx| {
ProjectDiagnosticsEditor::new(self.project.clone(), self.workspace.clone(), cx) ProjectDiagnosticsEditor::new(self.project.clone(), self.workspace.clone(), cx)
})) }))
} }
@ -778,7 +778,7 @@ impl Item for ProjectDiagnosticsEditor {
_item_id: workspace::ItemId, _item_id: workspace::ItemId,
cx: &mut ViewContext<Pane>, cx: &mut ViewContext<Pane>,
) -> Task<Result<View<Self>>> { ) -> Task<Result<View<Self>>> {
Task::ready(Ok(cx.build_view(|cx| Self::new(project, workspace, cx)))) Task::ready(Ok(cx.new_view(|cx| Self::new(project, workspace, cx))))
} }
} }

View file

@ -1046,7 +1046,7 @@ pub mod tests {
} }
}); });
let map = cx.build_model(|cx| { let map = cx.new_model(|cx| {
DisplayMap::new( DisplayMap::new(
buffer.clone(), buffer.clone(),
font("Helvetica"), font("Helvetica"),
@ -1286,7 +1286,7 @@ pub mod tests {
let text = "one two three four five\nsix seven eight"; let text = "one two three four five\nsix seven eight";
let buffer = MultiBuffer::build_simple(text, cx); let buffer = MultiBuffer::build_simple(text, cx);
let map = cx.build_model(|cx| { let map = cx.new_model(|cx| {
DisplayMap::new( DisplayMap::new(
buffer.clone(), buffer.clone(),
font("Helvetica"), font("Helvetica"),
@ -1393,7 +1393,7 @@ pub mod tests {
let buffer = MultiBuffer::build_simple(&text, cx); let buffer = MultiBuffer::build_simple(&text, cx);
let font_size = px(14.0); 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) 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()))); 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) Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
}); });
cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; 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 font_size = px(14.0);
let map = cx.build_model(|cx| { let map = cx
DisplayMap::new(buffer, font("Helvetica"), font_size, None, 1, 1, cx) .new_model(|cx| DisplayMap::new(buffer, font("Helvetica"), font_size, None, 1, 1, cx));
});
assert_eq!( assert_eq!(
cx.update(|cx| syntax_chunks(0..5, &map, &theme, cx)), cx.update(|cx| syntax_chunks(0..5, &map, &theme, cx)),
vec![ vec![
@ -1551,15 +1550,15 @@ pub mod tests {
cx.update(|cx| init_test(cx, |_| {})); 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) Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
}); });
cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; 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 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) DisplayMap::new(buffer, font("Courier"), font_size, Some(px(40.0)), 1, 1, cx)
}); });
assert_eq!( assert_eq!(
@ -1618,17 +1617,17 @@ pub mod tests {
let (text, highlighted_ranges) = marked_text_ranges(r#"constˇ «a»: B = "c «d»""#, false); 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) Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
}); });
cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; 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 buffer_snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx));
let font_size = px(16.0); let font_size = px(16.0);
let map = cx let map =
.build_model(|cx| DisplayMap::new(buffer, font("Courier"), font_size, None, 1, 1, cx)); cx.new_model(|cx| DisplayMap::new(buffer, font("Courier"), font_size, None, 1, 1, cx));
enum MyType {} enum MyType {}
@ -1742,7 +1741,7 @@ pub mod tests {
let buffer = MultiBuffer::build_simple(text, cx); let buffer = MultiBuffer::build_simple(text, cx);
let font_size = px(14.0); 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) DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx)
}); });
let map = map.update(cx, |map, cx| map.snapshot(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 buffer = MultiBuffer::build_simple("aaa\n\t\tbbb", cx);
let font_size = px(14.0); 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) DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx)
}); });
assert_eq!( assert_eq!(

View file

@ -74,7 +74,7 @@ impl WrapMap {
wrap_width: Option<Pixels>, wrap_width: Option<Pixels>,
cx: &mut AppContext, cx: &mut AppContext,
) -> (Model<Self>, WrapSnapshot) { ) -> (Model<Self>, WrapSnapshot) {
let handle = cx.build_model(|cx| { let handle = cx.new_model(|cx| {
let mut this = Self { let mut this = Self {
font_with_size: (font, font_size), font_with_size: (font, font_size),
wrap_width: None, wrap_width: None,

View file

@ -1637,20 +1637,20 @@ impl InlayHintRefreshReason {
impl Editor { impl Editor {
pub fn single_line(cx: &mut ViewContext<Self>) -> Self { pub fn single_line(cx: &mut ViewContext<Self>) -> Self {
let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); let buffer = cx.new_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| MultiBuffer::singleton(buffer, cx));
Self::new(EditorMode::SingleLine, buffer, None, cx) Self::new(EditorMode::SingleLine, buffer, None, cx)
} }
pub fn multi_line(cx: &mut ViewContext<Self>) -> Self { pub fn multi_line(cx: &mut ViewContext<Self>) -> Self {
let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); let buffer = cx.new_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| MultiBuffer::singleton(buffer, cx));
Self::new(EditorMode::Full, buffer, None, cx) Self::new(EditorMode::Full, buffer, None, cx)
} }
pub fn auto_height(max_lines: usize, cx: &mut ViewContext<Self>) -> Self { pub fn auto_height(max_lines: usize, cx: &mut ViewContext<Self>) -> Self {
let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); let buffer = cx.new_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| MultiBuffer::singleton(buffer, cx));
Self::new(EditorMode::AutoHeight { max_lines }, buffer, None, cx) Self::new(EditorMode::AutoHeight { max_lines }, buffer, None, cx)
} }
@ -1659,7 +1659,7 @@ impl Editor {
project: Option<Model<Project>>, project: Option<Model<Project>>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> 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) Self::new(EditorMode::Full, buffer, project, cx)
} }
@ -1693,13 +1693,13 @@ impl Editor {
) -> Self { ) -> Self {
let style = cx.text_style(); let style = cx.text_style();
let font_size = style.font_size.to_pixels(cx.rem_size()); 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) DisplayMap::new(buffer.clone(), style.font(), font_size, None, 2, 1, cx)
}); });
let selections = SelectionsCollection::new(display_map.clone(), buffer.clone()); 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 = let soft_wrap_mode_override =
(mode == EditorMode::SingleLine).then(|| language_settings::SoftWrap::None); (mode == EditorMode::SingleLine).then(|| language_settings::SoftWrap::None);
@ -1881,7 +1881,7 @@ impl Editor {
.log_err() .log_err()
{ {
workspace.add_item( 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, cx,
); );
} }
@ -1901,7 +1901,7 @@ impl Editor {
{ {
workspace.split_item( workspace.split_item(
action.0, 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, cx,
); );
} }
@ -3787,7 +3787,7 @@ impl Editor {
} }
let mut ranges_to_highlight = Vec::new(); 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); let mut multibuffer = MultiBuffer::new(replica_id).with_title(title);
for (buffer_handle, transaction) in &entries { for (buffer_handle, transaction) in &entries {
let buffer = buffer_handle.read(cx); let buffer = buffer_handle.read(cx);
@ -3809,7 +3809,7 @@ impl Editor {
workspace.update(&mut cx, |workspace, cx| { workspace.update(&mut cx, |workspace, cx| {
let project = workspace.project().clone(); let project = workspace.project().clone();
let editor = 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); workspace.add_item(Box::new(editor.clone()), cx);
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.highlight_background::<Self>( editor.highlight_background::<Self>(
@ -7494,7 +7494,7 @@ impl Editor {
let mut locations = locations.into_iter().peekable(); let mut locations = locations.into_iter().peekable();
let mut ranges_to_highlight = Vec::new(); 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); let mut multibuffer = MultiBuffer::new(replica_id);
while let Some(location) = locations.next() { while let Some(location) = locations.next() {
let buffer = location.buffer.read(cx); let buffer = location.buffer.read(cx);
@ -7523,7 +7523,7 @@ impl Editor {
multibuffer.with_title(title) 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::for_multibuffer(excerpt_buffer, Some(workspace.project().clone()), cx)
}); });
editor.update(cx, |editor, 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. // Position the selection in the rename editor so that it matches the current selection.
this.show_local_selections = false; 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); let mut editor = Editor::single_line(cx);
editor.buffer.update(cx, |buffer, cx| { editor.buffer.update(cx, |buffer, cx| {
buffer.edit([(0..0, old_name.clone())], None, cx) buffer.edit([(0..0, old_name.clone())], None, cx)

View file

@ -40,7 +40,7 @@ use workspace::{
fn test_edit_events(cx: &mut TestAppContext) { fn test_edit_events(cx: &mut TestAppContext) {
init_test(cx, |_| {}); 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"); let mut buffer = language::Buffer::new(0, cx.entity_id().as_u64(), "123456");
buffer.set_group_interval(Duration::from_secs(1)); buffer.set_group_interval(Duration::from_secs(1));
buffer buffer
@ -156,9 +156,9 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});
let mut now = Instant::now(); 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 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)); let editor = cx.add_window(|cx| build_editor(buffer.clone(), cx));
_ = editor.update(cx, |editor, 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) { fn test_ime_composition(cx: &mut TestAppContext) {
init_test(cx, |_| {}); 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"); let mut buffer = language::Buffer::new(0, cx.entity_id().as_u64(), "abcde");
// Ensure automatic grouping doesn't occur. // Ensure automatic grouping doesn't occur.
buffer.set_group_interval(Duration::ZERO); buffer.set_group_interval(Duration::ZERO);
buffer 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| { cx.add_window(|cx| {
let mut editor = build_editor(buffer.clone(), cx); let mut editor = build_editor(buffer.clone(), cx);
@ -504,9 +504,7 @@ fn test_clone(cx: &mut TestAppContext) {
let cloned_editor = editor let cloned_editor = editor
.update(cx, |editor, cx| { .update(cx, |editor, cx| {
cx.open_window(Default::default(), |cx| { cx.open_window(Default::default(), |cx| cx.new_view(|cx| editor.clone(cx)))
cx.build_view(|cx| editor.clone(cx))
})
}) })
.unwrap(); .unwrap();
@ -558,7 +556,7 @@ async fn test_navigation_history(cx: &mut TestAppContext) {
.unwrap(); .unwrap();
_ = workspace.update(cx, |_v, cx| { _ = 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 buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx);
let mut editor = build_editor(buffer.clone(), cx); let mut editor = build_editor(buffer.clone(), cx);
let handle = cx.view(); let handle = cx.view();
@ -2349,14 +2347,14 @@ fn test_indent_outdent_with_excerpts(cx: &mut TestAppContext) {
None, 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) 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") Buffer::new(0, cx.entity_id().as_u64(), "const c: usize = 3;\n")
.with_language(rust_language, cx) .with_language(rust_language, cx)
}); });
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
toml_buffer.clone(), toml_buffer.clone(),
@ -3907,10 +3905,9 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
"# "#
.unindent(); .unindent();
let buffer = cx.build_model(|cx| { let buffer = cx
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
view.condition::<crate::EditorEvent>(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) view.condition::<crate::EditorEvent>(&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 text = "fn a() {}";
let buffer = cx.build_model(|cx| { let buffer = cx
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
editor editor
.condition::<crate::EditorEvent>(cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx)) .condition::<crate::EditorEvent>(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(); .unindent();
let buffer = cx.build_model(|cx| { let buffer = cx
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
view.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) view.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await; .await;
@ -4788,10 +4783,9 @@ async fn test_delete_autoclose_pair(cx: &mut gpui::TestAppContext) {
"# "#
.unindent(); .unindent();
let buffer = cx.build_model(|cx| { let buffer = cx
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
editor editor
.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) .condition::<crate::EditorEvent>(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(); cx.executor().start_waiting();
let fake_server = fake_servers.next().await.unwrap(); 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)); 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)); _ = editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));
assert!(cx.read(|cx| editor.is_dirty(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(); cx.executor().start_waiting();
let fake_server = fake_servers.next().await.unwrap(); 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)); 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)); _ = editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));
assert!(cx.read(|cx| editor.is_dirty(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(); cx.executor().start_waiting();
let fake_server = fake_servers.next().await.unwrap(); 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)); 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)); _ = 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) { fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});
let buffer = let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a')));
cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a'))); let multibuffer = cx.new_model(|cx| {
let multibuffer = cx.build_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
buffer.clone(), buffer.clone(),
@ -6108,8 +6101,8 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) {
primary: None, primary: None,
} }
}); });
let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), initial_text)); let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), initial_text));
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts(buffer, excerpt_ranges, cx); multibuffer.push_excerpts(buffer, excerpt_ranges, cx);
multibuffer multibuffer
@ -6166,10 +6159,9 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) {
fn test_refresh_selections(cx: &mut TestAppContext) { fn test_refresh_selections(cx: &mut TestAppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});
let buffer = let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a')));
cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a')));
let mut excerpt1_id = None; let mut excerpt1_id = None;
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
excerpt1_id = multibuffer excerpt1_id = multibuffer
.push_excerpts( .push_excerpts(
@ -6252,10 +6244,9 @@ fn test_refresh_selections(cx: &mut TestAppContext) {
fn test_refresh_selections_while_selecting_with_mouse(cx: &mut TestAppContext) { fn test_refresh_selections_while_selecting_with_mouse(cx: &mut TestAppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});
let buffer = let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a')));
cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(3, 4, 'a')));
let mut excerpt1_id = None; let mut excerpt1_id = None;
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
excerpt1_id = multibuffer excerpt1_id = multibuffer
.push_excerpts( .push_excerpts(
@ -6348,10 +6339,9 @@ async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) {
"{{} }\n", // "{{} }\n", //
); );
let buffer = cx.build_model(|cx| { let buffer = cx
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, 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 buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx)); let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
view.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx)) view.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
.await; .await;
@ -6479,7 +6469,7 @@ async fn test_following(cx: &mut gpui::TestAppContext) {
let buffer = project let buffer = project
.create_buffer(&sample_text(16, 8, 'a'), None, cx) .create_buffer(&sample_text(16, 8, 'a'), None, cx)
.unwrap(); .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 leader = cx.add_window(|cx| build_editor(buffer.clone(), cx));
let follower = cx.update(|cx| { let follower = cx.update(|cx| {
@ -6491,7 +6481,7 @@ async fn test_following(cx: &mut gpui::TestAppContext) {
)), )),
..Default::default() ..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 cx = &mut VisualTestContext::from_window(*workspace.deref(), cx);
let leader = pane.update(cx, |_, cx| { let leader = pane.update(cx, |_, cx| {
let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let multibuffer = cx.new_model(|_| MultiBuffer::new(0));
cx.build_view(|cx| build_editor(multibuffer.clone(), cx)) cx.new_view(|cx| build_editor(multibuffer.clone(), cx))
}); });
// Start following the editor when it has no excerpts. // 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); let (copilot, copilot_lsp) = Copilot::fake(cx);
_ = cx.update(|cx| cx.set_global(copilot)); _ = 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_1 = cx.new_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 buffer_2 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "c = 3\nd = 4\n"));
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
buffer_1.clone(), buffer_1.clone(),
@ -7561,7 +7551,7 @@ async fn test_copilot_disabled_globs(executor: BackgroundExecutor, cx: &mut gpui
.await .await
.unwrap(); .unwrap();
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
private_buffer.clone(), private_buffer.clone(),
@ -8091,7 +8081,7 @@ async fn test_document_format_with_prettier(cx: &mut gpui::TestAppContext) {
.unwrap(); .unwrap();
let buffer_text = "one\ntwo\nthree\n"; 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)); let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
_ = editor.update(cx, |editor, cx| editor.set_text(buffer_text, cx)); _ = editor.update(cx, |editor, cx| editor.set_text(buffer_text, cx));

View file

@ -182,7 +182,7 @@ mod tests {
cx.background_executor.run_until_parked(); cx.background_executor.run_until_parked();
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
buffer_1.clone(), buffer_1.clone(),

View file

@ -2458,7 +2458,7 @@ pub mod tests {
}) })
.await .await
.unwrap(); .unwrap();
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
buffer_1.clone(), buffer_1.clone(),
@ -2798,7 +2798,7 @@ pub mod tests {
}) })
.await .await
.unwrap(); .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, buffer_2_excerpts) = multibuffer.update(cx, |multibuffer, cx| {
let buffer_1_excerpts = multibuffer.push_excerpts( let buffer_1_excerpts = multibuffer.push_excerpts(
buffer_1.clone(), buffer_1.clone(),

View file

@ -96,7 +96,7 @@ impl FollowableItem for Editor {
editor editor
} else { } else {
pane.update(&mut cx, |_, cx| { pane.update(&mut cx, |_, cx| {
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer; let mut multibuffer;
if state.singleton && buffers.len() == 1 { if state.singleton && buffers.len() == 1 {
multibuffer = MultiBuffer::singleton(buffers.pop().unwrap(), cx) multibuffer = MultiBuffer::singleton(buffers.pop().unwrap(), cx)
@ -129,7 +129,7 @@ impl FollowableItem for Editor {
multibuffer multibuffer
}); });
cx.build_view(|cx| { cx.new_view(|cx| {
let mut editor = let mut editor =
Editor::for_multibuffer(multibuffer, Some(project.clone()), cx); Editor::for_multibuffer(multibuffer, Some(project.clone()), cx);
editor.remote_id = Some(remote_id); editor.remote_id = Some(remote_id);
@ -632,7 +632,7 @@ impl Item for Editor {
where where
Self: Sized, 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<Self>) { fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
@ -911,7 +911,7 @@ impl Item for Editor {
.downcast::<Buffer>() .downcast::<Buffer>()
.map_err(|_| anyhow!("Project item at stored path was not a buffer"))?; .map_err(|_| anyhow!("Project item at stored path was not a buffer"))?;
Ok(pane.update(&mut cx, |_, cx| { Ok(pane.update(&mut cx, |_, cx| {
cx.build_view(|cx| { cx.new_view(|cx| {
let mut editor = Editor::for_buffer(buffer, Some(project), cx); let mut editor = Editor::for_buffer(buffer, Some(project), cx);
editor.read_scroll_position_from_db(item_id, workspace_id, cx); editor.read_scroll_position_from_db(item_id, workspace_id, cx);

View file

@ -576,7 +576,7 @@ mod tests {
let buffer = MultiBuffer::build_simple(input_text, cx); let buffer = MultiBuffer::build_simple(input_text, cx);
let buffer_snapshot = buffer.read(cx).snapshot(cx); let buffer_snapshot = buffer.read(cx).snapshot(cx);
let display_map = 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 // 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; let mut id = 0;
@ -763,9 +763,9 @@ mod tests {
let font = font("Helvetica"); let font = font("Helvetica");
let buffer = cx let buffer =
.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abc\ndefg\nhijkl\nmn")); cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abc\ndefg\nhijkl\nmn"));
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
buffer.clone(), buffer.clone(),
@ -784,7 +784,7 @@ mod tests {
multibuffer multibuffer
}); });
let display_map = 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)); let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\nhijkl\nmn"); assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\nhijkl\nmn");

View file

@ -102,11 +102,11 @@ pub fn expand_macro_recursively(
project.create_buffer(&macro_expansion.expansion, Some(rust_language), cx) project.create_buffer(&macro_expansion.expansion, Some(rust_language), cx)
})??; })??;
workspace.update(&mut cx, |workspace, 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) MultiBuffer::singleton(buffer, cx).with_title(macro_expansion.name)
}); });
workspace.add_item( 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, cx,
); );
}) })

View file

@ -30,7 +30,7 @@ pub fn marked_display_snapshot(
let font_size: Pixels = 14usize.into(); let font_size: Pixels = 14usize.into();
let buffer = MultiBuffer::build_simple(&unmarked_text, cx); 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 snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
let markers = markers let markers = markers
.into_iter() .into_iter()

View file

@ -154,7 +154,7 @@ impl FeedbackModal {
buffer: Model<Buffer>, buffer: Model<Buffer>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> Self {
let email_address_editor = cx.build_view(|cx| { let email_address_editor = cx.new_view(|cx| {
let mut editor = Editor::single_line(cx); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("Email address (optional)", cx); editor.set_placeholder_text("Email address (optional)", cx);
@ -169,7 +169,7 @@ impl FeedbackModal {
let placeholder_text = let placeholder_text =
"You can use markdown to organize your feedback with code and links."; "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); let mut editor = Editor::for_buffer(buffer, Some(project.clone()), cx);
editor.set_placeholder_text(placeholder_text, cx); editor.set_placeholder_text(placeholder_text, cx);
// editor.set_show_gutter(false, cx); // editor.set_show_gutter(false, cx);

View file

@ -106,7 +106,7 @@ impl FileFinder {
fn new(delegate: FileFinderDelegate, cx: &mut ViewContext<Self>) -> Self { fn new(delegate: FileFinderDelegate, cx: &mut ViewContext<Self>) -> Self {
Self { Self {
picker: cx.build_view(|cx| Picker::new(delegate, cx)), picker: cx.new_view(|cx| Picker::new(delegate, cx)),
} }
} }
} }

View file

@ -49,7 +49,7 @@ impl GoToLine {
} }
pub fn new(active_editor: View<Editor>, cx: &mut ViewContext<Self>) -> Self { pub fn new(active_editor: View<Editor>, cx: &mut ViewContext<Self>) -> 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 line_editor_change = cx.subscribe(&line_editor, Self::on_line_editor_event);
let editor = active_editor.read(cx); let editor = active_editor.read(cx);

View file

@ -1105,7 +1105,7 @@ impl Context for AppContext {
/// Build an entity that is owned by the application. The given function will be invoked with /// 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 /// 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. /// which can be used to access the entity in a context.
fn build_model<T: 'static>( fn new_model<T: 'static>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Model<T> { ) -> Model<T> {

View file

@ -17,7 +17,7 @@ pub struct AsyncAppContext {
impl Context for AsyncAppContext { impl Context for AsyncAppContext {
type Result<T> = Result<T>; type Result<T> = Result<T>;
fn build_model<T: 'static>( fn new_model<T: 'static>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Self::Result<Model<T>> ) -> Self::Result<Model<T>>
@ -29,7 +29,7 @@ impl Context for AsyncAppContext {
.upgrade() .upgrade()
.ok_or_else(|| anyhow!("app was released"))?; .ok_or_else(|| anyhow!("app was released"))?;
let mut app = app.borrow_mut(); let mut app = app.borrow_mut();
Ok(app.build_model(build_model)) Ok(app.new_model(build_model))
} }
fn update_model<T: 'static, R>( fn update_model<T: 'static, R>(
@ -230,15 +230,14 @@ impl AsyncWindowContext {
impl Context for AsyncWindowContext { impl Context for AsyncWindowContext {
type Result<T> = Result<T>; type Result<T> = Result<T>;
fn build_model<T>( fn new_model<T>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Result<Model<T>> ) -> Result<Model<T>>
where where
T: 'static, T: 'static,
{ {
self.window self.window.update(self, |_, cx| cx.new_model(build_model))
.update(self, |_, cx| cx.build_model(build_model))
} }
fn update_model<T: 'static, R>( fn update_model<T: 'static, R>(
@ -281,7 +280,7 @@ impl Context for AsyncWindowContext {
} }
impl VisualContext for AsyncWindowContext { impl VisualContext for AsyncWindowContext {
fn build_view<V>( fn new_view<V>(
&mut self, &mut self,
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V, build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>> ) -> Self::Result<View<V>>
@ -289,7 +288,7 @@ impl VisualContext for AsyncWindowContext {
V: 'static + Render, V: 'static + Render,
{ {
self.window self.window
.update(self, |_, cx| cx.build_view(build_view_state)) .update(self, |_, cx| cx.new_view(build_view_state))
} }
fn update_view<V: 'static, R>( fn update_view<V: 'static, R>(

View file

@ -215,11 +215,11 @@ impl<'a, T> ModelContext<'a, T> {
impl<'a, T> Context for ModelContext<'a, T> { impl<'a, T> Context for ModelContext<'a, T> {
type Result<U> = U; type Result<U> = U;
fn build_model<U: 'static>( fn new_model<U: 'static>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, U>) -> U, build_model: impl FnOnce(&mut ModelContext<'_, U>) -> U,
) -> Model<U> { ) -> Model<U> {
self.app.build_model(build_model) self.app.new_model(build_model)
} }
fn update_model<U: 'static, R>( fn update_model<U: 'static, R>(

View file

@ -23,7 +23,7 @@ pub struct TestAppContext {
impl Context for TestAppContext { impl Context for TestAppContext {
type Result<T> = T; type Result<T> = T;
fn build_model<T: 'static>( fn new_model<T: 'static>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Self::Result<Model<T>> ) -> Self::Result<Model<T>>
@ -31,7 +31,7 @@ impl Context for TestAppContext {
T: 'static, T: 'static,
{ {
let mut app = self.app.borrow_mut(); let mut app = self.app.borrow_mut();
app.build_model(build_model) app.new_model(build_model)
} }
fn update_model<T: 'static, R>( fn update_model<T: 'static, R>(
@ -134,15 +134,13 @@ impl TestAppContext {
V: 'static + Render, V: 'static + Render,
{ {
let mut cx = self.app.borrow_mut(); 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 { pub fn add_empty_window(&mut self) -> AnyWindowHandle {
let mut cx = self.app.borrow_mut(); let mut cx = self.app.borrow_mut();
cx.open_window(WindowOptions::default(), |cx| { cx.open_window(WindowOptions::default(), |cx| cx.new_view(|_| EmptyView {}))
cx.build_view(|_| EmptyView {}) .any_handle
})
.any_handle
} }
pub fn add_window_view<F, V>(&mut self, build_window: F) -> (View<V>, &mut VisualTestContext) pub fn add_window_view<F, V>(&mut self, build_window: F) -> (View<V>, &mut VisualTestContext)
@ -151,7 +149,7 @@ impl TestAppContext {
V: 'static + Render, V: 'static + Render,
{ {
let mut cx = self.app.borrow_mut(); 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); drop(cx);
let view = window.root_view(self).unwrap(); let view = window.root_view(self).unwrap();
let cx = Box::new(VisualTestContext::from_window(*window.deref(), self)); let cx = Box::new(VisualTestContext::from_window(*window.deref(), self));
@ -617,11 +615,11 @@ impl<'a> VisualTestContext<'a> {
impl<'a> Context for VisualTestContext<'a> { impl<'a> Context for VisualTestContext<'a> {
type Result<T> = <TestAppContext as Context>::Result<T>; type Result<T> = <TestAppContext as Context>::Result<T>;
fn build_model<T: 'static>( fn new_model<T: 'static>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Self::Result<Model<T>> { ) -> Self::Result<Model<T>> {
self.cx.build_model(build_model) self.cx.new_model(build_model)
} }
fn update_model<T, R>( fn update_model<T, R>(
@ -666,7 +664,7 @@ impl<'a> Context for VisualTestContext<'a> {
} }
impl<'a> VisualContext for VisualTestContext<'a> { impl<'a> VisualContext for VisualTestContext<'a> {
fn build_view<V>( fn new_view<V>(
&mut self, &mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V, build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>> ) -> Self::Result<View<V>>
@ -674,7 +672,7 @@ impl<'a> VisualContext for VisualTestContext<'a> {
V: 'static + Render, V: 'static + Render,
{ {
self.window self.window
.update(self.cx, |_, cx| cx.build_view(build_view)) .update(self.cx, |_, cx| cx.new_view(build_view))
.unwrap() .unwrap()
} }
@ -726,7 +724,7 @@ impl AnyWindowHandle {
cx: &mut TestAppContext, cx: &mut TestAppContext,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V, build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
) -> View<V> { ) -> View<V> {
self.update(cx, |_, cx| cx.build_view(build_view)).unwrap() self.update(cx, |_, cx| cx.new_view(build_view)).unwrap()
} }
} }

View file

@ -85,7 +85,7 @@ use taffy::TaffyLayoutEngine;
pub trait Context { pub trait Context {
type Result<T>; type Result<T>;
fn build_model<T: 'static>( fn new_model<T: 'static>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Self::Result<Model<T>>; ) -> Self::Result<Model<T>>;
@ -120,7 +120,7 @@ pub trait Context {
} }
pub trait VisualContext: Context { pub trait VisualContext: Context {
fn build_view<V>( fn new_view<V>(
&mut self, &mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V, build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>> ) -> Self::Result<View<V>>

View file

@ -327,7 +327,7 @@ mod test {
fn test_on_events(cx: &mut TestAppContext) { fn test_on_events(cx: &mut TestAppContext) {
let window = cx.update(|cx| { let window = cx.update(|cx| {
cx.open_window(Default::default(), |cx| { cx.open_window(Default::default(), |cx| {
cx.build_view(|cx| TestView { cx.new_view(|cx| TestView {
saw_key_down: false, saw_key_down: false,
saw_action: false, saw_action: false,
focus_handle: cx.focus_handle(), focus_handle: cx.focus_handle(),

View file

@ -1463,7 +1463,7 @@ impl<'a> WindowContext<'a> {
if self.active_drag.is_none() { if self.active_drag.is_none() {
self.active_drag = Some(AnyDrag { self.active_drag = Some(AnyDrag {
value: Box::new(files.clone()), value: Box::new(files.clone()),
view: self.build_view(|_| files).into(), view: self.new_view(|_| files).into(),
cursor_offset: position, cursor_offset: position,
}); });
} }
@ -1842,10 +1842,7 @@ impl<'a> WindowContext<'a> {
impl Context for WindowContext<'_> { impl Context for WindowContext<'_> {
type Result<T> = T; type Result<T> = T;
fn build_model<T>( fn new_model<T>(&mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T) -> Model<T>
&mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Model<T>
where where
T: 'static, T: 'static,
{ {
@ -1916,7 +1913,7 @@ impl Context for WindowContext<'_> {
} }
impl VisualContext for WindowContext<'_> { impl VisualContext for WindowContext<'_> {
fn build_view<V>( fn new_view<V>(
&mut self, &mut self,
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V, build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>> ) -> Self::Result<View<V>>
@ -1962,7 +1959,7 @@ impl VisualContext for WindowContext<'_> {
where where
V: 'static + Render, 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.window.root_view = Some(view.clone().into());
self.notify(); self.notify();
view view
@ -2728,11 +2725,11 @@ impl<'a, V: 'static> ViewContext<'a, V> {
impl<V> Context for ViewContext<'_, V> { impl<V> Context for ViewContext<'_, V> {
type Result<U> = U; type Result<U> = U;
fn build_model<T: 'static>( fn new_model<T: 'static>(
&mut self, &mut self,
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
) -> Model<T> { ) -> Model<T> {
self.window_cx.build_model(build_model) self.window_cx.new_model(build_model)
} }
fn update_model<T: 'static, R>( fn update_model<T: 'static, R>(
@ -2774,11 +2771,11 @@ impl<V> Context for ViewContext<'_, V> {
} }
impl<V: 'static> VisualContext for ViewContext<'_, V> { impl<V: 'static> VisualContext for ViewContext<'_, V> {
fn build_view<W: Render + 'static>( fn new_view<W: Render + 'static>(
&mut self, &mut self,
build_view_state: impl FnOnce(&mut ViewContext<'_, W>) -> W, build_view_state: impl FnOnce(&mut ViewContext<'_, W>) -> W,
) -> Self::Result<View<W>> { ) -> Self::Result<View<W>> {
self.window_cx.build_view(build_view_state) self.window_cx.new_view(build_view_state)
} }
fn update_view<V2: 'static, R>( fn update_view<V2: 'static, R>(

View file

@ -42,7 +42,7 @@ fn init_logger() {
fn test_line_endings(cx: &mut gpui::AppContext) { fn test_line_endings(cx: &mut gpui::AppContext) {
init_settings(cx, |_| {}); 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") let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "one\r\ntwo\rthree")
.with_language(Arc::new(rust_lang()), cx); .with_language(Arc::new(rust_lang()), cx);
assert_eq!(buffer.text(), "one\ntwo\nthree"); 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_1_events = Arc::new(Mutex::new(Vec::new()));
let buffer_2_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 buffer1 = cx.new_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 buffer2 = cx.new_model(|cx| Buffer::new(1, cx.entity_id().as_u64(), "abcdef"));
let buffer1_ops = Arc::new(Mutex::new(Vec::new())); let buffer1_ops = Arc::new(Mutex::new(Vec::new()));
buffer1.update(cx, { buffer1.update(cx, {
let buffer1_ops = buffer1_ops.clone(); let buffer1_ops = buffer1_ops.clone();
@ -218,7 +218,7 @@ fn test_edit_events(cx: &mut gpui::AppContext) {
#[gpui::test] #[gpui::test]
async fn test_apply_diff(cx: &mut TestAppContext) { async fn test_apply_diff(cx: &mut TestAppContext) {
let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n"; 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 anchor = buffer.update(cx, |buffer, _| buffer.anchor_before(Point::new(3, 3)));
let text = "a\nccc\ndddd\nffffff\n"; let text = "a\nccc\ndddd\nffffff\n";
@ -250,7 +250,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
] ]
.join("\n"); .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. // Spawn a task to format the buffer's whitespace.
// Pause so that the foratting task starts running. // Pause so that the foratting task starts running.
@ -314,7 +314,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
#[gpui::test] #[gpui::test]
async fn test_reparse(cx: &mut gpui::TestAppContext) { async fn test_reparse(cx: &mut gpui::TestAppContext) {
let text = "fn a() {}"; 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) 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] #[gpui::test]
async fn test_resetting_language(cx: &mut gpui::TestAppContext) { async fn test_resetting_language(cx: &mut gpui::TestAppContext) {
let buffer = cx.build_model(|cx| { let buffer = cx.new_model(|cx| {
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), "{}").with_language(Arc::new(rust_lang()), cx); Buffer::new(0, cx.entity_id().as_u64(), "{}").with_language(Arc::new(rust_lang()), cx);
buffer.set_sync_parse_timeout(Duration::ZERO); buffer.set_sync_parse_timeout(Duration::ZERO);
@ -492,7 +492,7 @@ async fn test_outline(cx: &mut gpui::TestAppContext) {
"# "#
.unindent(); .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) Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx)
}); });
let outline = buffer let outline = buffer
@ -578,7 +578,7 @@ async fn test_outline_nodes_with_newlines(cx: &mut gpui::TestAppContext) {
"# "#
.unindent(); .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) Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx)
}); });
let outline = buffer let outline = buffer
@ -616,7 +616,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) {
"# "#
.unindent(); .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) Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(language), cx)
}); });
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot()); let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
@ -660,7 +660,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
"# "#
.unindent(); .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) Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx)
}); });
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot()); 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] #[gpui::test]
fn test_range_for_syntax_ancestor(cx: &mut AppContext) { fn test_range_for_syntax_ancestor(cx: &mut AppContext) {
cx.build_model(|cx| { cx.new_model(|cx| {
let text = "fn a() { b(|c| {}) }"; let text = "fn a() { b(|c| {}) }";
let buffer = let buffer =
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); 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) { fn test_autoindent_with_soft_tabs(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let text = "fn a() {}"; let text = "fn a() {}";
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); 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); settings.defaults.hard_tabs = Some(true);
}); });
cx.build_model(|cx| { cx.new_model(|cx| {
let text = "fn a() {}"; let text = "fn a() {}";
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); 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) { fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let entity_id = cx.entity_id(); let entity_id = cx.entity_id();
let mut buffer = Buffer::new( let mut buffer = Buffer::new(
0, 0,
@ -1080,7 +1080,7 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppC
buffer buffer
}); });
cx.build_model(|cx| { cx.new_model(|cx| {
eprintln!("second buffer: {:?}", cx.entity_id()); eprintln!("second buffer: {:?}", cx.entity_id());
let mut buffer = Buffer::new( 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) { fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let mut buffer = Buffer::new( let mut buffer = Buffer::new(
0, 0,
cx.entity_id().as_u64(), 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) { fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let mut buffer = Buffer::new( let mut buffer = Buffer::new(
0, 0,
cx.entity_id().as_u64(), 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) { fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let text = "a\nb"; let text = "a\nb";
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(Arc::new(rust_lang()), cx); 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) { fn test_autoindent_multi_line_insertion(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let text = " let text = "
const a: usize = 1; const a: usize = 1;
fn b() { fn b() {
@ -1326,7 +1326,7 @@ fn test_autoindent_multi_line_insertion(cx: &mut AppContext) {
fn test_autoindent_block_mode(cx: &mut AppContext) { fn test_autoindent_block_mode(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let text = r#" let text = r#"
fn a() { fn a() {
b(); 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) { fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let text = r#" let text = r#"
fn a() { fn a() {
if b() { 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) { fn test_autoindent_language_without_indents_query(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let text = " let text = "
* one * one
- a - a
@ -1559,7 +1559,7 @@ fn test_autoindent_with_injected_languages(cx: &mut AppContext) {
language_registry.add(html_language.clone()); language_registry.add(html_language.clone());
language_registry.add(javascript_language.clone()); language_registry.add(javascript_language.clone());
cx.build_model(|cx| { cx.new_model(|cx| {
let (text, ranges) = marked_text_ranges( let (text, ranges) = marked_text_ranges(
&" &"
<div>ˇ <div>ˇ
@ -1610,7 +1610,7 @@ fn test_autoindent_query_with_outdent_captures(cx: &mut AppContext) {
settings.defaults.tab_size = Some(2.try_into().unwrap()); settings.defaults.tab_size = Some(2.try_into().unwrap());
}); });
cx.build_model(|cx| { cx.new_model(|cx| {
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), "").with_language(Arc::new(ruby_lang()), cx); 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) { fn test_language_scope_at_with_javascript(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let language = Language::new( let language = Language::new(
LanguageConfig { LanguageConfig {
name: "JavaScript".into(), 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) { fn test_language_scope_at_with_rust(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let language = Language::new( let language = Language::new(
LanguageConfig { LanguageConfig {
name: "Rust".into(), 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) { fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) {
init_settings(cx, |_| {}); init_settings(cx, |_| {});
cx.build_model(|cx| { cx.new_model(|cx| {
let text = r#" let text = r#"
<ol> <ol>
<% people.each do |person| %> <% 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) { fn test_serialization(cx: &mut gpui::AppContext) {
let mut now = Instant::now(); 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"); let mut buffer = Buffer::new(0, cx.entity_id().as_u64(), "abc");
buffer.edit([(3..3, "D")], None, cx); buffer.edit([(3..3, "D")], None, cx);
@ -1925,7 +1925,7 @@ fn test_serialization(cx: &mut gpui::AppContext) {
let ops = cx let ops = cx
.background_executor() .background_executor()
.block(buffer1.read(cx).serialize_ops(None, cx)); .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(); let mut buffer = Buffer::from_proto(1, state, None).unwrap();
buffer buffer
.apply_ops( .apply_ops(
@ -1959,10 +1959,10 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
let mut buffers = Vec::new(); let mut buffers = Vec::new();
let network = Arc::new(Mutex::new(Network::new(rng.clone()))); let network = Arc::new(Mutex::new(Network::new(rng.clone())));
let base_buffer = 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) { 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 state = base_buffer.read(cx).to_proto();
let ops = cx let ops = cx
.background_executor() .background_executor()
@ -2082,7 +2082,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
new_replica_id, new_replica_id,
replica_id replica_id
); );
new_buffer = Some(cx.build_model(|cx| { new_buffer = Some(cx.new_model(|cx| {
let mut new_buffer = let mut new_buffer =
Buffer::from_proto(new_replica_id, old_buffer_state, None).unwrap(); Buffer::from_proto(new_replica_id, old_buffer_state, None).unwrap();
new_buffer new_buffer
@ -2460,7 +2460,7 @@ fn assert_bracket_pairs(
cx: &mut AppContext, cx: &mut AppContext,
) { ) {
let (expected_text, selection_ranges) = marked_text_ranges(selection_text, false); 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()) Buffer::new(0, cx.entity_id().as_u64(), expected_text.clone())
.with_language(Arc::new(language), cx) .with_language(Arc::new(language), cx)
}); });

View file

@ -61,7 +61,7 @@ impl LanguageSelector {
language_registry, language_registry,
); );
let picker = cx.build_view(|cx| Picker::new(delegate, cx)); let picker = cx.new_view(|cx| Picker::new(delegate, cx));
Self { picker } Self { picker }
} }
} }

View file

@ -78,7 +78,7 @@ pub(crate) struct LogMenuItem {
actions!(debug, [OpenLanguageServerLogs]); actions!(debug, [OpenLanguageServerLogs]);
pub fn init(cx: &mut AppContext) { 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| { cx.observe_new_views(move |workspace: &mut Workspace, cx| {
let project = workspace.project(); let project = workspace.project();
@ -93,7 +93,7 @@ pub fn init(cx: &mut AppContext) {
let project = workspace.project().read(cx); let project = workspace.project().read(cx);
if project.is_local() { if project.is_local() {
workspace.add_item( workspace.add_item(
Box::new(cx.build_view(|cx| { Box::new(cx.new_view(|cx| {
LspLogView::new(workspace.project().clone(), log_store.clone(), cx) LspLogView::new(workspace.project().clone(), log_store.clone(), cx)
})), })),
cx, cx,
@ -444,7 +444,7 @@ impl LspLogView {
log_contents: String, log_contents: String,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> (View<Editor>, Subscription) { ) -> (View<Editor>, Subscription) {
let editor = cx.build_view(|cx| { let editor = cx.new_view(|cx| {
let mut editor = Editor::multi_line(cx); let mut editor = Editor::multi_line(cx);
editor.set_text(log_contents, cx); editor.set_text(log_contents, cx);
editor.move_to_end(&MoveToEnd, cx); editor.move_to_end(&MoveToEnd, cx);

View file

@ -46,7 +46,7 @@ async fn test_lsp_logs(cx: &mut TestAppContext) {
project.languages().add(Arc::new(rust_language)); 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)); log_store.update(cx, |store, cx| store.add_project(&project, cx));
let _rust_buffer = project let _rust_buffer = project

View file

@ -24,7 +24,7 @@ pub fn init(cx: &mut AppContext) {
let active_item = workspace.active_item(cx); let active_item = workspace.active_item(cx);
let workspace_handle = workspace.weak_handle(); let workspace_handle = workspace.weak_handle();
let syntax_tree_view = 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) workspace.split_item(SplitDirection::Right, Box::new(syntax_tree_view), cx)
}); });
}) })
@ -417,7 +417,7 @@ impl Item for SyntaxTreeView {
where where
Self: Sized, Self: Sized,
{ {
Some(cx.build_view(|cx| { Some(cx.new_view(|cx| {
let mut clone = Self::new(self.workspace_handle.clone(), None, cx); let mut clone = Self::new(self.workspace_handle.clone(), None, cx);
if let Some(editor) = &self.editor { if let Some(editor) = &self.editor {
clone.set_editor(editor.editor.clone(), cx) clone.set_editor(editor.editor.clone(), cx)

View file

@ -1649,17 +1649,17 @@ impl MultiBuffer {
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
impl MultiBuffer { impl MultiBuffer {
pub fn build_simple(text: &str, cx: &mut gpui::AppContext) -> Model<Self> { pub fn build_simple(text: &str, cx: &mut gpui::AppContext) -> Model<Self> {
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));
cx.build_model(|cx| Self::singleton(buffer, cx)) cx.new_model(|cx| Self::singleton(buffer, cx))
} }
pub fn build_multi<const COUNT: usize>( pub fn build_multi<const COUNT: usize>(
excerpts: [(&str, Vec<Range<Point>>); COUNT], excerpts: [(&str, Vec<Range<Point>>); COUNT],
cx: &mut gpui::AppContext, cx: &mut gpui::AppContext,
) -> Model<Self> { ) -> Model<Self> {
let multi = cx.build_model(|_| Self::new(0)); let multi = cx.new_model(|_| Self::new(0));
for (text, ranges) in excerpts { 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 { let excerpt_ranges = ranges.into_iter().map(|range| ExcerptRange {
context: range, context: range,
primary: None, primary: None,
@ -1673,11 +1673,11 @@ impl MultiBuffer {
} }
pub fn build_from_buffer(buffer: Model<Buffer>, cx: &mut gpui::AppContext) -> Model<Self> { pub fn build_from_buffer(buffer: Model<Buffer>, cx: &mut gpui::AppContext) -> Model<Self> {
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<Self> { pub fn build_random(rng: &mut impl rand::Rng, cx: &mut gpui::AppContext) -> Model<Self> {
cx.build_model(|cx| { cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
let mutation_count = rng.gen_range(1..=5); let mutation_count = rng.gen_range(1..=5);
multibuffer.randomly_edit_excerpts(rng, mutation_count, cx); 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) { if excerpt_ids.is_empty() || (rng.gen() && excerpt_ids.len() < max_excerpts) {
let buffer_handle = if rng.gen() || self.buffers.borrow().is_empty() { let buffer_handle = if rng.gen() || self.buffers.borrow().is_empty() {
let text = RandomCharIter::new(&mut *rng).take(10).collect::<String>(); let text = RandomCharIter::new(&mut *rng).take(10).collect::<String>();
buffers buffers.push(cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)));
.push(cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)));
let buffer = buffers.last().unwrap().read(cx); let buffer = buffers.last().unwrap().read(cx);
log::info!( log::info!(
"Creating new buffer {} with text: {:?}", "Creating new buffer {} with text: {:?}",
@ -4144,8 +4143,8 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_singleton(cx: &mut AppContext) { fn test_singleton(cx: &mut AppContext) {
let buffer = let buffer =
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 multibuffer = cx.build_model(|cx| MultiBuffer::singleton(buffer.clone(), cx)); let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
let snapshot = multibuffer.read(cx).snapshot(cx); let snapshot = multibuffer.read(cx).snapshot(cx);
assert_eq!(snapshot.text(), buffer.read(cx).text()); assert_eq!(snapshot.text(), buffer.read(cx).text());
@ -4171,8 +4170,8 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_remote(cx: &mut AppContext) { fn test_remote(cx: &mut AppContext) {
let host_buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "a")); let host_buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "a"));
let guest_buffer = cx.build_model(|cx| { let guest_buffer = cx.new_model(|cx| {
let state = host_buffer.read(cx).to_proto(); let state = host_buffer.read(cx).to_proto();
let ops = cx let ops = cx
.background_executor() .background_executor()
@ -4187,7 +4186,7 @@ mod tests {
.unwrap(); .unwrap();
buffer 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); let snapshot = multibuffer.read(cx).snapshot(cx);
assert_eq!(snapshot.text(), "a"); assert_eq!(snapshot.text(), "a");
@ -4203,10 +4202,10 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_excerpt_boundaries_and_clipping(cx: &mut AppContext) { fn test_excerpt_boundaries_and_clipping(cx: &mut AppContext) {
let buffer_1 = 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 = let buffer_2 =
cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'g'))); cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(6, 6, 'g')));
let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let multibuffer = cx.new_model(|_| MultiBuffer::new(0));
let events = Arc::new(RwLock::new(Vec::<Event>::new())); let events = Arc::new(RwLock::new(Vec::<Event>::new()));
multibuffer.update(cx, |_, cx| { multibuffer.update(cx, |_, cx| {
@ -4439,12 +4438,12 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_excerpt_events(cx: &mut AppContext) { fn test_excerpt_events(cx: &mut AppContext) {
let buffer_1 = 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 = 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 leader_multibuffer = cx.new_model(|_| MultiBuffer::new(0));
let follower_multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let follower_multibuffer = cx.new_model(|_| MultiBuffer::new(0));
let follower_edit_event_count = Arc::new(RwLock::new(0)); let follower_edit_event_count = Arc::new(RwLock::new(0));
follower_multibuffer.update(cx, |_, cx| { follower_multibuffer.update(cx, |_, cx| {
@ -4547,8 +4546,8 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_push_excerpts_with_context_lines(cx: &mut AppContext) { fn test_push_excerpts_with_context_lines(cx: &mut AppContext) {
let buffer = let buffer =
cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a'))); cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a')));
let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let multibuffer = cx.new_model(|_| MultiBuffer::new(0));
let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| { let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| {
multibuffer.push_excerpts_with_context_lines( multibuffer.push_excerpts_with_context_lines(
buffer.clone(), buffer.clone(),
@ -4584,8 +4583,8 @@ mod tests {
#[gpui::test] #[gpui::test]
async fn test_stream_excerpts_with_context_lines(cx: &mut TestAppContext) { async fn test_stream_excerpts_with_context_lines(cx: &mut TestAppContext) {
let buffer = let buffer =
cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a'))); cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), sample_text(20, 3, 'a')));
let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let multibuffer = cx.new_model(|_| MultiBuffer::new(0));
let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| { let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| {
let snapshot = buffer.read(cx); let snapshot = buffer.read(cx);
let ranges = vec![ let ranges = vec![
@ -4620,7 +4619,7 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_empty_multibuffer(cx: &mut AppContext) { 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); let snapshot = multibuffer.read(cx).snapshot(cx);
assert_eq!(snapshot.text(), ""); assert_eq!(snapshot.text(), "");
@ -4630,8 +4629,8 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_singleton_multibuffer_anchors(cx: &mut AppContext) { fn test_singleton_multibuffer_anchors(cx: &mut AppContext) {
let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd")); let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "abcd"));
let multibuffer = cx.build_model(|cx| MultiBuffer::singleton(buffer.clone(), cx)); let multibuffer = cx.new_model(|cx| MultiBuffer::singleton(buffer.clone(), cx));
let old_snapshot = multibuffer.read(cx).snapshot(cx); let old_snapshot = multibuffer.read(cx).snapshot(cx);
buffer.update(cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
buffer.edit([(0..0, "X")], None, cx); buffer.edit([(0..0, "X")], None, cx);
@ -4650,9 +4649,9 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_multibuffer_anchors(cx: &mut AppContext) { 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_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(), "efghi")); let buffer_2 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "efghi"));
let multibuffer = cx.build_model(|cx| { let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0); let mut multibuffer = MultiBuffer::new(0);
multibuffer.push_excerpts( multibuffer.push_excerpts(
buffer_1.clone(), buffer_1.clone(),
@ -4708,10 +4707,10 @@ mod tests {
#[gpui::test] #[gpui::test]
fn test_resolving_anchors_after_replacing_their_excerpts(cx: &mut AppContext) { 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 = let buffer_2 =
cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "ABCDEFGHIJKLMNOP")); cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "ABCDEFGHIJKLMNOP"));
let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let multibuffer = cx.new_model(|_| MultiBuffer::new(0));
// Create an insertion id in buffer 1 that doesn't exist in buffer 2. // 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. // Add an excerpt from buffer 1 that spans this new insertion.
@ -4845,7 +4844,7 @@ mod tests {
.unwrap_or(10); .unwrap_or(10);
let mut buffers: Vec<Model<Buffer>> = Vec::new(); let mut buffers: Vec<Model<Buffer>> = Vec::new();
let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let multibuffer = cx.new_model(|_| MultiBuffer::new(0));
let mut excerpt_ids = Vec::<ExcerptId>::new(); let mut excerpt_ids = Vec::<ExcerptId>::new();
let mut expected_excerpts = Vec::<(Model<Buffer>, Range<text::Anchor>)>::new(); let mut expected_excerpts = Vec::<(Model<Buffer>, Range<text::Anchor>)>::new();
let mut anchors = Vec::new(); let mut anchors = Vec::new();
@ -4922,7 +4921,7 @@ mod tests {
.take(10) .take(10)
.collect::<String>(); .collect::<String>();
buffers.push( 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() buffers.last().unwrap()
} else { } else {
@ -5265,9 +5264,9 @@ mod tests {
let test_settings = SettingsStore::test(cx); let test_settings = SettingsStore::test(cx);
cx.set_global(test_settings); cx.set_global(test_settings);
let buffer_1 = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "1234")); let buffer_1 = cx.new_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 buffer_2 = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), "5678"));
let multibuffer = cx.build_model(|_| MultiBuffer::new(0)); let multibuffer = cx.new_model(|_| MultiBuffer::new(0));
let group_interval = multibuffer.read(cx).history.group_interval; let group_interval = multibuffer.read(cx).history.group_interval;
multibuffer.update(cx, |multibuffer, cx| { multibuffer.update(cx, |multibuffer, cx| {
multibuffer.push_excerpts( multibuffer.push_excerpts(

View file

@ -11,7 +11,7 @@ use time::OffsetDateTime;
use util::ResultExt; use util::ResultExt;
pub fn init(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut AppContext) { pub fn init(client: Arc<Client>, user_store: Model<UserStore>, 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); cx.set_global(notification_store);
} }

View file

@ -80,7 +80,7 @@ impl OutlineView {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> OutlineView { ) -> OutlineView {
let delegate = OutlineViewDelegate::new(cx.view().downgrade(), outline, editor, cx); 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 } OutlineView { picker }
} }
} }

View file

@ -59,7 +59,7 @@ impl<D: PickerDelegate> FocusableView for Picker<D> {
impl<D: PickerDelegate> Picker<D> { impl<D: PickerDelegate> Picker<D> {
pub fn new(delegate: D, cx: &mut ViewContext<Self>) -> Self { pub fn new(delegate: D, cx: &mut ViewContext<Self>) -> Self {
let editor = cx.build_view(|cx| { let editor = cx.new_view(|cx| {
let mut editor = Editor::single_line(cx); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text(delegate.placeholder_text(), cx); editor.set_placeholder_text(delegate.placeholder_text(), cx);
editor editor

View file

@ -636,7 +636,7 @@ impl Project {
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
cx: &mut AppContext, cx: &mut AppContext,
) -> Model<Self> { ) -> Model<Self> {
cx.build_model(|cx: &mut ModelContext<Self>| { cx.new_model(|cx: &mut ModelContext<Self>| {
let (tx, rx) = mpsc::unbounded(); let (tx, rx) = mpsc::unbounded();
cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx)) cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx))
.detach(); .detach();
@ -712,7 +712,7 @@ impl Project {
project_id: remote_id, project_id: remote_id,
}) })
.await?; .await?;
let this = cx.build_model(|cx| { let this = cx.new_model(|cx| {
let replica_id = response.payload.replica_id as ReplicaId; let replica_id = response.payload.replica_id as ReplicaId;
let mut worktrees = Vec::new(); let mut worktrees = Vec::new();
@ -868,7 +868,7 @@ impl Project {
languages.set_executor(cx.executor()); languages.set_executor(cx.executor());
let http_client = util::http::FakeHttpClient::with_404_response(); let http_client = util::http::FakeHttpClient::with_404_response();
let client = cx.update(|cx| client::Client::new(http_client.clone(), cx)); 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| { let project = cx.update(|cx| {
Project::local( Project::local(
client, client,
@ -1690,7 +1690,7 @@ impl Project {
return Err(anyhow!("creating buffers as a guest is not supported yet")); return Err(anyhow!("creating buffers as a guest is not supported yet"));
} }
let id = post_inc(&mut self.next_buffer_id); 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) Buffer::new(self.replica_id(), id, text)
.with_language(language.unwrap_or_else(|| language::PLAIN_TEXT.clone()), cx) .with_language(language.unwrap_or_else(|| language::PLAIN_TEXT.clone()), cx)
}); });
@ -7193,7 +7193,7 @@ impl Project {
} }
let buffer_id = state.id; 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() Buffer::from_proto(this.replica_id(), state, buffer_file).unwrap()
}); });
this.incomplete_remote_buffers this.incomplete_remote_buffers

View file

@ -39,7 +39,7 @@ impl Project {
window, window,
) )
.map(|builder| { .map(|builder| {
let terminal_handle = cx.build_model(|cx| builder.subscribe(cx)); let terminal_handle = cx.new_model(|cx| builder.subscribe(cx));
self.terminals self.terminals
.local_handles .local_handles

View file

@ -312,7 +312,7 @@ impl Worktree {
let closure_fs = Arc::clone(&fs); let closure_fs = Arc::clone(&fs);
let closure_next_entry_id = Arc::clone(&next_entry_id); let closure_next_entry_id = Arc::clone(&next_entry_id);
let closure_abs_path = abs_path.to_path_buf(); let closure_abs_path = abs_path.to_path_buf();
cx.build_model(move |cx: &mut ModelContext<Worktree>| { cx.new_model(move |cx: &mut ModelContext<Worktree>| {
cx.observe_global::<SettingsStore>(move |this, cx| { cx.observe_global::<SettingsStore>(move |this, cx| {
if let Self::Local(this) = this { if let Self::Local(this) = this {
let new_file_scan_exclusions = let new_file_scan_exclusions =
@ -415,7 +415,7 @@ impl Worktree {
client: Arc<Client>, client: Arc<Client>,
cx: &mut AppContext, cx: &mut AppContext,
) -> Model<Self> { ) -> Model<Self> {
cx.build_model(|cx: &mut ModelContext<Self>| { cx.new_model(|cx: &mut ModelContext<Self>| {
let snapshot = Snapshot { let snapshot = Snapshot {
id: WorktreeId(worktree.id as usize), id: WorktreeId(worktree.id as usize),
abs_path: Arc::from(PathBuf::from(worktree.abs_path)), abs_path: Arc::from(PathBuf::from(worktree.abs_path)),
@ -682,7 +682,7 @@ impl LocalWorktree {
.background_executor() .background_executor()
.spawn(async move { text::Buffer::new(0, id, contents) }) .spawn(async move { text::Buffer::new(0, id, contents) })
.await; .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))))
}) })
} }

View file

@ -168,7 +168,7 @@ struct DraggedProjectEntryView {
impl ProjectPanel { impl ProjectPanel {
fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> { fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
let project = workspace.project().clone(); let project = workspace.project().clone();
let project_panel = cx.build_view(|cx: &mut ViewContext<Self>| { let project_panel = cx.new_view(|cx: &mut ViewContext<Self>| {
cx.observe(&project, |this, _, cx| { cx.observe(&project, |this, _, cx| {
this.update_visible_entries(None, cx); this.update_visible_entries(None, cx);
cx.notify(); cx.notify();
@ -200,7 +200,7 @@ impl ProjectPanel {
}) })
.detach(); .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 { cx.subscribe(&filename_editor, |this, _, event, cx| match event {
editor::EditorEvent::BufferEdited editor::EditorEvent::BufferEdited
@ -1384,7 +1384,7 @@ impl ProjectPanel {
div() div()
.id(entry_id.to_proto() as usize) .id(entry_id.to_proto() as usize)
.on_drag(entry_id, move |entry_id, cx| { .on_drag(entry_id, move |entry_id, cx| {
cx.build_view(|_| DraggedProjectEntryView { cx.new_view(|_| DraggedProjectEntryView {
details: details.clone(), details: details.clone(),
width, width,
entry_id: *entry_id, entry_id: *entry_id,

View file

@ -340,7 +340,7 @@ mod tests {
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx)); let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx));
// Create the project symbols view. // Create the project symbols view.
let symbols = cx.build_view(|cx| { let symbols = cx.new_view(|cx| {
Picker::new( Picker::new(
ProjectSymbolsDelegate::new(workspace.downgrade(), project.clone()), ProjectSymbolsDelegate::new(workspace.downgrade(), project.clone()),
cx, cx,

View file

@ -30,7 +30,7 @@ impl ModalView for RecentProjects {}
impl RecentProjects { impl RecentProjects {
fn new(delegate: RecentProjectsDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> Self { fn new(delegate: RecentProjectsDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> 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)); 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 // 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. // out workspace locations once the future runs to completion.
@ -90,7 +90,7 @@ impl RecentProjects {
})) }))
} }
pub fn open_popover(workspace: WeakView<Workspace>, cx: &mut WindowContext<'_>) -> View<Self> { pub fn open_popover(workspace: WeakView<Workspace>, cx: &mut WindowContext<'_>) -> View<Self> {
cx.build_view(|cx| Self::new(RecentProjectsDelegate::new(workspace, false), 20., cx)) cx.new_view(|cx| Self::new(RecentProjectsDelegate::new(workspace, false), 20., cx))
} }
} }

View file

@ -434,7 +434,7 @@ impl BufferSearchBar {
}); });
return; 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); this.add_item(view.clone(), cx);
view.update(cx, |this, cx| this.deploy(deploy, cx)); view.update(cx, |this, cx| this.deploy(deploy, cx));
cx.notify(); cx.notify();
@ -506,10 +506,10 @@ impl BufferSearchBar {
}); });
} }
pub fn new(cx: &mut ViewContext<Self>) -> Self { pub fn new(cx: &mut ViewContext<Self>) -> 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) cx.subscribe(&query_editor, Self::on_query_editor_event)
.detach(); .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) cx.subscribe(&replacement_editor, Self::on_query_editor_event)
.detach(); .detach();
Self { Self {
@ -1044,7 +1044,7 @@ mod tests {
&mut VisualTestContext<'_>, &mut VisualTestContext<'_>,
) { ) {
init_globals(cx); init_globals(cx);
let buffer = cx.build_model(|cx| { let buffer = cx.new_model(|cx| {
Buffer::new( Buffer::new(
0, 0,
cx.entity_id().as_u64(), cx.entity_id().as_u64(),
@ -1058,9 +1058,9 @@ mod tests {
) )
}); });
let (_, cx) = cx.add_window_view(|_| EmptyView {}); 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); let mut search_bar = BufferSearchBar::new(cx);
search_bar.set_active_pane_item(Some(&editor), cx); search_bar.set_active_pane_item(Some(&editor), cx);
search_bar.show(cx); search_bar.show(cx);
@ -1405,7 +1405,7 @@ mod tests {
expected_query_matches_count > 1, expected_query_matches_count > 1,
"Should pick a query with multiple results" "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 window = cx.add_window(|_| EmptyView {});
let editor = window.build_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx)); let editor = window.build_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx));
@ -1602,12 +1602,12 @@ mod tests {
for "find" or "find and replace" operations on strings, or for input validation. for "find" or "find and replace" operations on strings, or for input validation.
"# "#
.unindent(); .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 (_, 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); let mut search_bar = BufferSearchBar::new(cx);
search_bar.set_active_pane_item(Some(&editor), cx); search_bar.set_active_pane_item(Some(&editor), cx);
search_bar.show(cx); search_bar.show(cx);

View file

@ -134,7 +134,7 @@ impl ProjectSearch {
let replica_id = project.read(cx).replica_id(); let replica_id = project.read(cx).replica_id();
Self { Self {
project, project,
excerpts: cx.build_model(|_| MultiBuffer::new(replica_id)), excerpts: cx.new_model(|_| MultiBuffer::new(replica_id)),
pending_search: Default::default(), pending_search: Default::default(),
match_ranges: Default::default(), match_ranges: Default::default(),
active_query: None, active_query: None,
@ -145,11 +145,11 @@ impl ProjectSearch {
} }
fn clone(&self, cx: &mut ModelContext<Self>) -> Model<Self> { fn clone(&self, cx: &mut ModelContext<Self>) -> Model<Self> {
cx.build_model(|cx| Self { cx.new_model(|cx| Self {
project: self.project.clone(), project: self.project.clone(),
excerpts: self excerpts: self
.excerpts .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(), pending_search: Default::default(),
match_ranges: self.match_ranges.clone(), match_ranges: self.match_ranges.clone(),
active_query: self.active_query.clone(), active_query: self.active_query.clone(),
@ -504,7 +504,7 @@ impl Item for ProjectSearchView {
Self: Sized, Self: Sized,
{ {
let model = self.model.update(cx, |model, cx| model.clone(cx)); 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<Self>) { fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) {
@ -805,7 +805,7 @@ impl ProjectSearchView {
} }
subscriptions.push(cx.observe(&model, |this, _, cx| this.model_changed(cx))); 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); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("Text search all files", cx); editor.set_placeholder_text("Text search all files", cx);
editor.set_text(query_text, cx); editor.set_text(query_text, cx);
@ -817,7 +817,7 @@ impl ProjectSearchView {
cx.emit(ViewEvent::EditorEvent(event.clone())) 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); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("Replace in project..", cx); editor.set_placeholder_text("Replace in project..", cx);
if let Some(text) = replacement_text { if let Some(text) = replacement_text {
@ -825,7 +825,7 @@ impl ProjectSearchView {
} }
editor 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); let mut editor = Editor::for_multibuffer(excerpts, Some(project.clone()), cx);
editor.set_searchable(false); editor.set_searchable(false);
editor 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); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("Include: crates/**/*.toml", 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); let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("Exclude: vendor/*, *.lock", cx); editor.set_placeholder_text("Exclude: vendor/*, *.lock", cx);
@ -929,8 +929,8 @@ impl ProjectSearchView {
return; return;
}; };
let model = cx.build_model(|cx| ProjectSearch::new(workspace.project().clone(), cx)); let model = cx.new_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
let search = cx.build_view(|cx| ProjectSearchView::new(model, cx, None)); let search = cx.new_view(|cx| ProjectSearchView::new(model, cx, None));
workspace.add_item(Box::new(search.clone()), cx); workspace.add_item(Box::new(search.clone()), cx);
search.update(cx, |search, cx| { search.update(cx, |search, cx| {
search search
@ -973,8 +973,8 @@ impl ProjectSearchView {
None None
}; };
let model = cx.build_model(|cx| ProjectSearch::new(workspace.project().clone(), cx)); let model = cx.new_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
let search = cx.build_view(|cx| ProjectSearchView::new(model, cx, settings)); let search = cx.new_view(|cx| ProjectSearchView::new(model, cx, settings));
workspace.add_item(Box::new(search.clone()), cx); workspace.add_item(Box::new(search.clone()), cx);
@ -1293,13 +1293,13 @@ impl ProjectSearchBar {
new_query new_query
}); });
if let Some(new_query) = 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); let mut model = ProjectSearch::new(workspace.project().clone(), cx);
model.search(new_query, cx); model.search(new_query, cx);
model model
}); });
workspace.add_item( 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, cx,
); );
} }
@ -1944,7 +1944,7 @@ pub mod tests {
) )
.await; .await;
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).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)); let search_view = cx.add_window(|cx| ProjectSearchView::new(search.clone(), cx, None));
search_view search_view

View file

@ -341,7 +341,7 @@ impl SemanticIndex {
t0.elapsed().as_millis() t0.elapsed().as_millis()
); );
cx.build_model(|cx| { cx.new_model(|cx| {
let t0 = Instant::now(); let t0 = Instant::now();
let embedding_queue = let embedding_queue =
EmbeddingQueue::new(embedding_provider.clone(), cx.background_executor().clone()); EmbeddingQueue::new(embedding_provider.clone(), cx.background_executor().clone());

View file

@ -11,8 +11,8 @@ pub struct AutoHeightEditorStory {
impl AutoHeightEditorStory { impl AutoHeightEditorStory {
pub fn new(cx: &mut WindowContext) -> View<Self> { pub fn new(cx: &mut WindowContext) -> View<Self> {
cx.bind_keys([KeyBinding::new("enter", editor::Newline, Some("Editor"))]); cx.bind_keys([KeyBinding::new("enter", editor::Newline, Some("Editor"))]);
cx.build_view(|cx| Self { cx.new_view(|cx| Self {
editor: cx.build_view(|cx| { editor: cx.new_view(|cx| {
let mut editor = Editor::auto_height(3, cx); let mut editor = Editor::auto_height(3, cx);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx); editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
editor editor

View file

@ -20,7 +20,7 @@ impl FocusStory {
KeyBinding::new("cmd-c", ActionC, None), KeyBinding::new("cmd-c", ActionC, None),
]); ]);
cx.build_view(move |cx| { cx.new_view(move |cx| {
let parent_focus = cx.focus_handle(); let parent_focus = cx.focus_handle();
let child_1_focus = cx.focus_handle(); let child_1_focus = cx.focus_handle();
let child_2_focus = cx.focus_handle(); let child_2_focus = cx.focus_handle();

View file

@ -9,7 +9,7 @@ pub struct KitchenSinkStory;
impl KitchenSinkStory { impl KitchenSinkStory {
pub fn view(cx: &mut WindowContext) -> View<Self> { pub fn view(cx: &mut WindowContext) -> View<Self> {
cx.build_view(|_cx| Self) cx.new_view(|_cx| Self)
} }
} }

View file

@ -116,7 +116,7 @@ impl PickerDelegate for Delegate {
impl PickerStory { impl PickerStory {
pub fn new(cx: &mut WindowContext) -> View<Self> { pub fn new(cx: &mut WindowContext) -> View<Self> {
cx.build_view(|cx| { cx.new_view(|cx| {
cx.bind_keys([ cx.bind_keys([
KeyBinding::new("up", menu::SelectPrev, Some("picker")), KeyBinding::new("up", menu::SelectPrev, Some("picker")),
KeyBinding::new("pageup", menu::SelectFirst, Some("picker")), KeyBinding::new("pageup", menu::SelectFirst, Some("picker")),
@ -136,7 +136,7 @@ impl PickerStory {
]); ]);
PickerStory { PickerStory {
picker: cx.build_view(|cx| { picker: cx.new_view(|cx| {
let mut delegate = Delegate::new(&[ let mut delegate = Delegate::new(&[
"Baguette (France)", "Baguette (France)",
"Baklava (Turkey)", "Baklava (Turkey)",

View file

@ -6,7 +6,7 @@ pub struct ScrollStory;
impl ScrollStory { impl ScrollStory {
pub fn view(cx: &mut WindowContext) -> View<ScrollStory> { pub fn view(cx: &mut WindowContext) -> View<ScrollStory> {
cx.build_view(|_cx| ScrollStory) cx.new_view(|_cx| ScrollStory)
} }
} }

View file

@ -9,7 +9,7 @@ pub struct TextStory;
impl TextStory { impl TextStory {
pub fn view(cx: &mut WindowContext) -> View<Self> { pub fn view(cx: &mut WindowContext) -> View<Self> {
cx.build_view(|_cx| Self) cx.new_view(|_cx| Self)
} }
} }

View file

@ -42,30 +42,28 @@ impl ComponentStory {
pub fn story(&self, cx: &mut WindowContext) -> AnyView { pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self { match self {
Self::AutoHeightEditor => AutoHeightEditorStory::new(cx).into(), Self::AutoHeightEditor => AutoHeightEditorStory::new(cx).into(),
Self::Avatar => cx.build_view(|_| ui::AvatarStory).into(), Self::Avatar => cx.new_view(|_| ui::AvatarStory).into(),
Self::Button => cx.build_view(|_| ui::ButtonStory).into(), Self::Button => cx.new_view(|_| ui::ButtonStory).into(),
Self::Checkbox => cx.build_view(|_| ui::CheckboxStory).into(), Self::Checkbox => cx.new_view(|_| ui::CheckboxStory).into(),
Self::ContextMenu => cx.build_view(|_| ui::ContextMenuStory).into(), Self::ContextMenu => cx.new_view(|_| ui::ContextMenuStory).into(),
Self::Cursor => cx.build_view(|_| crate::stories::CursorStory).into(), Self::Cursor => cx.new_view(|_| crate::stories::CursorStory).into(),
Self::Disclosure => cx.build_view(|_| ui::DisclosureStory).into(), Self::Disclosure => cx.new_view(|_| ui::DisclosureStory).into(),
Self::Focus => FocusStory::view(cx).into(), Self::Focus => FocusStory::view(cx).into(),
Self::Icon => cx.build_view(|_| ui::IconStory).into(), Self::Icon => cx.new_view(|_| ui::IconStory).into(),
Self::IconButton => cx.build_view(|_| ui::IconButtonStory).into(), Self::IconButton => cx.new_view(|_| ui::IconButtonStory).into(),
Self::Keybinding => cx.build_view(|_| ui::KeybindingStory).into(), Self::Keybinding => cx.new_view(|_| ui::KeybindingStory).into(),
Self::Label => cx.build_view(|_| ui::LabelStory).into(), Self::Label => cx.new_view(|_| ui::LabelStory).into(),
Self::List => cx.build_view(|_| ui::ListStory).into(), Self::List => cx.new_view(|_| ui::ListStory).into(),
Self::ListHeader => cx.build_view(|_| ui::ListHeaderStory).into(), Self::ListHeader => cx.new_view(|_| ui::ListHeaderStory).into(),
Self::ListItem => cx.build_view(|_| ui::ListItemStory).into(), Self::ListItem => cx.new_view(|_| ui::ListItemStory).into(),
Self::OverflowScroll => cx Self::OverflowScroll => cx.new_view(|_| crate::stories::OverflowScrollStory).into(),
.build_view(|_| crate::stories::OverflowScrollStory)
.into(),
Self::Scroll => ScrollStory::view(cx).into(), Self::Scroll => ScrollStory::view(cx).into(),
Self::Text => TextStory::view(cx).into(), Self::Text => TextStory::view(cx).into(),
Self::Tab => cx.build_view(|_| ui::TabStory).into(), Self::Tab => cx.new_view(|_| ui::TabStory).into(),
Self::TabBar => cx.build_view(|_| ui::TabBarStory).into(), Self::TabBar => cx.new_view(|_| ui::TabBarStory).into(),
Self::ToggleButton => cx.build_view(|_| ui::ToggleButtonStory).into(), Self::ToggleButton => cx.new_view(|_| ui::ToggleButtonStory).into(),
Self::ViewportUnits => cx.build_view(|_| crate::stories::ViewportUnitsStory).into(), Self::ViewportUnits => cx.new_view(|_| crate::stories::ViewportUnitsStory).into(),
Self::ZIndex => cx.build_view(|_| ZIndexStory).into(), Self::ZIndex => cx.new_view(|_| ZIndexStory).into(),
Self::Picker => PickerStory::new(cx).into(), Self::Picker => PickerStory::new(cx).into(),
} }
} }

View file

@ -93,7 +93,7 @@ fn main() {
let ui_font_size = ThemeSettings::get_global(cx).ui_font_size; let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
cx.set_rem_size(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)))
}, },
); );

View file

@ -53,7 +53,7 @@ pub struct TerminalPanel {
impl TerminalPanel { impl TerminalPanel {
fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self { fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
let terminal_panel = cx.view().clone(); let terminal_panel = cx.view().clone();
let pane = cx.build_view(|cx| { let pane = cx.new_view(|cx| {
let mut pane = Pane::new( let mut pane = Pane::new(
workspace.weak_handle(), workspace.weak_handle(),
workspace.project().clone(), workspace.project().clone(),
@ -147,7 +147,7 @@ impl TerminalPanel {
.flatten(); .flatten();
let (panel, pane, items) = workspace.update(&mut cx, |workspace, cx| { 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() { let items = if let Some(serialized_panel) = serialized_panel.as_ref() {
panel.update(cx, |panel, cx| { panel.update(cx, |panel, cx| {
cx.notify(); cx.notify();
@ -272,7 +272,7 @@ impl TerminalPanel {
.create_terminal(working_directory, window, cx) .create_terminal(working_directory, window, cx)
.log_err() .log_err()
}) { }) {
let terminal = Box::new(cx.build_view(|cx| { let terminal = Box::new(cx.new_view(|cx| {
TerminalView::new( TerminalView::new(
terminal, terminal,
workspace.weak_handle(), workspace.weak_handle(),

View file

@ -118,7 +118,7 @@ impl TerminalView {
.notify_err(workspace, cx); .notify_err(workspace, cx);
if let Some(terminal) = terminal { if let Some(terminal) = terminal {
let view = cx.build_view(|cx| { let view = cx.new_view(|cx| {
TerminalView::new( TerminalView::new(
terminal, terminal,
workspace.weak_handle(), workspace.weak_handle(),
@ -765,7 +765,7 @@ impl Item for TerminalView {
project.create_terminal(cwd, window, cx) project.create_terminal(cwd, window, cx)
})??; })??;
pane.update(&mut cx, |_, 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))
}) })
}) })
} }

View file

@ -74,7 +74,7 @@ impl Render for ThemeSelector {
impl ThemeSelector { impl ThemeSelector {
pub fn new(delegate: ThemeSelectorDelegate, cx: &mut ViewContext<Self>) -> Self { pub fn new(delegate: ThemeSelectorDelegate, cx: &mut ViewContext<Self>) -> Self {
let picker = cx.build_view(|cx| Picker::new(delegate, cx)); let picker = cx.new_view(|cx| Picker::new(delegate, cx));
Self { picker } Self { picker }
} }
} }

View file

@ -46,7 +46,7 @@ impl ContextMenu {
cx: &mut WindowContext, cx: &mut WindowContext,
f: impl FnOnce(Self, &mut WindowContext) -> Self, f: impl FnOnce(Self, &mut WindowContext) -> Self,
) -> View<Self> { ) -> View<Self> {
cx.build_view(|cx| { cx.new_view(|cx| {
let focus_handle = cx.focus_handle(); let focus_handle = cx.focus_handle();
let _on_blur_subscription = cx.on_blur(&focus_handle, |this: &mut ContextMenu, cx| { let _on_blur_subscription = cx.on_blur(&focus_handle, |this: &mut ContextMenu, cx| {
this.cancel(&menu::Cancel, cx) this.cancel(&menu::Cancel, cx)

View file

@ -13,7 +13,7 @@ pub struct Tooltip {
impl Tooltip { impl Tooltip {
pub fn text(title: impl Into<SharedString>, cx: &mut WindowContext) -> AnyView { pub fn text(title: impl Into<SharedString>, cx: &mut WindowContext) -> AnyView {
cx.build_view(|_cx| Self { cx.new_view(|_cx| Self {
title: title.into(), title: title.into(),
meta: None, meta: None,
key_binding: None, key_binding: None,
@ -26,7 +26,7 @@ impl Tooltip {
action: &dyn Action, action: &dyn Action,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> AnyView { ) -> AnyView {
cx.build_view(|cx| Self { cx.new_view(|cx| Self {
title: title.into(), title: title.into(),
meta: None, meta: None,
key_binding: KeyBinding::for_action(action, cx), key_binding: KeyBinding::for_action(action, cx),
@ -40,7 +40,7 @@ impl Tooltip {
meta: impl Into<SharedString>, meta: impl Into<SharedString>,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> AnyView { ) -> AnyView {
cx.build_view(|cx| Self { cx.new_view(|cx| Self {
title: title.into(), title: title.into(),
meta: Some(meta.into()), meta: Some(meta.into()),
key_binding: action.and_then(|action| KeyBinding::for_action(action, cx)), key_binding: action.and_then(|action| KeyBinding::for_action(action, cx)),

View file

@ -35,7 +35,7 @@ pub struct BranchList {
impl BranchList { impl BranchList {
fn new(delegate: BranchListDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> Self { fn new(delegate: BranchListDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> 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)); let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent));
Self { Self {
picker, picker,
@ -84,7 +84,7 @@ pub fn build_branch_list(
let delegate = workspace.update(cx, |workspace, cx| { let delegate = workspace.update(cx, |workspace, cx| {
BranchListDelegate::new(workspace, cx.view().clone(), 29, 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 { pub struct BranchListDelegate {

View file

@ -77,7 +77,7 @@ mod test {
async fn test_blur_focus(cx: &mut gpui::TestAppContext) { async fn test_blur_focus(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await; 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 window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx));
let editor2 = cx let editor2 = cx
.update(|cx| { .update(|cx| {

View file

@ -57,7 +57,7 @@ impl<'a> VimTestContext<'a> {
observe_keystrokes(cx); observe_keystrokes(cx);
workspace.active_pane().update(cx, |pane, cx| { workspace.active_pane().update(cx, |pane, cx| {
pane.toolbar().update(cx, |toolbar, 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); toolbar.add_item(buffer_search_bar, cx);
// todo!(); // todo!();
// let project_search_bar = cx.add_view(|_| ProjectSearchBar::new()); // 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| { 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); status_bar.add_right_item(vim_mode_indicator, cx);
}); });
}); });

View file

@ -54,7 +54,7 @@ impl BaseKeymapSelector {
delegate: BaseKeymapSelectorDelegate, delegate: BaseKeymapSelectorDelegate,
cx: &mut ViewContext<BaseKeymapSelector>, cx: &mut ViewContext<BaseKeymapSelector>,
) -> Self { ) -> 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(); let focus_handle = cx.focus_handle();
Self { Self {
focus_handle, focus_handle,

View file

@ -27,7 +27,7 @@ pub fn init(cx: &mut AppContext) {
cx.observe_new_views(|workspace: &mut Workspace, _cx| { cx.observe_new_views(|workspace: &mut Workspace, _cx| {
workspace.register_action(|workspace, _: &Welcome, 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) 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<AppState>, cx: &mut AppContext) { pub fn show_welcome_view(app_state: &Arc<AppState>, cx: &mut AppContext) {
open_new(&app_state, cx, |workspace, cx| { open_new(&app_state, cx, |workspace, cx| {
workspace.toggle_dock(DockPosition::Left, 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); workspace.add_item_to_center(Box::new(welcome_page.clone()), cx);
cx.focus_view(&welcome_page); cx.focus_view(&welcome_page);
cx.notify(); cx.notify();
@ -270,7 +270,7 @@ impl Item for WelcomePage {
_workspace_id: WorkspaceId, _workspace_id: WorkspaceId,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<View<Self>> { ) -> Option<View<Self>> {
Some(cx.build_view(|cx| WelcomePage { Some(cx.new_view(|cx| WelcomePage {
focus_handle: cx.focus_handle(), focus_handle: cx.focus_handle(),
workspace: self.workspace.clone(), workspace: self.workspace.clone(),
_settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()), _settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),

View file

@ -195,7 +195,7 @@ impl Dock {
pub fn new(position: DockPosition, cx: &mut ViewContext<Workspace>) -> View<Self> { pub fn new(position: DockPosition, cx: &mut ViewContext<Workspace>) -> View<Self> {
let focus_handle = cx.focus_handle(); let focus_handle = cx.focus_handle();
let dock = cx.build_view(|cx: &mut ViewContext<Self>| { let dock = cx.new_view(|cx: &mut ViewContext<Self>| {
let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| { let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| {
if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) { if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) {
active_entry.panel.focus_handle(cx).focus(cx) active_entry.panel.focus_handle(cx).focus(cx)
@ -514,7 +514,7 @@ impl Render for Dock {
.id("resize-handle") .id("resize-handle")
.on_drag(DraggedDock(position), |dock, cx| { .on_drag(DraggedDock(position), |dock, cx| {
cx.stop_propagation(); cx.stop_propagation();
cx.build_view(|_| dock.clone()) cx.new_view(|_| dock.clone())
}) })
.on_click(cx.listener(|v, e: &ClickEvent, cx| { .on_click(cx.listener(|v, e: &ClickEvent, cx| {
if e.down.button == MouseButton::Left && e.down.click_count == 2 { if e.down.button == MouseButton::Left && e.down.click_count == 2 {

View file

@ -831,14 +831,14 @@ pub mod test {
worktree_id: WorktreeId::from_usize(0), worktree_id: WorktreeId::from_usize(0),
path: Path::new(path).into(), path: Path::new(path).into(),
}); });
cx.build_model(|_| Self { cx.new_model(|_| Self {
entry_id, entry_id,
project_path, project_path,
}) })
} }
pub fn new_untitled(cx: &mut AppContext) -> Model<Self> { pub fn new_untitled(cx: &mut AppContext) -> Model<Self> {
cx.build_model(|_| Self { cx.new_model(|_| Self {
project_path: None, project_path: None,
entry_id: None, entry_id: None,
}) })
@ -987,7 +987,7 @@ pub mod test {
where where
Self: Sized, Self: Sized,
{ {
Some(cx.build_view(|cx| Self { Some(cx.new_view(|cx| Self {
state: self.state.clone(), state: self.state.clone(),
label: self.label.clone(), label: self.label.clone(),
save_count: self.save_count, save_count: self.save_count,
@ -1063,7 +1063,7 @@ pub mod test {
_item_id: ItemId, _item_id: ItemId,
cx: &mut ViewContext<Pane>, cx: &mut ViewContext<Pane>,
) -> Task<anyhow::Result<View<Self>>> { ) -> Task<anyhow::Result<View<Self>>> {
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))) Task::Ready(Some(anyhow::Ok(view)))
} }
} }

View file

@ -53,7 +53,7 @@ impl ModalLayer {
return; return;
} }
} }
let new_modal = cx.build_view(build_view); let new_modal = cx.new_view(build_view);
self.show_modal(new_modal, cx); self.show_modal(new_modal, cx);
} }

View file

@ -119,7 +119,7 @@ impl Workspace {
E: std::fmt::Debug, E: std::fmt::Debug,
{ {
self.show_notification(0, cx, |cx| { self.show_notification(0, cx, |cx| {
cx.build_view(|_cx| { cx.new_view(|_cx| {
simple_message_notification::MessageNotification::new(format!("Error: {err:?}")) 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>) { pub fn show_toast(&mut self, toast: Toast, cx: &mut ViewContext<Self>) {
self.dismiss_notification::<simple_message_notification::MessageNotification>(toast.id, cx); self.dismiss_notification::<simple_message_notification::MessageNotification>(toast.id, cx);
self.show_notification(toast.id, cx, |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)) => { Some((click_msg, on_click)) => {
let on_click = on_click.clone(); let on_click = on_click.clone();
simple_message_notification::MessageNotification::new(toast.msg.clone()) simple_message_notification::MessageNotification::new(toast.msg.clone())

View file

@ -361,7 +361,7 @@ impl Pane {
pane: handle.clone(), pane: handle.clone(),
next_timestamp, next_timestamp,
}))), }))),
toolbar: cx.build_view(|_| Toolbar::new()), toolbar: cx.new_view(|_| Toolbar::new()),
new_item_menu: None, new_item_menu: None,
split_item_menu: None, split_item_menu: None,
tab_bar_scroll_handle: ScrollHandle::new(), tab_bar_scroll_handle: ScrollHandle::new(),
@ -1540,7 +1540,7 @@ impl Pane {
is_active, is_active,
ix, ix,
}, },
|tab, cx| cx.build_view(|_| tab.clone()), |tab, cx| cx.new_view(|_| tab.clone()),
) )
.drag_over::<DraggedTab>(|tab| tab.bg(cx.theme().colors().drop_target_background)) .drag_over::<DraggedTab>(|tab| tab.bg(cx.theme().colors().drop_target_background))
.drag_over::<ProjectEntryId>(|tab| tab.bg(cx.theme().colors().drop_target_background)) .drag_over::<ProjectEntryId>(|tab| tab.bg(cx.theme().colors().drop_target_background))
@ -2241,7 +2241,7 @@ mod tests {
set_labeled_items(&pane, ["A", "B*", "C"], cx); set_labeled_items(&pane, ["A", "B*", "C"], cx);
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( 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,
false, false,
Some(0), Some(0),
@ -2254,7 +2254,7 @@ mod tests {
set_labeled_items(&pane, ["A", "B*", "C"], cx); set_labeled_items(&pane, ["A", "B*", "C"], cx);
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( 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,
false, false,
Some(2), Some(2),
@ -2267,7 +2267,7 @@ mod tests {
set_labeled_items(&pane, ["A", "B*", "C"], cx); set_labeled_items(&pane, ["A", "B*", "C"], cx);
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( 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,
false, false,
Some(5), Some(5),
@ -2281,7 +2281,7 @@ mod tests {
set_labeled_items(&pane, ["A*", "B", "C"], cx); set_labeled_items(&pane, ["A*", "B", "C"], cx);
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( 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,
false, false,
None, None,
@ -2294,7 +2294,7 @@ mod tests {
set_labeled_items(&pane, ["A", "B", "C*"], cx); set_labeled_items(&pane, ["A", "B", "C*"], cx);
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( 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,
false, false,
None, None,
@ -2391,7 +2391,7 @@ mod tests {
// singleton view // singleton view
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( pane.add_item(
Box::new(cx.build_view(|cx| { Box::new(cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_singleton(true) .with_singleton(true)
.with_label("buffer 1") .with_label("buffer 1")
@ -2408,7 +2408,7 @@ mod tests {
// new singleton view with the same project entry // new singleton view with the same project entry
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( pane.add_item(
Box::new(cx.build_view(|cx| { Box::new(cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_singleton(true) .with_singleton(true)
.with_label("buffer 1") .with_label("buffer 1")
@ -2425,7 +2425,7 @@ mod tests {
// new singleton view with different project entry // new singleton view with different project entry
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( pane.add_item(
Box::new(cx.build_view(|cx| { Box::new(cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_singleton(true) .with_singleton(true)
.with_label("buffer 2") .with_label("buffer 2")
@ -2442,7 +2442,7 @@ mod tests {
// new multibuffer view with the same project entry // new multibuffer view with the same project entry
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( pane.add_item(
Box::new(cx.build_view(|cx| { Box::new(cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_singleton(false) .with_singleton(false)
.with_label("multibuffer 1") .with_label("multibuffer 1")
@ -2459,7 +2459,7 @@ mod tests {
// another multibuffer view with the same project entry // another multibuffer view with the same project entry
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.add_item( pane.add_item(
Box::new(cx.build_view(|cx| { Box::new(cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_singleton(false) .with_singleton(false)
.with_label("multibuffer 1b") .with_label("multibuffer 1b")
@ -2673,7 +2673,7 @@ mod tests {
) -> Box<View<TestItem>> { ) -> Box<View<TestItem>> {
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
let labeled_item = Box::new( 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); pane.add_item(labeled_item.clone(), false, false, None, cx);
labeled_item labeled_item
@ -2696,8 +2696,7 @@ mod tests {
active_item_index = index; active_item_index = index;
} }
let labeled_item = let labeled_item = Box::new(cx.new_view(|cx| TestItem::new(cx).with_label(label)));
Box::new(cx.build_view(|cx| TestItem::new(cx).with_label(label)));
pane.add_item(labeled_item.clone(), false, false, None, cx); pane.add_item(labeled_item.clone(), false, false, None, cx);
index += 1; index += 1;
labeled_item labeled_item

View file

@ -117,7 +117,7 @@ impl Item for SharedScreen {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<View<Self>> { ) -> Option<View<Self>> {
let track = self.track.upgrade()?; 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)) { fn to_item_events(event: &Self::Event, mut f: impl FnMut(ItemEvent)) {

View file

@ -261,7 +261,7 @@ pub fn register_project_item<I: ProjectItem>(cx: &mut AppContext) {
let builders = cx.default_global::<ProjectItemBuilders>(); let builders = cx.default_global::<ProjectItemBuilders>();
builders.insert(TypeId::of::<I::Item>(), |project, model, cx| { builders.insert(TypeId::of::<I::Item>(), |project, model, cx| {
let item = model.downcast::<I::Item>().unwrap(); let item = model.downcast::<I::Item>().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 languages = Arc::new(LanguageRegistry::test());
let http_client = util::http::FakeHttpClient::with_404_response(); let http_client = util::http::FakeHttpClient::with_404_response();
let client = Client::new(http_client.clone(), cx); let 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 workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
theme::init(theme::LoadThemes::JustBase, cx); theme::init(theme::LoadThemes::JustBase, cx);
client::init(&client, cx); client::init(&client, cx);
@ -519,7 +519,7 @@ impl Workspace {
} }
project::Event::Notification(message) => this.show_notification(0, cx, |cx| { 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 weak_handle = cx.view().downgrade();
let pane_history_timestamp = Arc::new(AtomicUsize::new(0)); 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( Pane::new(
weak_handle.clone(), weak_handle.clone(),
project.clone(), project.clone(),
@ -589,10 +589,10 @@ impl Workspace {
let left_dock = Dock::new(DockPosition::Left, cx); let left_dock = Dock::new(DockPosition::Left, cx);
let bottom_dock = Dock::new(DockPosition::Bottom, cx); let bottom_dock = Dock::new(DockPosition::Bottom, cx);
let right_dock = Dock::new(DockPosition::Right, cx); let right_dock = Dock::new(DockPosition::Right, cx);
let left_dock_buttons = cx.build_view(|cx| PanelButtons::new(left_dock.clone(), cx)); let left_dock_buttons = cx.new_view(|cx| PanelButtons::new(left_dock.clone(), cx));
let bottom_dock_buttons = cx.build_view(|cx| PanelButtons::new(bottom_dock.clone(), cx)); let bottom_dock_buttons = cx.new_view(|cx| PanelButtons::new(bottom_dock.clone(), cx));
let right_dock_buttons = cx.build_view(|cx| PanelButtons::new(right_dock.clone(), cx)); let right_dock_buttons = cx.new_view(|cx| PanelButtons::new(right_dock.clone(), cx));
let status_bar = cx.build_view(|cx| { let status_bar = cx.new_view(|cx| {
let mut status_bar = StatusBar::new(&center_pane.clone(), cx); let mut status_bar = StatusBar::new(&center_pane.clone(), cx);
status_bar.add_left_item(left_dock_buttons, cx); status_bar.add_left_item(left_dock_buttons, cx);
status_bar.add_right_item(right_dock_buttons, cx); status_bar.add_right_item(right_dock_buttons, cx);
@ -600,7 +600,7 @@ impl Workspace {
status_bar status_bar
}); });
let modal_layer = cx.build_view(|_| ModalLayer::new()); let modal_layer = cx.new_view(|_| ModalLayer::new());
let mut active_call = None; let mut active_call = None;
if cx.has_global::<Model<ActiveCall>>() { if cx.has_global::<Model<ActiveCall>>() {
@ -800,7 +800,7 @@ impl Workspace {
let workspace_id = workspace_id.clone(); let workspace_id = workspace_id.clone();
let project_handle = project_handle.clone(); let project_handle = project_handle.clone();
move |cx| { move |cx| {
cx.build_view(|cx| { cx.new_view(|cx| {
Workspace::new(workspace_id, project_handle, app_state, cx) Workspace::new(workspace_id, project_handle, app_state, cx)
}) })
} }
@ -1718,7 +1718,7 @@ impl Workspace {
} }
fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> View<Pane> { fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> View<Pane> {
let pane = cx.build_view(|cx| { let pane = cx.new_view(|cx| {
Pane::new( Pane::new(
self.weak_handle(), self.weak_handle(),
self.project.clone(), self.project.clone(),
@ -1915,8 +1915,7 @@ impl Workspace {
return item; return item;
} }
let item = let item = cx.new_view(|cx| T::for_project_item(self.project().clone(), project_item, cx));
cx.build_view(|cx| T::for_project_item(self.project().clone(), project_item, cx));
self.add_item(Box::new(item.clone()), cx); self.add_item(Box::new(item.clone()), cx);
item item
} }
@ -1940,8 +1939,7 @@ impl Workspace {
return item; return item;
} }
let item = let item = cx.new_view(|cx| T::for_project_item(self.project().clone(), project_item, cx));
cx.build_view(|cx| T::for_project_item(self.project().clone(), project_item, cx));
self.split_item(SplitDirection::Right, Box::new(item.clone()), cx); self.split_item(SplitDirection::Right, Box::new(item.clone()), cx);
item 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<Self>) { pub fn on_window_activation_changed(&mut self, cx: &mut ViewContext<Self>) {
@ -3265,7 +3263,7 @@ impl Workspace {
let client = project.read(cx).client(); let client = project.read(cx).client();
let user_store = project.read(cx).user_store(); 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 { let app_state = Arc::new(AppState {
languages: project.read(cx).languages().clone(), languages: project.read(cx).languages().clone(),
workspace_store, workspace_store,
@ -3468,7 +3466,7 @@ fn notify_if_database_failed(workspace: WindowHandle<Workspace>, cx: &mut AsyncA
.update(cx, |workspace, cx| { .update(cx, |workspace, cx| {
if (*db::ALL_FILE_DB_FAILED).load(std::sync::atomic::Ordering::Acquire) { if (*db::ALL_FILE_DB_FAILED).load(std::sync::atomic::Ordering::Acquire) {
workspace.show_notification_once(0, cx, |cx| { workspace.show_notification_once(0, cx, |cx| {
cx.build_view(|_| { cx.new_view(|_| {
MessageNotification::new("Failed to load the database file.") MessageNotification::new("Failed to load the database file.")
.with_click_message("Click to let us know about this error") .with_click_message("Click to let us know about this error")
.on_click(|cx| cx.open_url(REPORT_ISSUE_URL)) .on_click(|cx| cx.open_url(REPORT_ISSUE_URL))
@ -4180,7 +4178,7 @@ pub fn join_remote_project(
cx.update(|cx| { cx.update(|cx| {
let options = (app_state.build_window_options)(window_bounds_override, None, cx); let options = (app_state.build_window_options)(window_bounds_override, None, cx);
cx.open_window(options, |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)); 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. // 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); let mut item = TestItem::new(cx);
item.tab_descriptions = Some(vec!["c", "b1/c", "a/b1/c"]); item.tab_descriptions = Some(vec!["c", "b1/c", "a/b1/c"]);
item item
@ -4366,7 +4364,7 @@ mod tests {
// Adding an item that creates ambiguity increases the level of detail on // Adding an item that creates ambiguity increases the level of detail on
// both tabs. // both tabs.
let item2 = cx.build_view(|cx| { let item2 = cx.new_view(|cx| {
let mut item = TestItem::new(cx); let mut item = TestItem::new(cx);
item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]); item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);
item item
@ -4380,7 +4378,7 @@ mod tests {
// Adding an item that creates ambiguity increases the level of detail only // 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 // on the ambiguous tabs. In this case, the ambiguity can't be resolved so
// we stop at the highest detail available. // 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); let mut item = TestItem::new(cx);
item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]); item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);
item item
@ -4421,10 +4419,10 @@ mod tests {
project.worktrees().next().unwrap().read(cx).id() 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)]) 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)]) 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)); 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. // 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)); 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)); let task = workspace.update(cx, |w, cx| w.prepare_to_close(false, cx));
assert!(task.await.unwrap()); assert!(task.await.unwrap());
// When there are dirty untitled items, prompt to save each one. If the user // When there are dirty untitled items, prompt to save each one. If the user
// cancels any prompt, then abort. // cancels any prompt, then abort.
let item2 = cx.build_view(|cx| TestItem::new(cx).with_dirty(true)); let item2 = cx.new_view(|cx| TestItem::new(cx).with_dirty(true));
let item3 = cx.build_view(|cx| { let item3 = cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_project_items(&[TestProjectItem::new(1, "1.txt", cx)]) .with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
@ -4529,24 +4527,24 @@ mod tests {
let project = Project::test(fs, None, cx).await; let project = Project::test(fs, None, cx).await;
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); 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) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_project_items(&[TestProjectItem::new(1, "1.txt", cx)]) .with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
}); });
let item2 = cx.build_view(|cx| { let item2 = cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_conflict(true) .with_conflict(true)
.with_project_items(&[TestProjectItem::new(2, "2.txt", cx)]) .with_project_items(&[TestProjectItem::new(2, "2.txt", cx)])
}); });
let item3 = cx.build_view(|cx| { let item3 = cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_conflict(true) .with_conflict(true)
.with_project_items(&[TestProjectItem::new(3, "3.txt", cx)]) .with_project_items(&[TestProjectItem::new(3, "3.txt", cx)])
}); });
let item4 = cx.build_view(|cx| { let item4 = cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_project_items(&[TestProjectItem::new_untitled(cx)]) .with_project_items(&[TestProjectItem::new_untitled(cx)])
@ -4638,7 +4636,7 @@ mod tests {
// workspace items with multiple project entries. // workspace items with multiple project entries.
let single_entry_items = (0..=4) let single_entry_items = (0..=4)
.map(|project_entry_id| { .map(|project_entry_id| {
cx.build_view(|cx| { cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_project_items(&[TestProjectItem::new( .with_project_items(&[TestProjectItem::new(
@ -4649,7 +4647,7 @@ mod tests {
}) })
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let item_2_3 = cx.build_view(|cx| { let item_2_3 = cx.new_view(|cx| {
TestItem::new(cx) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_singleton(false) .with_singleton(false)
@ -4658,7 +4656,7 @@ mod tests {
single_entry_items[3].read(cx).project_items[0].clone(), 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) TestItem::new(cx)
.with_dirty(true) .with_dirty(true)
.with_singleton(false) .with_singleton(false)
@ -4745,7 +4743,7 @@ mod tests {
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone()); 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)]) TestItem::new(cx).with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
}); });
let item_id = item.entity_id(); let item_id = item.entity_id();
@ -4864,7 +4862,7 @@ mod tests {
let project = Project::test(fs, [], cx).await; let project = Project::test(fs, [], cx).await;
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx)); 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)]) TestItem::new(cx).with_project_items(&[TestProjectItem::new(1, "1.txt", cx)])
}); });
let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone()); let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone());

View file

@ -293,7 +293,7 @@ mod tests {
}); });
let language = crate::languages::language("c", tree_sitter_c::language(), None).await; let language = crate::languages::language("c", tree_sitter_c::language(), None).await;
cx.build_model(|cx| { cx.new_model(|cx| {
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx); Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx);

View file

@ -198,7 +198,7 @@ mod tests {
}); });
}); });
cx.build_model(|cx| { cx.new_model(|cx| {
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx); Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx);
let append = |buffer: &mut Buffer, text: &str, cx: &mut ModelContext<Buffer>| { let append = |buffer: &mut Buffer, text: &str, cx: &mut ModelContext<Buffer>| {

View file

@ -508,7 +508,7 @@ mod tests {
let language = crate::languages::language("rust", tree_sitter_rust::language(), None).await; let language = crate::languages::language("rust", tree_sitter_rust::language(), None).await;
cx.build_model(|cx| { cx.new_model(|cx| {
let mut buffer = let mut buffer =
Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx); Buffer::new(0, cx.entity_id().as_u64(), "").with_language(language, cx);

View file

@ -378,7 +378,7 @@ mod tests {
"# "#
.unindent(); .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) 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()); let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None).unwrap());

View file

@ -139,8 +139,8 @@ fn main() {
language::init(cx); language::init(cx);
languages::init(languages.clone(), node_runtime.clone(), cx); languages::init(languages.clone(), node_runtime.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 workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx)); let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
cx.set_global(client.clone()); cx.set_global(client.clone());

View file

@ -115,17 +115,17 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
// workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx); // workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
let copilot = 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 = 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 = let activity_indicator =
activity_indicator::ActivityIndicator::new(workspace, app_state.languages.clone(), cx); activity_indicator::ActivityIndicator::new(workspace, app_state.languages.clone(), cx);
let active_buffer_language = let active_buffer_language =
cx.build_view(|_| language_selector::ActiveBufferLanguage::new(workspace)); cx.new_view(|_| language_selector::ActiveBufferLanguage::new(workspace));
let vim_mode_indicator = cx.build_view(|cx| vim::ModeIndicator::new(cx)); let vim_mode_indicator = cx.new_view(|cx| vim::ModeIndicator::new(cx));
let feedback_button = cx let feedback_button =
.build_view(|_| feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace)); cx.new_view(|_| feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace));
let cursor_position = cx.build_view(|_| editor::items::CursorPosition::new()); let cursor_position = cx.new_view(|_| editor::items::CursorPosition::new());
workspace.status_bar().update(cx, |status_bar, cx| { workspace.status_bar().update(cx, |status_bar, cx| {
status_bar.add_left_item(diagnostic_summary, cx); status_bar.add_left_item(diagnostic_summary, cx);
status_bar.add_left_item(activity_indicator, cx); status_bar.add_left_item(activity_indicator, cx);
@ -412,22 +412,22 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
fn initialize_pane(workspace: &mut Workspace, pane: &View<Pane>, cx: &mut ViewContext<Workspace>) { fn initialize_pane(workspace: &mut Workspace, pane: &View<Pane>, cx: &mut ViewContext<Workspace>) {
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.toolbar().update(cx, |toolbar, 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); 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); toolbar.add_item(buffer_search_bar.clone(), cx);
let quick_action_bar = 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); 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); 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); 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); toolbar.add_item(lsp_log_item, cx);
let syntax_tree_item = 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); toolbar.add_item(syntax_tree_item, cx);
}) })
}); });
@ -541,13 +541,15 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
.expect("creating buffers on a local workspace always succeeds"); .expect("creating buffers on a local workspace always succeeds");
buffer.update(cx, |buffer, cx| buffer.edit([(0..0, log)], None, cx)); 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()) MultiBuffer::singleton(buffer, cx).with_title("Log".into())
}); });
workspace.add_item( workspace.add_item(
Box::new(cx.build_view(|cx| { Box::new(
Editor::for_multibuffer(buffer, Some(project), cx) cx.new_view(|cx| {
})), Editor::for_multibuffer(buffer, Some(project), cx)
}),
),
cx, cx,
); );
}) })
@ -655,7 +657,7 @@ fn open_local_settings_file(
.detach(); .detach();
} else { } else {
workspace.show_notification(0, cx, |cx| { 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<Works
buffer.edit([(buffer.len()..buffer.len(), log_suffix)], None, cx); buffer.edit([(buffer.len()..buffer.len(), log_suffix)], None, cx);
}); });
let buffer = cx.build_model(|cx| { let buffer = cx.new_model(|cx| {
MultiBuffer::singleton(buffer, cx).with_title("Telemetry Log".into()) MultiBuffer::singleton(buffer, cx).with_title("Telemetry Log".into())
}); });
workspace.add_item( 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, cx,
); );
}).log_err()?; }).log_err()?;
@ -736,11 +738,11 @@ fn open_bundled_file(
.create_buffer(text.as_ref(), language, cx) .create_buffer(text.as_ref(), language, cx)
.expect("creating buffers on a local workspace always succeeds") .expect("creating buffers on a local workspace always succeeds")
}); });
let buffer = cx.build_model(|cx| { let buffer = cx.new_model(|cx| {
MultiBuffer::singleton(buffer, cx).with_title(title.into()) MultiBuffer::singleton(buffer, cx).with_title(title.into())
}); });
workspace.add_item( workspace.add_item(
Box::new(cx.build_view(|cx| { Box::new(cx.new_view(|cx| {
Editor::for_multibuffer(buffer, Some(project.clone()), cx) Editor::for_multibuffer(buffer, Some(project.clone()), cx)
})), })),
cx, cx,