From 6a1fb18334410e4465ee084426c80da41bb22830 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Fri, 3 Nov 2023 10:46:47 -0700 Subject: [PATCH] Update to latest patterns for porting work --- crates/channel2/Cargo.toml | 24 ++++++------- crates/channel2/src/channel2.rs | 4 +-- crates/channel2/src/channel_buffer.rs | 34 ++++++++++--------- crates/channel2/src/channel_chat.rs | 4 +-- crates/channel2/src/channel_store.rs | 34 +++++++++---------- .../src/channel_store/channel_index.rs | 2 +- crates/channel2/src/channel_store_tests.rs | 16 ++++----- 7 files changed, 60 insertions(+), 58 deletions(-) diff --git a/crates/channel2/Cargo.toml b/crates/channel2/Cargo.toml index c611944b89..c292d4e8dd 100644 --- a/crates/channel2/Cargo.toml +++ b/crates/channel2/Cargo.toml @@ -9,19 +9,19 @@ path = "src/channel2.rs" doctest = false [features] -test-support = ["collections/test-support", "gpui2/test-support", "rpc2/test-support"] +test-support = ["collections/test-support", "gpui/test-support", "rpc/test-support"] [dependencies] -client2 = { path = "../client2" } +client = { package = "client2", path = "../client2" } collections = { path = "../collections" } -db2 = { path = "../db2" } -gpui2 = { path = "../gpui2" } +db = { package = "db2", path = "../db2" } +gpui = { package = "gpui2", path = "../gpui2" } util = { path = "../util" } -rpc2 = { path = "../rpc2" } +rpc = { package = "rpc2", path = "../rpc2" } text = { path = "../text" } -language2 = { path = "../language2" } -settings2 = { path = "../settings2" } -feature_flags2 = { path = "../feature_flags2" } +language = { package = "language2", path = "../language2" } +settings = { package = "settings2", path = "../settings2" } +feature_flags = { package = "feature_flags2", path = "../feature_flags2" } sum_tree = { path = "../sum_tree" } clock = { path = "../clock" } @@ -47,8 +47,8 @@ tempfile = "3" [dev-dependencies] collections = { path = "../collections", features = ["test-support"] } -gpui2 = { path = "../gpui2", features = ["test-support"] } -rpc2 = { path = "../rpc2", features = ["test-support"] } -client2 = { path = "../client2", features = ["test-support"] } -settings2 = { path = "../settings2", features = ["test-support"] } +gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] } +rpc = { package = "rpc2", path = "../rpc2", features = ["test-support"] } +client = { package = "client2", path = "../client2", features = ["test-support"] } +settings = { package = "settings2", path = "../settings2", features = ["test-support"] } util = { path = "../util", features = ["test-support"] } diff --git a/crates/channel2/src/channel2.rs b/crates/channel2/src/channel2.rs index d300b170af..f38ae4078a 100644 --- a/crates/channel2/src/channel2.rs +++ b/crates/channel2/src/channel2.rs @@ -2,8 +2,8 @@ mod channel_buffer; mod channel_chat; mod channel_store; -use client2::{Client, UserStore}; -use gpui2::{AppContext, Model}; +use client::{Client, UserStore}; +use gpui::{AppContext, Model}; use std::sync::Arc; pub use channel_buffer::{ChannelBuffer, ChannelBufferEvent, ACKNOWLEDGE_DEBOUNCE_INTERVAL}; diff --git a/crates/channel2/src/channel_buffer.rs b/crates/channel2/src/channel_buffer.rs index 115896af7c..4c321a8fbc 100644 --- a/crates/channel2/src/channel_buffer.rs +++ b/crates/channel2/src/channel_buffer.rs @@ -1,10 +1,10 @@ use crate::{Channel, ChannelId, ChannelStore}; use anyhow::Result; -use client2::{Client, Collaborator, UserStore}; +use client::{Client, Collaborator, UserStore}; use collections::HashMap; -use gpui2::{AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task}; -use language2::proto::serialize_version; -use rpc2::{ +use gpui::{AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task}; +use language::proto::serialize_version; +use rpc::{ proto::{self, PeerId}, TypedEnvelope, }; @@ -24,10 +24,10 @@ pub struct ChannelBuffer { collaborators: HashMap, user_store: Model, channel_store: Model, - buffer: Model, + buffer: Model, buffer_epoch: u64, client: Arc, - subscription: Option, + subscription: Option, acknowledge_task: Option>>, } @@ -60,11 +60,11 @@ impl ChannelBuffer { let operations = response .operations .into_iter() - .map(language2::proto::deserialize_operation) + .map(language::proto::deserialize_operation) .collect::, _>>()?; let buffer = cx.build_model(|_| { - language2::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))??; @@ -145,7 +145,7 @@ impl ChannelBuffer { .payload .operations .into_iter() - .map(language2::proto::deserialize_operation) + .map(language::proto::deserialize_operation) .collect::, _>>()?; this.update(&mut cx, |this, cx| { @@ -172,13 +172,13 @@ impl ChannelBuffer { fn on_buffer_update( &mut self, - _: Model, - event: &language2::Event, + _: Model, + event: &language::Event, cx: &mut ModelContext, ) { match event { - language2::Event::Operation(operation) => { - let operation = language2::proto::serialize_operation(operation); + language::Event::Operation(operation) => { + let operation = language::proto::serialize_operation(operation); self.client .send(proto::UpdateChannelBuffer { channel_id: self.channel_id, @@ -186,7 +186,7 @@ impl ChannelBuffer { }) .log_err(); } - language2::Event::Edited => { + language::Event::Edited => { cx.emit(ChannelBufferEvent::BufferEdited); } _ => {} @@ -201,7 +201,9 @@ impl ChannelBuffer { let epoch = self.epoch(); self.acknowledge_task = Some(cx.spawn(move |_, cx| async move { - cx.executor().timer(ACKNOWLEDGE_DEBOUNCE_INTERVAL).await; + cx.background_executor() + .timer(ACKNOWLEDGE_DEBOUNCE_INTERVAL) + .await; client .send(proto::AckBufferOperation { buffer_id, @@ -217,7 +219,7 @@ impl ChannelBuffer { self.buffer_epoch } - pub fn buffer(&self) -> Model { + pub fn buffer(&self) -> Model { self.buffer.clone() } diff --git a/crates/channel2/src/channel_chat.rs b/crates/channel2/src/channel_chat.rs index 9306d78520..a5b5249853 100644 --- a/crates/channel2/src/channel_chat.rs +++ b/crates/channel2/src/channel_chat.rs @@ -1,12 +1,12 @@ use crate::{Channel, ChannelId, ChannelStore}; use anyhow::{anyhow, Result}; -use client2::{ +use client::{ proto, user::{User, UserStore}, Client, Subscription, TypedEnvelope, UserId, }; use futures::lock::Mutex; -use gpui2::{AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task}; +use gpui::{AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task}; use rand::prelude::*; use std::{ collections::HashSet, diff --git a/crates/channel2/src/channel_store.rs b/crates/channel2/src/channel_store.rs index 389b96ba42..3c9abd59e2 100644 --- a/crates/channel2/src/channel_store.rs +++ b/crates/channel2/src/channel_store.rs @@ -3,14 +3,14 @@ mod channel_index; use crate::{channel_buffer::ChannelBuffer, channel_chat::ChannelChat, ChannelMessage}; use anyhow::{anyhow, Result}; use channel_index::ChannelIndex; -use client2::{Client, Subscription, User, UserId, UserStore}; +use client::{Client, Subscription, User, UserId, UserStore}; use collections::{hash_map, HashMap, HashSet}; -use db2::RELEASE_CHANNEL; +use db::RELEASE_CHANNEL; use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt}; -use gpui2::{ +use gpui::{ AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakModel, }; -use rpc2::{ +use rpc::{ proto::{self, ChannelVisibility}, TypedEnvelope, }; @@ -142,13 +142,13 @@ impl ChannelStore { while let Some(status) = connection_status.next().await { let this = this.upgrade()?; match status { - client2::Status::Connected { .. } => { + client::Status::Connected { .. } => { this.update(&mut cx, |this, cx| this.handle_connect(cx)) .ok()? .await .log_err()?; } - client2::Status::SignedOut | client2::Status::UpgradeRequired => { + client::Status::SignedOut | client::Status::UpgradeRequired => { this.update(&mut cx, |this, cx| this.handle_disconnect(false, cx)) .ok(); } @@ -389,8 +389,8 @@ impl ChannelStore { cx: &mut ModelContext, ) -> Task>> where - F: 'static + Send + FnOnce(Arc, AsyncAppContext) -> Fut, - Fut: Send + Future>>, + F: 'static + FnOnce(Arc, AsyncAppContext) -> Fut, + Fut: Future>>, T: 'static, { let task = loop { @@ -445,7 +445,7 @@ impl ChannelStore { } } }; - cx.executor() + cx.background_executor() .spawn(async move { task.await.map_err(|error| anyhow!("{}", error)) }) } @@ -671,7 +671,7 @@ impl ChannelStore { cx: &mut ModelContext, ) -> Task> { let client = self.client.clone(); - cx.executor().spawn(async move { + cx.background_executor().spawn(async move { client .request(proto::RespondToChannelInvite { channel_id, accept }) .await?; @@ -770,7 +770,7 @@ impl ChannelStore { buffer_versions.push(proto::ChannelBufferVersion { channel_id: channel_buffer.channel_id, epoch: channel_buffer.epoch(), - version: language2::proto::serialize_version(&buffer.version()), + version: language::proto::serialize_version(&buffer.version()), }); } } @@ -803,7 +803,7 @@ impl ChannelStore { { let channel_id = channel_buffer.channel_id; let remote_version = - language2::proto::deserialize_version(&remote_buffer.version); + language::proto::deserialize_version(&remote_buffer.version); channel_buffer.replace_collaborators( mem::take(&mut remote_buffer.collaborators), @@ -818,7 +818,7 @@ impl ChannelStore { let incoming_operations = mem::take(&mut remote_buffer.operations) .into_iter() - .map(language2::proto::deserialize_operation) + .map(language::proto::deserialize_operation) .collect::>>()?; buffer.apply_ops(incoming_operations, cx)?; anyhow::Ok(outgoing_operations) @@ -827,11 +827,11 @@ impl ChannelStore { if let Some(operations) = operations { let client = this.client.clone(); - cx.executor() + cx.background_executor() .spawn(async move { let operations = operations.await; for chunk in - language2::proto::split_operations(operations) + language::proto::split_operations(operations) { client .send(proto::UpdateChannelBuffer { @@ -864,7 +864,7 @@ impl ChannelStore { self.disconnect_channel_buffers_task.get_or_insert_with(|| { cx.spawn(move |this, mut cx| async move { if wait_for_reconnect { - cx.executor().timer(RECONNECT_TIMEOUT).await; + cx.background_executor().timer(RECONNECT_TIMEOUT).await; } if let Some(this) = this.upgrade() { @@ -958,7 +958,7 @@ impl ChannelStore { } for unseen_buffer_change in payload.unseen_channel_buffer_changes { - let version = language2::proto::deserialize_version(&unseen_buffer_change.version); + let version = language::proto::deserialize_version(&unseen_buffer_change.version); index.note_changed( unseen_buffer_change.channel_id, unseen_buffer_change.epoch, diff --git a/crates/channel2/src/channel_store/channel_index.rs b/crates/channel2/src/channel_store/channel_index.rs index 9b8abb0c95..97b2ab6318 100644 --- a/crates/channel2/src/channel_store/channel_index.rs +++ b/crates/channel2/src/channel_store/channel_index.rs @@ -1,6 +1,6 @@ use crate::{Channel, ChannelId}; use collections::BTreeMap; -use rpc2::proto; +use rpc::proto; use std::sync::Arc; #[derive(Default, Debug)] diff --git a/crates/channel2/src/channel_store_tests.rs b/crates/channel2/src/channel_store_tests.rs index 036c7015ac..e193917b76 100644 --- a/crates/channel2/src/channel_store_tests.rs +++ b/crates/channel2/src/channel_store_tests.rs @@ -1,13 +1,13 @@ use crate::channel_chat::ChannelChatEvent; use super::*; -use client2::{test::FakeServer, Client, UserStore}; -use gpui2::{AppContext, Context, Model, TestAppContext}; -use rpc2::proto::{self}; -use settings2::SettingsStore; +use client::{test::FakeServer, Client, UserStore}; +use gpui::{AppContext, Context, Model, TestAppContext}; +use rpc::proto::{self}; +use settings::SettingsStore; use util::http::FakeHttpClient; -#[gpui2::test] +#[gpui::test] fn test_update_channels(cx: &mut AppContext) { let channel_store = init_test(cx); @@ -79,7 +79,7 @@ fn test_update_channels(cx: &mut AppContext) { ); } -#[gpui2::test] +#[gpui::test] fn test_dangling_channel_paths(cx: &mut AppContext) { let channel_store = init_test(cx); @@ -142,7 +142,7 @@ fn test_dangling_channel_paths(cx: &mut AppContext) { ); } -#[gpui2::test] +#[gpui::test] async fn test_channel_messages(cx: &mut TestAppContext) { let user_id = 5; let channel_id = 5; @@ -349,7 +349,7 @@ fn init_test(cx: &mut AppContext) -> Model { let settings_store = SettingsStore::test(cx); cx.set_global(settings_store); - client2::init(&client, cx); + client::init(&client, cx); crate::init(&client, user_store, cx); ChannelStore::global(cx)