Update to latest patterns for porting work

This commit is contained in:
Mikayla 2023-11-03 10:46:47 -07:00
parent b085569b46
commit 6a1fb18334
No known key found for this signature in database
7 changed files with 60 additions and 58 deletions

View file

@ -9,19 +9,19 @@ path = "src/channel2.rs"
doctest = false doctest = false
[features] [features]
test-support = ["collections/test-support", "gpui2/test-support", "rpc2/test-support"] test-support = ["collections/test-support", "gpui/test-support", "rpc/test-support"]
[dependencies] [dependencies]
client2 = { path = "../client2" } client = { package = "client2", path = "../client2" }
collections = { path = "../collections" } collections = { path = "../collections" }
db2 = { path = "../db2" } db = { package = "db2", path = "../db2" }
gpui2 = { path = "../gpui2" } gpui = { package = "gpui2", path = "../gpui2" }
util = { path = "../util" } util = { path = "../util" }
rpc2 = { path = "../rpc2" } rpc = { package = "rpc2", path = "../rpc2" }
text = { path = "../text" } text = { path = "../text" }
language2 = { path = "../language2" } language = { package = "language2", path = "../language2" }
settings2 = { path = "../settings2" } settings = { package = "settings2", path = "../settings2" }
feature_flags2 = { path = "../feature_flags2" } feature_flags = { package = "feature_flags2", path = "../feature_flags2" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
clock = { path = "../clock" } clock = { path = "../clock" }
@ -47,8 +47,8 @@ tempfile = "3"
[dev-dependencies] [dev-dependencies]
collections = { path = "../collections", features = ["test-support"] } collections = { path = "../collections", features = ["test-support"] }
gpui2 = { path = "../gpui2", features = ["test-support"] } gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
rpc2 = { path = "../rpc2", features = ["test-support"] } rpc = { package = "rpc2", path = "../rpc2", features = ["test-support"] }
client2 = { path = "../client2", features = ["test-support"] } client = { package = "client2", path = "../client2", features = ["test-support"] }
settings2 = { path = "../settings2", features = ["test-support"] } settings = { package = "settings2", path = "../settings2", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] } util = { path = "../util", features = ["test-support"] }

View file

@ -2,8 +2,8 @@ mod channel_buffer;
mod channel_chat; mod channel_chat;
mod channel_store; mod channel_store;
use client2::{Client, UserStore}; use client::{Client, UserStore};
use gpui2::{AppContext, Model}; use gpui::{AppContext, Model};
use std::sync::Arc; use std::sync::Arc;
pub use channel_buffer::{ChannelBuffer, ChannelBufferEvent, ACKNOWLEDGE_DEBOUNCE_INTERVAL}; pub use channel_buffer::{ChannelBuffer, ChannelBufferEvent, ACKNOWLEDGE_DEBOUNCE_INTERVAL};

View file

@ -1,10 +1,10 @@
use crate::{Channel, ChannelId, ChannelStore}; use crate::{Channel, ChannelId, ChannelStore};
use anyhow::Result; use anyhow::Result;
use client2::{Client, Collaborator, UserStore}; use client::{Client, Collaborator, UserStore};
use collections::HashMap; use collections::HashMap;
use gpui2::{AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task}; use gpui::{AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task};
use language2::proto::serialize_version; use language::proto::serialize_version;
use rpc2::{ use rpc::{
proto::{self, PeerId}, proto::{self, PeerId},
TypedEnvelope, TypedEnvelope,
}; };
@ -24,10 +24,10 @@ pub struct ChannelBuffer {
collaborators: HashMap<PeerId, Collaborator>, collaborators: HashMap<PeerId, Collaborator>,
user_store: Model<UserStore>, user_store: Model<UserStore>,
channel_store: Model<ChannelStore>, channel_store: Model<ChannelStore>,
buffer: Model<language2::Buffer>, buffer: Model<language::Buffer>,
buffer_epoch: u64, buffer_epoch: u64,
client: Arc<Client>, client: Arc<Client>,
subscription: Option<client2::Subscription>, subscription: Option<client::Subscription>,
acknowledge_task: Option<Task<Result<()>>>, acknowledge_task: Option<Task<Result<()>>>,
} }
@ -60,11 +60,11 @@ impl ChannelBuffer {
let operations = response let operations = response
.operations .operations
.into_iter() .into_iter()
.map(language2::proto::deserialize_operation) .map(language::proto::deserialize_operation)
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
let buffer = cx.build_model(|_| { 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))??; buffer.update(&mut cx, |buffer, cx| buffer.apply_ops(operations, cx))??;
@ -145,7 +145,7 @@ impl ChannelBuffer {
.payload .payload
.operations .operations
.into_iter() .into_iter()
.map(language2::proto::deserialize_operation) .map(language::proto::deserialize_operation)
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
@ -172,13 +172,13 @@ impl ChannelBuffer {
fn on_buffer_update( fn on_buffer_update(
&mut self, &mut self,
_: Model<language2::Buffer>, _: Model<language::Buffer>,
event: &language2::Event, event: &language::Event,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) { ) {
match event { match event {
language2::Event::Operation(operation) => { language::Event::Operation(operation) => {
let operation = language2::proto::serialize_operation(operation); let operation = language::proto::serialize_operation(operation);
self.client self.client
.send(proto::UpdateChannelBuffer { .send(proto::UpdateChannelBuffer {
channel_id: self.channel_id, channel_id: self.channel_id,
@ -186,7 +186,7 @@ impl ChannelBuffer {
}) })
.log_err(); .log_err();
} }
language2::Event::Edited => { language::Event::Edited => {
cx.emit(ChannelBufferEvent::BufferEdited); cx.emit(ChannelBufferEvent::BufferEdited);
} }
_ => {} _ => {}
@ -201,7 +201,9 @@ impl ChannelBuffer {
let epoch = self.epoch(); let epoch = self.epoch();
self.acknowledge_task = Some(cx.spawn(move |_, cx| async move { 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 client
.send(proto::AckBufferOperation { .send(proto::AckBufferOperation {
buffer_id, buffer_id,
@ -217,7 +219,7 @@ impl ChannelBuffer {
self.buffer_epoch self.buffer_epoch
} }
pub fn buffer(&self) -> Model<language2::Buffer> { pub fn buffer(&self) -> Model<language::Buffer> {
self.buffer.clone() self.buffer.clone()
} }

View file

@ -1,12 +1,12 @@
use crate::{Channel, ChannelId, ChannelStore}; use crate::{Channel, ChannelId, ChannelStore};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use client2::{ use client::{
proto, proto,
user::{User, UserStore}, user::{User, UserStore},
Client, Subscription, TypedEnvelope, UserId, Client, Subscription, TypedEnvelope, UserId,
}; };
use futures::lock::Mutex; 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 rand::prelude::*;
use std::{ use std::{
collections::HashSet, collections::HashSet,

View file

@ -3,14 +3,14 @@ mod channel_index;
use crate::{channel_buffer::ChannelBuffer, channel_chat::ChannelChat, ChannelMessage}; use crate::{channel_buffer::ChannelBuffer, channel_chat::ChannelChat, ChannelMessage};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use channel_index::ChannelIndex; 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 collections::{hash_map, HashMap, HashSet};
use db2::RELEASE_CHANNEL; use db::RELEASE_CHANNEL;
use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt}; use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt};
use gpui2::{ use gpui::{
AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakModel, AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakModel,
}; };
use rpc2::{ use rpc::{
proto::{self, ChannelVisibility}, proto::{self, ChannelVisibility},
TypedEnvelope, TypedEnvelope,
}; };
@ -142,13 +142,13 @@ impl ChannelStore {
while let Some(status) = connection_status.next().await { while let Some(status) = connection_status.next().await {
let this = this.upgrade()?; let this = this.upgrade()?;
match status { match status {
client2::Status::Connected { .. } => { client::Status::Connected { .. } => {
this.update(&mut cx, |this, cx| this.handle_connect(cx)) this.update(&mut cx, |this, cx| this.handle_connect(cx))
.ok()? .ok()?
.await .await
.log_err()?; .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)) this.update(&mut cx, |this, cx| this.handle_disconnect(false, cx))
.ok(); .ok();
} }
@ -389,8 +389,8 @@ impl ChannelStore {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Task<Result<Model<T>>> ) -> Task<Result<Model<T>>>
where where
F: 'static + Send + FnOnce(Arc<Channel>, AsyncAppContext) -> Fut, F: 'static + FnOnce(Arc<Channel>, AsyncAppContext) -> Fut,
Fut: Send + Future<Output = Result<Model<T>>>, Fut: Future<Output = Result<Model<T>>>,
T: 'static, T: 'static,
{ {
let task = loop { let task = loop {
@ -445,7 +445,7 @@ impl ChannelStore {
} }
} }
}; };
cx.executor() cx.background_executor()
.spawn(async move { task.await.map_err(|error| anyhow!("{}", error)) }) .spawn(async move { task.await.map_err(|error| anyhow!("{}", error)) })
} }
@ -671,7 +671,7 @@ impl ChannelStore {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
let client = self.client.clone(); let client = self.client.clone();
cx.executor().spawn(async move { cx.background_executor().spawn(async move {
client client
.request(proto::RespondToChannelInvite { channel_id, accept }) .request(proto::RespondToChannelInvite { channel_id, accept })
.await?; .await?;
@ -770,7 +770,7 @@ impl ChannelStore {
buffer_versions.push(proto::ChannelBufferVersion { buffer_versions.push(proto::ChannelBufferVersion {
channel_id: channel_buffer.channel_id, channel_id: channel_buffer.channel_id,
epoch: channel_buffer.epoch(), 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 channel_id = channel_buffer.channel_id;
let remote_version = let remote_version =
language2::proto::deserialize_version(&remote_buffer.version); language::proto::deserialize_version(&remote_buffer.version);
channel_buffer.replace_collaborators( channel_buffer.replace_collaborators(
mem::take(&mut remote_buffer.collaborators), mem::take(&mut remote_buffer.collaborators),
@ -818,7 +818,7 @@ impl ChannelStore {
let incoming_operations = let incoming_operations =
mem::take(&mut remote_buffer.operations) mem::take(&mut remote_buffer.operations)
.into_iter() .into_iter()
.map(language2::proto::deserialize_operation) .map(language::proto::deserialize_operation)
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;
buffer.apply_ops(incoming_operations, cx)?; buffer.apply_ops(incoming_operations, cx)?;
anyhow::Ok(outgoing_operations) anyhow::Ok(outgoing_operations)
@ -827,11 +827,11 @@ impl ChannelStore {
if let Some(operations) = operations { if let Some(operations) = operations {
let client = this.client.clone(); let client = this.client.clone();
cx.executor() cx.background_executor()
.spawn(async move { .spawn(async move {
let operations = operations.await; let operations = operations.await;
for chunk in for chunk in
language2::proto::split_operations(operations) language::proto::split_operations(operations)
{ {
client client
.send(proto::UpdateChannelBuffer { .send(proto::UpdateChannelBuffer {
@ -864,7 +864,7 @@ impl ChannelStore {
self.disconnect_channel_buffers_task.get_or_insert_with(|| { self.disconnect_channel_buffers_task.get_or_insert_with(|| {
cx.spawn(move |this, mut cx| async move { cx.spawn(move |this, mut cx| async move {
if wait_for_reconnect { if wait_for_reconnect {
cx.executor().timer(RECONNECT_TIMEOUT).await; cx.background_executor().timer(RECONNECT_TIMEOUT).await;
} }
if let Some(this) = this.upgrade() { if let Some(this) = this.upgrade() {
@ -958,7 +958,7 @@ impl ChannelStore {
} }
for unseen_buffer_change in payload.unseen_channel_buffer_changes { 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( index.note_changed(
unseen_buffer_change.channel_id, unseen_buffer_change.channel_id,
unseen_buffer_change.epoch, unseen_buffer_change.epoch,

View file

@ -1,6 +1,6 @@
use crate::{Channel, ChannelId}; use crate::{Channel, ChannelId};
use collections::BTreeMap; use collections::BTreeMap;
use rpc2::proto; use rpc::proto;
use std::sync::Arc; use std::sync::Arc;
#[derive(Default, Debug)] #[derive(Default, Debug)]

View file

@ -1,13 +1,13 @@
use crate::channel_chat::ChannelChatEvent; use crate::channel_chat::ChannelChatEvent;
use super::*; use super::*;
use client2::{test::FakeServer, Client, UserStore}; use client::{test::FakeServer, Client, UserStore};
use gpui2::{AppContext, Context, Model, TestAppContext}; use gpui::{AppContext, Context, Model, TestAppContext};
use rpc2::proto::{self}; use rpc::proto::{self};
use settings2::SettingsStore; use settings::SettingsStore;
use util::http::FakeHttpClient; use util::http::FakeHttpClient;
#[gpui2::test] #[gpui::test]
fn test_update_channels(cx: &mut AppContext) { fn test_update_channels(cx: &mut AppContext) {
let channel_store = init_test(cx); 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) { fn test_dangling_channel_paths(cx: &mut AppContext) {
let channel_store = init_test(cx); 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) { async fn test_channel_messages(cx: &mut TestAppContext) {
let user_id = 5; let user_id = 5;
let channel_id = 5; let channel_id = 5;
@ -349,7 +349,7 @@ fn init_test(cx: &mut AppContext) -> Model<ChannelStore> {
let settings_store = SettingsStore::test(cx); let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store); cx.set_global(settings_store);
client2::init(&client, cx); client::init(&client, cx);
crate::init(&client, user_store, cx); crate::init(&client, user_store, cx);
ChannelStore::global(cx) ChannelStore::global(cx)