Detailed changes
@@ -1021,6 +1021,27 @@ dependencies = [
"syn",
]
+[[package]]
+name = "client"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "async-recursion",
+ "async-tungstenite",
+ "gpui",
+ "lazy_static",
+ "log",
+ "parking_lot",
+ "postage",
+ "rand 0.8.3",
+ "rpc",
+ "smol",
+ "surf",
+ "thiserror",
+ "tiny_http",
+ "util",
+]
+
[[package]]
name = "clock"
version = "0.1.0"
@@ -3685,6 +3706,7 @@ dependencies = [
"anyhow",
"async-trait",
"buffer",
+ "client",
"clock",
"fsevent",
"futures",
@@ -3698,7 +3720,6 @@ dependencies = [
"postage",
"rand 0.8.3",
"rpc",
- "rpc_client",
"serde 1.0.125",
"serde_json 1.0.64",
"smol",
@@ -4166,27 +4187,6 @@ dependencies = [
"zstd",
]
-[[package]]
-name = "rpc_client"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "async-recursion",
- "async-tungstenite",
- "gpui",
- "lazy_static",
- "log",
- "parking_lot",
- "postage",
- "rand 0.8.3",
- "rpc",
- "smol",
- "surf",
- "thiserror",
- "tiny_http",
- "util",
-]
-
[[package]]
name = "rsa"
version = "0.4.0"
@@ -6052,6 +6052,7 @@ dependencies = [
"async-tungstenite",
"buffer",
"cargo-bundle",
+ "client",
"clock",
"crossbeam-channel",
"ctor",
@@ -6077,7 +6078,6 @@ dependencies = [
"project",
"rand 0.8.3",
"rpc",
- "rpc_client",
"rsa",
"rust-embed",
"serde 1.0.125",
@@ -23,6 +23,7 @@ pub use point::*;
#[cfg(any(test, feature = "test-support"))]
pub use random_char_iter::*;
pub use rope::{Chunks, Rope, TextSummary};
+use rpc::proto;
use seahash::SeaHasher;
pub use selection::*;
use similar::{ChangeTag, TextDiff};
@@ -40,10 +41,9 @@ use std::{
sync::Arc,
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
};
-use sum_tree::{self, Bias, FilterCursor, SumTree};
+use sum_tree::{Bias, FilterCursor, SumTree};
pub use syntax_theme::SyntaxTheme;
use tree_sitter::{InputEdit, Parser, QueryCursor};
-use rpc::proto;
pub trait File {
fn worktree_id(&self) -> usize;
@@ -2,7 +2,7 @@ use super::Point;
use arrayvec::ArrayString;
use smallvec::SmallVec;
use std::{cmp, ops::Range, str};
-use sum_tree::{self, Bias, SumTree};
+use sum_tree::{Bias, SumTree};
#[cfg(test)]
const CHUNK_BASE: usize = 6;
@@ -1,5 +1,5 @@
[package]
-name = "rpc_client"
+name = "client"
version = "0.1.0"
edition = "2018"
@@ -2,7 +2,7 @@ mod fold_map;
mod tab_map;
mod wrap_map;
-use buffer::{self, Anchor, Buffer, Point, ToOffset, ToPoint};
+use buffer::{Anchor, Buffer, Point, ToOffset, ToPoint};
use fold_map::{FoldMap, ToFoldPoint as _};
use gpui::{fonts::FontId, Entity, ModelContext, ModelHandle};
use std::ops::Range;
@@ -1,8 +1,4 @@
-use super::{
- buffer::{AnchorRangeExt, TextSummary},
- Anchor, Buffer, Point, ToOffset,
-};
-use buffer::HighlightId;
+use buffer::{Anchor, Buffer, Point, ToOffset, AnchorRangeExt, HighlightId, TextSummary};
use gpui::{AppContext, ModelHandle};
use parking_lot::Mutex;
use std::{
@@ -11,7 +7,7 @@ use std::{
ops::Range,
sync::atomic::{AtomicUsize, Ordering::SeqCst},
};
-use sum_tree::{self, Bias, Cursor, FilterCursor, SumTree};
+use sum_tree::{Bias, Cursor, FilterCursor, SumTree};
pub trait ToFoldPoint {
fn to_fold_point(&self, snapshot: &Snapshot, bias: Bias) -> FoldPoint;
@@ -7,7 +7,7 @@ use gpui::{fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, Task};
use lazy_static::lazy_static;
use smol::future::yield_now;
use std::{collections::VecDeque, ops::Range, time::Duration};
-use sum_tree::{self, Bias, Cursor, SumTree};
+use sum_tree::{Bias, Cursor, SumTree};
pub struct WrapMap {
snapshot: Snapshot,
@@ -8,7 +8,7 @@ use crate::{
SizeConstraint,
};
use std::{cell::RefCell, collections::VecDeque, ops::Range, rc::Rc};
-use sum_tree::{self, Bias, SumTree};
+use sum_tree::{Bias, SumTree};
pub struct List {
state: ListState,
@@ -4,7 +4,7 @@ use crate::geometry::{
};
use etagere::BucketedAtlasAllocator;
use foreign_types::ForeignType;
-use metal::{self, Device, TextureDescriptor};
+use metal::{Device, TextureDescriptor};
use objc::{msg_send, sel, sel_impl};
pub struct AtlasAllocator {
@@ -12,7 +12,7 @@ clock = { path = "../clock" }
fsevent = { path = "../fsevent" }
fuzzy = { path = "../fuzzy" }
gpui = { path = "../gpui" }
-rpc_client = { path = "../rpc_client" }
+client = { path = "../client" }
sum_tree = { path = "../sum_tree" }
util = { path = "../util" }
rpc = { path = "../rpc" }
@@ -32,7 +32,7 @@ smol = "1.2.5"
toml = "0.5"
[dev-dependencies]
-rpc_client = { path = "../rpc_client", features = ["test-support"] }
+client = { path = "../client", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] }
rpc = { path = "../rpc", features = ["test-support"] }
@@ -4,10 +4,10 @@ mod worktree;
use anyhow::Result;
use buffer::LanguageRegistry;
+use client::Client;
use futures::Future;
-use fuzzy::{self, PathMatch, PathMatchCandidate, PathMatchCandidateSet};
+use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
-use rpc_client as rpc;
use std::{
path::Path,
sync::{atomic::AtomicBool, Arc},
@@ -21,7 +21,7 @@ pub struct Project {
worktrees: Vec<ModelHandle<Worktree>>,
active_entry: Option<ProjectEntry>,
languages: Arc<LanguageRegistry>,
- rpc: Arc<rpc::Client>,
+ client: Arc<client::Client>,
fs: Arc<dyn Fs>,
}
@@ -43,12 +43,12 @@ pub struct ProjectEntry {
}
impl Project {
- pub fn new(languages: Arc<LanguageRegistry>, rpc: Arc<rpc::Client>, fs: Arc<dyn Fs>) -> Self {
+ pub fn new(languages: Arc<LanguageRegistry>, rpc: Arc<Client>, fs: Arc<dyn Fs>) -> Self {
Self {
worktrees: Default::default(),
active_entry: None,
languages,
- rpc,
+ client: rpc,
fs,
}
}
@@ -70,7 +70,7 @@ impl Project {
cx: &mut ModelContext<Self>,
) -> Task<Result<ModelHandle<Worktree>>> {
let fs = self.fs.clone();
- let rpc = self.rpc.clone();
+ let rpc = self.client.clone();
let languages = self.languages.clone();
let path = Arc::from(abs_path);
cx.spawn(|this, mut cx| async move {
@@ -87,7 +87,7 @@ impl Project {
remote_id: u64,
cx: &mut ModelContext<Self>,
) -> Task<Result<ModelHandle<Worktree>>> {
- let rpc = self.rpc.clone();
+ let rpc = self.client.clone();
let languages = self.languages.clone();
cx.spawn(|this, mut cx| async move {
rpc.authenticate_and_connect(&cx).await?;
@@ -133,7 +133,7 @@ impl Project {
}
pub fn share_worktree(&self, remote_id: u64, cx: &mut ModelContext<Self>) {
- let rpc = self.rpc.clone();
+ let rpc = self.client.clone();
cx.spawn(|this, mut cx| {
async move {
rpc.authenticate_and_connect(&cx).await?;
@@ -407,7 +407,7 @@ mod tests {
fn build_project(cx: &mut TestAppContext) -> ModelHandle<Project> {
let languages = Arc::new(LanguageRegistry::new());
let fs = Arc::new(RealFs);
- let rpc = rpc::Client::new();
+ let rpc = client::Client::new();
cx.add_model(|_| Project::new(languages, rpc, fs))
}
}
@@ -4,7 +4,8 @@ use super::{
};
use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
use anyhow::{anyhow, Result};
-use buffer::{self, Buffer, History, LanguageRegistry, Operation, Rope};
+use buffer::{Buffer, History, LanguageRegistry, Operation, Rope};
+use client::{proto, Client, PeerId, TypedEnvelope};
use clock::ReplicaId;
use futures::{Stream, StreamExt};
use fuzzy::CharBag;
@@ -18,7 +19,6 @@ use postage::{
prelude::{Sink as _, Stream as _},
watch,
};
-use rpc_client::{self as rpc, proto, PeerId, TypedEnvelope};
use serde::Deserialize;
use smol::channel::{self, Sender};
use std::{
@@ -38,7 +38,7 @@ use std::{
time::{Duration, SystemTime},
};
use sum_tree::Bias;
-use sum_tree::{self, Edit, SeekTarget, SumTree};
+use sum_tree::{Edit, SeekTarget, SumTree};
use util::TryFutureExt;
lazy_static! {
@@ -78,7 +78,7 @@ impl Entity for Worktree {
}
}
Self::Remote(tree) => {
- let rpc = tree.rpc.clone();
+ let rpc = tree.client.clone();
let worktree_id = tree.remote_id;
cx.spawn(|_| async move {
if let Err(err) = rpc.send(proto::LeaveWorktree { worktree_id }).await {
@@ -93,7 +93,7 @@ impl Entity for Worktree {
impl Worktree {
pub async fn open_local(
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
path: impl Into<Arc<Path>>,
fs: Arc<dyn Fs>,
languages: Arc<LanguageRegistry>,
@@ -117,7 +117,7 @@ impl Worktree {
}
pub async fn open_remote(
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
id: u64,
languages: Arc<LanguageRegistry>,
cx: &mut AsyncAppContext,
@@ -128,7 +128,7 @@ impl Worktree {
async fn remote(
join_response: proto::JoinWorktreeResponse,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
languages: Arc<LanguageRegistry>,
cx: &mut AsyncAppContext,
) -> Result<ModelHandle<Self>> {
@@ -232,7 +232,7 @@ impl Worktree {
snapshot,
snapshot_rx,
updates_tx,
- rpc: rpc.clone(),
+ client: rpc.clone(),
open_buffers: Default::default(),
peers: peers
.into_iter()
@@ -296,7 +296,7 @@ impl Worktree {
pub fn handle_add_peer(
&mut self,
envelope: TypedEnvelope<proto::AddPeer>,
- _: Arc<rpc::Client>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
match self {
@@ -308,7 +308,7 @@ impl Worktree {
pub fn handle_remove_peer(
&mut self,
envelope: TypedEnvelope<proto::RemovePeer>,
- _: Arc<rpc::Client>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
match self {
@@ -320,7 +320,7 @@ impl Worktree {
pub fn handle_update(
&mut self,
envelope: TypedEnvelope<proto::UpdateWorktree>,
- _: Arc<rpc::Client>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> anyhow::Result<()> {
self.as_remote_mut()
@@ -331,7 +331,7 @@ impl Worktree {
pub fn handle_open_buffer(
&mut self,
envelope: TypedEnvelope<proto::OpenBuffer>,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> anyhow::Result<()> {
let receipt = envelope.receipt();
@@ -357,7 +357,7 @@ impl Worktree {
pub fn handle_close_buffer(
&mut self,
envelope: TypedEnvelope<proto::CloseBuffer>,
- _: Arc<rpc::Client>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> anyhow::Result<()> {
self.as_local_mut()
@@ -413,7 +413,7 @@ impl Worktree {
pub fn handle_update_buffer(
&mut self,
envelope: TypedEnvelope<proto::UpdateBuffer>,
- _: Arc<rpc::Client>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
let payload = envelope.payload.clone();
@@ -460,7 +460,7 @@ impl Worktree {
pub fn handle_save_buffer(
&mut self,
envelope: TypedEnvelope<proto::SaveBuffer>,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
let sender_id = envelope.original_sender_id()?;
@@ -507,7 +507,7 @@ impl Worktree {
pub fn handle_buffer_saved(
&mut self,
envelope: TypedEnvelope<proto::BufferSaved>,
- _: Arc<rpc::Client>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
let payload = envelope.payload.clone();
@@ -533,7 +533,7 @@ impl Worktree {
pub fn handle_unshare(
&mut self,
_: TypedEnvelope<proto::UnshareWorktree>,
- _: Arc<rpc::Client>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
cx.emit(Event::Closed);
@@ -682,7 +682,7 @@ pub struct LocalWorktree {
peers: HashMap<PeerId, ReplicaId>,
languages: Arc<LanguageRegistry>,
queued_operations: Vec<(u64, Operation)>,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
fs: Arc<dyn Fs>,
}
@@ -693,7 +693,7 @@ struct WorktreeConfig {
impl LocalWorktree {
async fn new(
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
path: impl Into<Arc<Path>>,
fs: Arc<dyn Fs>,
languages: Arc<LanguageRegistry>,
@@ -753,7 +753,7 @@ impl LocalWorktree {
let mut status = rpc.status();
while let Some(status) = status.recv().await {
if let Some(this) = this.upgrade(&cx) {
- let remote_id = if let rpc::Status::Connected { .. } = status {
+ let remote_id = if let client::Status::Connected { .. } = status {
let collaborator_logins = this.read_with(&cx, |this, _| {
this.as_local().unwrap().config.collaborators.clone()
});
@@ -1217,21 +1217,21 @@ impl fmt::Debug for LocalWorktree {
struct ShareState {
snapshots_tx: Sender<Snapshot>,
- _subscriptions: Vec<rpc::Subscription>,
+ _subscriptions: Vec<client::Subscription>,
}
pub struct RemoteWorktree {
remote_id: u64,
snapshot: Snapshot,
snapshot_rx: watch::Receiver<Snapshot>,
- rpc: Arc<rpc::Client>,
+ client: Arc<Client>,
updates_tx: postage::mpsc::Sender<proto::UpdateWorktree>,
replica_id: ReplicaId,
open_buffers: HashMap<usize, RemoteBuffer>,
peers: HashMap<PeerId, ReplicaId>,
languages: Arc<LanguageRegistry>,
queued_operations: Vec<(u64, Operation)>,
- _subscriptions: Vec<rpc::Subscription>,
+ _subscriptions: Vec<client::Subscription>,
}
impl RemoteWorktree {
@@ -1254,7 +1254,7 @@ impl RemoteWorktree {
}
});
- let rpc = self.rpc.clone();
+ let rpc = self.client.clone();
let replica_id = self.replica_id;
let remote_worktree_id = self.remote_id;
let path = path.to_string_lossy().to_string();
@@ -1867,7 +1867,7 @@ impl buffer::File for File {
})
}
Worktree::Remote(worktree) => {
- let rpc = worktree.rpc.clone();
+ let rpc = worktree.client.clone();
let worktree_id = worktree.remote_id;
cx.foreground().spawn(async move {
let response = rpc
@@ -1894,7 +1894,7 @@ impl buffer::File for File {
.remote_id
.borrow()
.map(|id| (worktree.rpc.clone(), id)),
- Worktree::Remote(worktree) => Some((worktree.rpc.clone(), worktree.remote_id)),
+ Worktree::Remote(worktree) => Some((worktree.client.clone(), worktree.remote_id)),
} {
cx.spawn(|worktree, mut cx| async move {
if let Err(error) = rpc
@@ -1924,7 +1924,7 @@ impl buffer::File for File {
self.worktree.update(cx, |worktree, cx| {
if let Worktree::Remote(worktree) = worktree {
let worktree_id = worktree.remote_id;
- let rpc = worktree.rpc.clone();
+ let rpc = worktree.client.clone();
cx.background()
.spawn(async move {
if let Err(error) = rpc
@@ -2832,9 +2832,9 @@ mod tests {
use super::*;
use crate::fs::FakeFs;
use anyhow::Result;
+ use client::test::FakeServer;
use fs::RealFs;
use rand::prelude::*;
- use rpc_client::test::FakeServer;
use serde_json::json;
use std::{cell::RefCell, rc::Rc};
use std::{
@@ -2860,7 +2860,7 @@ mod tests {
.await;
let tree = Worktree::open_local(
- rpc::Client::new(),
+ Client::new(),
Arc::from(Path::new("/root")),
Arc::new(fs),
Default::default(),
@@ -2892,7 +2892,7 @@ mod tests {
"file1": "the old contents",
}));
let tree = Worktree::open_local(
- rpc::Client::new(),
+ Client::new(),
dir.path(),
Arc::new(RealFs),
Default::default(),
@@ -2922,7 +2922,7 @@ mod tests {
let file_path = dir.path().join("file1");
let tree = Worktree::open_local(
- rpc::Client::new(),
+ Client::new(),
file_path.clone(),
Arc::new(RealFs),
Default::default(),
@@ -2965,7 +2965,7 @@ mod tests {
}));
let user_id = 5;
- let mut client = rpc::Client::new();
+ let mut client = Client::new();
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let tree = Worktree::open_local(
client,
@@ -3022,7 +3022,7 @@ mod tests {
replica_id: 1,
peers: Vec::new(),
},
- rpc::Client::new(),
+ Client::new(),
Default::default(),
&mut cx.to_async(),
)
@@ -3128,7 +3128,7 @@ mod tests {
}));
let tree = Worktree::open_local(
- rpc::Client::new(),
+ Client::new(),
dir.path(),
Arc::new(RealFs),
Default::default(),
@@ -3164,7 +3164,7 @@ mod tests {
#[gpui::test]
async fn test_open_and_share_worktree(mut cx: gpui::TestAppContext) {
let user_id = 100;
- let mut client = rpc::Client::new();
+ let mut client = Client::new();
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let fs = Arc::new(FakeFs::new());
@@ -3230,7 +3230,7 @@ mod tests {
"file3": "ghi",
}));
let tree = Worktree::open_local(
- rpc::Client::new(),
+ Client::new(),
dir.path(),
Arc::new(RealFs),
Default::default(),
@@ -3363,7 +3363,7 @@ mod tests {
let initial_contents = "aaa\nbbbbb\nc\n";
let dir = temp_tree(json!({ "the-file": initial_contents }));
let tree = Worktree::open_local(
- rpc::Client::new(),
+ Client::new(),
dir.path(),
Arc::new(RealFs),
Default::default(),
@@ -978,11 +978,11 @@ mod tests {
use zed::{
buffer::LanguageRegistry,
channel::{Channel, ChannelDetails, ChannelList},
+ client::{self, Client, Credentials, EstablishConnectionError},
editor::{Editor, EditorSettings, Insert},
fs::{FakeFs, Fs as _},
people_panel::JoinWorktree,
project::{ProjectPath, Worktree},
- rpc::{self, Client, Credentials, EstablishConnectionError},
test::FakeHttpClient,
user::UserStore,
workspace::Workspace,
@@ -1103,7 +1103,7 @@ mod tests {
let (client_a, _) = server.create_client(&mut cx_a, "user_a").await;
let (client_b, user_store_b) = server.create_client(&mut cx_b, "user_b").await;
let app_state_b = zed::AppState {
- rpc: client_b,
+ client: client_b,
user_store: user_store_b,
..Arc::try_unwrap(cx_b.update(zed::test::test_app_state))
.ok()
@@ -1889,7 +1889,7 @@ mod tests {
server.disconnect_client(current_user_id(&user_store_b, &cx_b));
while !matches!(
status_b.recv().await,
- Some(rpc::Status::ReconnectionError { .. })
+ Some(client::Status::ReconnectionError { .. })
) {}
channels_b.read_with(&cx_b, |channels, _| {
@@ -16,15 +16,16 @@ path = "src/main.rs"
[features]
test-support = [
"buffer/test-support",
+ "client/test-support",
"gpui/test-support",
"project/test-support",
"rpc/test-support",
- "rpc_client/test-support",
"tempdir",
]
[dependencies]
buffer = { path = "../buffer" }
+client = { path = "../client" }
clock = { path = "../clock" }
fsevent = { path = "../fsevent" }
fuzzy = { path = "../fuzzy" }
@@ -32,7 +33,6 @@ editor = { path = "../editor" }
gpui = { path = "../gpui" }
project = { path = "../project" }
rpc = { path = "../rpc" }
-rpc_client = { path = "../rpc_client" }
sum_tree = { path = "../sum_tree" }
util = { path = "../util" }
@@ -81,7 +81,7 @@ editor = { path = "../editor", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] }
project = { path = "../project", features = ["test-support"] }
rpc = { path = "../rpc", features = ["test-support"] }
-rpc_client = { path = "../rpc_client", features = ["test-support"] }
+client = { path = "../client", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] }
cargo-bundle = "0.5.0"
@@ -1,29 +1,25 @@
use crate::user::{User, UserStore};
use anyhow::{anyhow, Context, Result};
+use client::{proto, Client, TypedEnvelope};
use gpui::{
AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakModelHandle,
};
use postage::prelude::Stream;
use rand::prelude::*;
-use rpc_client::{
- self as rpc,
- proto::{self, ChannelMessageSent},
- TypedEnvelope,
-};
use std::{
collections::{HashMap, HashSet},
mem,
ops::Range,
sync::Arc,
};
-use sum_tree::{self, Bias, SumTree};
+use sum_tree::{Bias, SumTree};
use time::OffsetDateTime;
use util::{post_inc, TryFutureExt};
pub struct ChannelList {
available_channels: Option<Vec<ChannelDetails>>,
channels: HashMap<u64, WeakModelHandle<Channel>>,
- rpc: Arc<rpc::Client>,
+ client: Arc<Client>,
user_store: ModelHandle<UserStore>,
_task: Task<Option<()>>,
}
@@ -40,9 +36,9 @@ pub struct Channel {
loaded_all_messages: bool,
next_pending_message_id: usize,
user_store: ModelHandle<UserStore>,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
rng: StdRng,
- _subscription: rpc::Subscription,
+ _subscription: client::Subscription,
}
#[derive(Clone, Debug)]
@@ -86,7 +82,7 @@ impl Entity for ChannelList {
impl ChannelList {
pub fn new(
user_store: ModelHandle<UserStore>,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Self {
let _task = cx.spawn_weak(|this, mut cx| {
@@ -95,7 +91,7 @@ impl ChannelList {
let mut status = rpc.status();
while let Some((status, this)) = status.recv().await.zip(this.upgrade(&cx)) {
match status {
- rpc::Status::Connected { .. } => {
+ client::Status::Connected { .. } => {
let response = rpc
.request(proto::GetChannels {})
.await
@@ -119,7 +115,7 @@ impl ChannelList {
cx.notify();
});
}
- rpc::Status::SignedOut { .. } => {
+ client::Status::SignedOut { .. } => {
this.update(&mut cx, |this, cx| {
this.available_channels = None;
this.channels.clear();
@@ -138,7 +134,7 @@ impl ChannelList {
available_channels: None,
channels: Default::default(),
user_store,
- rpc,
+ client: rpc,
_task,
}
}
@@ -158,8 +154,9 @@ impl ChannelList {
let channels = self.available_channels.as_ref()?;
let details = channels.iter().find(|details| details.id == id)?.clone();
- let channel =
- cx.add_model(|cx| Channel::new(details, self.user_store.clone(), self.rpc.clone(), cx));
+ let channel = cx.add_model(|cx| {
+ Channel::new(details, self.user_store.clone(), self.client.clone(), cx)
+ });
self.channels.insert(id, channel.downgrade());
Some(channel)
}
@@ -185,7 +182,7 @@ impl Channel {
pub fn new(
details: ChannelDetails,
user_store: ModelHandle<UserStore>,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Self {
let _subscription = rpc.subscribe_to_entity(details.id, cx, Self::handle_message_sent);
@@ -404,8 +401,8 @@ impl Channel {
fn handle_message_sent(
&mut self,
- message: TypedEnvelope<ChannelMessageSent>,
- _: Arc<rpc::Client>,
+ message: TypedEnvelope<proto::ChannelMessageSent>,
+ _: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
let user_store = self.user_store.clone();
@@ -593,14 +590,14 @@ impl<'a> sum_tree::Dimension<'a, ChannelMessageSummary> for Count {
mod tests {
use super::*;
use crate::test::FakeHttpClient;
+ use client::test::FakeServer;
use gpui::TestAppContext;
- use rpc_client::test::FakeServer;
use surf::http::Response;
#[gpui::test]
async fn test_channel_messages(mut cx: TestAppContext) {
let user_id = 5;
- let mut client = rpc::Client::new();
+ let mut client = Client::new();
let http_client = FakeHttpClient::new(|_| async move { Ok(Response::new(404)) });
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
@@ -2,6 +2,7 @@ use crate::{
channel::{Channel, ChannelEvent, ChannelList, ChannelMessage},
theme, Settings,
};
+use client::Client;
use editor::{Editor, EditorSettings};
use gpui::{
action,
@@ -13,7 +14,6 @@ use gpui::{
ViewContext, ViewHandle,
};
use postage::{prelude::Stream, watch};
-use rpc_client as rpc;
use std::sync::Arc;
use time::{OffsetDateTime, UtcOffset};
use util::{ResultExt, TryFutureExt};
@@ -21,7 +21,7 @@ use util::{ResultExt, TryFutureExt};
const MESSAGE_LOADING_THRESHOLD: usize = 50;
pub struct ChatPanel {
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
channel_list: ModelHandle<ChannelList>,
active_channel: Option<(ModelHandle<Channel>, Subscription)>,
message_list: ListState,
@@ -46,7 +46,7 @@ pub fn init(cx: &mut MutableAppContext) {
impl ChatPanel {
pub fn new(
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
channel_list: ModelHandle<ChannelList>,
settings: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>,
@@ -409,7 +409,10 @@ impl View for ChatPanel {
}
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
- if matches!(*self.rpc.status().borrow(), rpc::Status::Connected { .. }) {
+ if matches!(
+ *self.rpc.status().borrow(),
+ client::Status::Connected { .. }
+ ) {
cx.focus(&self.input_editor);
}
}
@@ -1,5 +1,5 @@
use crate::{settings::Settings, workspace::Workspace};
-use editor::{self, Editor, EditorSettings};
+use editor::{Editor, EditorSettings};
use fuzzy::PathMatch;
use gpui::{
action,
@@ -423,7 +423,7 @@ impl FileFinder {
mod tests {
use super::*;
use crate::{test::test_app_state, workspace::Workspace};
- use editor::{self, Insert};
+ use editor::Insert;
use project::fs::FakeFs;
use serde_json::json;
use std::path::PathBuf;
@@ -18,12 +18,12 @@ pub mod workspace;
pub use buffer;
use buffer::LanguageRegistry;
use channel::ChannelList;
+pub use client;
pub use editor;
use gpui::{action, keymap::Binding, ModelHandle};
use parking_lot::Mutex;
use postage::watch;
pub use project::{self, fs};
-pub use rpc_client as rpc;
pub use settings::Settings;
use std::sync::Arc;
use util::TryFutureExt;
@@ -40,7 +40,7 @@ pub struct AppState {
pub settings: watch::Receiver<Settings>,
pub languages: Arc<LanguageRegistry>,
pub themes: Arc<settings::ThemeRegistry>,
- pub rpc: Arc<rpc::Client>,
+ pub client: Arc<client::Client>,
pub user_store: ModelHandle<user::UserStore>,
pub fs: Arc<dyn fs::Fs>,
pub channel_list: ModelHandle<ChannelList>,
@@ -50,7 +50,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.add_global_action(quit);
cx.add_global_action({
- let rpc = app_state.rpc.clone();
+ let rpc = app_state.client.clone();
move |_: &Authenticate, cx| {
let rpc = rpc.clone();
cx.spawn(|cx| async move { rpc.authenticate_and_connect(&cx).log_err().await })
@@ -11,9 +11,9 @@ use zed::{
self,
assets::Assets,
channel::ChannelList,
- chat_panel, editor, file_finder,
+ chat_panel, client, editor, file_finder,
fs::RealFs,
- http, language, menus, project_panel, rpc, settings, theme_selector,
+ http, language, menus, project_panel, settings, theme_selector,
user::UserStore,
workspace::{self, OpenNew, OpenParams, OpenPaths},
AppState,
@@ -36,16 +36,17 @@ fn main() {
languages.set_theme(&settings.borrow().theme.editor.syntax);
app.run(move |cx| {
- let rpc = rpc::Client::new();
+ let client = client::Client::new();
let http = http::client();
- let user_store = cx.add_model(|cx| UserStore::new(rpc.clone(), http.clone(), cx));
+ let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
let app_state = Arc::new(AppState {
languages: languages.clone(),
settings_tx: Arc::new(Mutex::new(settings_tx)),
settings,
themes,
- channel_list: cx.add_model(|cx| ChannelList::new(user_store.clone(), rpc.clone(), cx)),
- rpc,
+ channel_list: cx
+ .add_model(|cx| ChannelList::new(user_store.clone(), client.clone(), cx)),
+ client,
user_store,
fs: Arc::new(RealFs),
});
@@ -626,7 +626,7 @@ mod tests {
let project = cx.add_model(|_| {
Project::new(
app_state.languages.clone(),
- app_state.rpc.clone(),
+ app_state.client.clone(),
app_state.fs.clone(),
)
});
@@ -9,11 +9,11 @@ use crate::{
};
use anyhow::Result;
use buffer::LanguageRegistry;
+use client::Client;
use futures::{future::BoxFuture, Future};
use gpui::MutableAppContext;
use parking_lot::Mutex;
use project::fs::FakeFs;
-use rpc_client as rpc;
use std::{fmt, sync::Arc};
#[cfg(test)]
@@ -27,16 +27,16 @@ pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
let mut languages = LanguageRegistry::new();
languages.add(Arc::new(language::rust()));
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone());
- let rpc = rpc::Client::new();
+ let client = Client::new();
let http = FakeHttpClient::new(|_| async move { Ok(ServerResponse::new(404)) });
- let user_store = cx.add_model(|cx| UserStore::new(rpc.clone(), http, cx));
+ let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx));
Arc::new(AppState {
settings_tx: Arc::new(Mutex::new(settings_tx)),
settings,
themes,
languages: Arc::new(languages),
- channel_list: cx.add_model(|cx| ChannelList::new(user_store.clone(), rpc.clone(), cx)),
- rpc,
+ channel_list: cx.add_model(|cx| ChannelList::new(user_store.clone(), client.clone(), cx)),
+ client,
user_store,
fs: Arc::new(FakeFs::new()),
})
@@ -1,5 +1,5 @@
use crate::{settings::ThemeRegistry, workspace::Workspace, AppState, Settings};
-use editor::{self, Editor, EditorSettings};
+use editor::{Editor, EditorSettings};
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{
action,
@@ -1,9 +1,9 @@
use crate::http::{HttpClient, Method, Request, Url};
use anyhow::{anyhow, Context, Result};
+use client::{proto, Client, TypedEnvelope};
use futures::future;
use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task};
use postage::{prelude::Stream, sink::Sink, watch};
-use rpc_client::{self as rpc, proto, TypedEnvelope};
use std::{
collections::{HashMap, HashSet},
sync::Arc,
@@ -35,7 +35,7 @@ pub struct UserStore {
users: HashMap<u64, Arc<User>>,
current_user: watch::Receiver<Option<Arc<User>>>,
collaborators: Arc<[Collaborator]>,
- rpc: Arc<rpc::Client>,
+ rpc: Arc<Client>,
http: Arc<dyn HttpClient>,
_maintain_collaborators: Task<()>,
_maintain_current_user: Task<()>,
@@ -48,11 +48,7 @@ impl Entity for UserStore {
}
impl UserStore {
- pub fn new(
- rpc: Arc<rpc::Client>,
- http: Arc<dyn HttpClient>,
- cx: &mut ModelContext<Self>,
- ) -> Self {
+ pub fn new(rpc: Arc<Client>, http: Arc<dyn HttpClient>, cx: &mut ModelContext<Self>) -> Self {
let (mut current_user_tx, current_user_rx) = watch::channel();
let (mut update_collaborators_tx, mut update_collaborators_rx) =
watch::channel::<Option<proto::UpdateCollaborators>>();
@@ -83,7 +79,7 @@ impl UserStore {
let mut status = rpc.status();
while let Some(status) = status.recv().await {
match status {
- rpc::Status::Connected { .. } => {
+ client::Status::Connected { .. } => {
if let Some((this, user_id)) = this.upgrade(&cx).zip(rpc.user_id()) {
let user = this
.update(&mut cx, |this, cx| this.fetch_user(user_id, cx))
@@ -92,7 +88,7 @@ impl UserStore {
current_user_tx.send(user).await.ok();
}
}
- rpc::Status::SignedOut => {
+ client::Status::SignedOut => {
current_user_tx.send(None).await.ok();
}
_ => {}
@@ -9,7 +9,6 @@ use crate::{
people_panel::{JoinWorktree, LeaveWorktree, PeoplePanel, ShareWorktree, UnshareWorktree},
project::{Project, ProjectPath},
project_panel::ProjectPanel,
- rpc,
settings::Settings,
user,
workspace::sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus},
@@ -17,6 +16,7 @@ use crate::{
};
use anyhow::Result;
use buffer::Buffer;
+use client::Client;
use gpui::{
action,
elements::*,
@@ -356,7 +356,7 @@ impl Clone for Box<dyn ItemHandle> {
pub struct Workspace {
pub settings: watch::Receiver<Settings>,
- rpc: Arc<rpc::Client>,
+ client: Arc<Client>,
user_store: ModelHandle<user::UserStore>,
fs: Arc<dyn Fs>,
modal: Option<AnyViewHandle>,
@@ -379,7 +379,7 @@ impl Workspace {
let project = cx.add_model(|_| {
Project::new(
app_state.languages.clone(),
- app_state.rpc.clone(),
+ app_state.client.clone(),
app_state.fs.clone(),
)
});
@@ -417,7 +417,7 @@ impl Workspace {
"icons/comment-16.svg",
cx.add_view(|cx| {
ChatPanel::new(
- app_state.rpc.clone(),
+ app_state.client.clone(),
app_state.channel_list.clone(),
app_state.settings.clone(),
cx,
@@ -427,7 +427,7 @@ impl Workspace {
);
let mut current_user = app_state.user_store.read(cx).watch_current_user().clone();
- let mut connection_status = app_state.rpc.status().clone();
+ let mut connection_status = app_state.client.status().clone();
let _observe_current_user = cx.spawn_weak(|this, mut cx| async move {
current_user.recv().await;
connection_status.recv().await;
@@ -449,7 +449,7 @@ impl Workspace {
panes: vec![pane.clone()],
active_pane: pane.clone(),
settings: app_state.settings.clone(),
- rpc: app_state.rpc.clone(),
+ client: app_state.client.clone(),
user_store: app_state.user_store.clone(),
fs: app_state.fs.clone(),
left_sidebar,
@@ -981,12 +981,12 @@ impl Workspace {
fn render_connection_status(&self) -> Option<ElementBox> {
let theme = &self.settings.borrow().theme;
- match &*self.rpc.status().borrow() {
- rpc::Status::ConnectionError
- | rpc::Status::ConnectionLost
- | rpc::Status::Reauthenticating
- | rpc::Status::Reconnecting { .. }
- | rpc::Status::ReconnectionError { .. } => Some(
+ match &*self.client.status().borrow() {
+ client::Status::ConnectionError
+ | client::Status::ConnectionLost
+ | client::Status::Reauthenticating
+ | client::Status::Reconnecting { .. }
+ | client::Status::ReconnectionError { .. } => Some(
Container::new(
Align::new(
ConstrainedBox::new(
@@ -1002,7 +1002,7 @@ impl Workspace {
.with_style(theme.workspace.titlebar.offline_icon.container)
.boxed(),
),
- rpc::Status::UpgradeRequired => Some(
+ client::Status::UpgradeRequired => Some(
Label::new(
"Please update Zed to collaborate".to_string(),
theme.workspace.titlebar.outdated_warning.text.clone(),