From 94209d2b6d0d7e7b0014d9efeb4287a273eb6f90 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 4 Oct 2021 17:14:21 -0700 Subject: [PATCH] Rename rpc_client -> client Co-Authored-By: Nathan Sobo --- Cargo.lock | 46 +++++++------- crates/buffer/src/lib.rs | 4 +- crates/buffer/src/rope.rs | 2 +- crates/{rpc_client => client}/Cargo.toml | 2 +- crates/{rpc_client => client}/src/lib.rs | 0 crates/{rpc_client => client}/src/test.rs | 0 crates/editor/src/display_map.rs | 2 +- crates/editor/src/display_map/fold_map.rs | 8 +-- crates/editor/src/display_map/wrap_map.rs | 2 +- crates/gpui/src/elements/list.rs | 2 +- crates/gpui/src/platform/mac/atlas.rs | 2 +- crates/project/Cargo.toml | 4 +- crates/project/src/lib.rs | 18 +++--- crates/project/src/worktree.rs | 74 +++++++++++------------ crates/server/src/rpc.rs | 6 +- crates/zed/Cargo.toml | 6 +- crates/zed/src/channel.rs | 37 ++++++------ crates/zed/src/chat_panel.rs | 11 ++-- crates/zed/src/file_finder.rs | 4 +- crates/zed/src/lib.rs | 6 +- crates/zed/src/main.rs | 13 ++-- crates/zed/src/project_panel.rs | 2 +- crates/zed/src/test.rs | 10 +-- crates/zed/src/theme_selector.rs | 2 +- crates/zed/src/user.rs | 14 ++--- crates/zed/src/workspace.rs | 26 ++++---- 26 files changed, 148 insertions(+), 155 deletions(-) rename crates/{rpc_client => client}/Cargo.toml (96%) rename crates/{rpc_client => client}/src/lib.rs (100%) rename crates/{rpc_client => client}/src/test.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index a4536da262..e18a854fba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/crates/buffer/src/lib.rs b/crates/buffer/src/lib.rs index a857f47976..e664e5de4e 100644 --- a/crates/buffer/src/lib.rs +++ b/crates/buffer/src/lib.rs @@ -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; diff --git a/crates/buffer/src/rope.rs b/crates/buffer/src/rope.rs index 3177b26994..8467a98947 100644 --- a/crates/buffer/src/rope.rs +++ b/crates/buffer/src/rope.rs @@ -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; diff --git a/crates/rpc_client/Cargo.toml b/crates/client/Cargo.toml similarity index 96% rename from crates/rpc_client/Cargo.toml rename to crates/client/Cargo.toml index 2fd75685f8..0931de7c31 100644 --- a/crates/rpc_client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rpc_client" +name = "client" version = "0.1.0" edition = "2018" diff --git a/crates/rpc_client/src/lib.rs b/crates/client/src/lib.rs similarity index 100% rename from crates/rpc_client/src/lib.rs rename to crates/client/src/lib.rs diff --git a/crates/rpc_client/src/test.rs b/crates/client/src/test.rs similarity index 100% rename from crates/rpc_client/src/test.rs rename to crates/client/src/test.rs diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 7ba2fb3d77..931a7619d8 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -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; diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index cc1f1e1a8c..3dc671e59d 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -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; diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index 2b3433711e..fa26685a65 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -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, diff --git a/crates/gpui/src/elements/list.rs b/crates/gpui/src/elements/list.rs index 3fbd2a6d28..547b5be3f4 100644 --- a/crates/gpui/src/elements/list.rs +++ b/crates/gpui/src/elements/list.rs @@ -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, diff --git a/crates/gpui/src/platform/mac/atlas.rs b/crates/gpui/src/platform/mac/atlas.rs index e23a045d47..5e87474bf1 100644 --- a/crates/gpui/src/platform/mac/atlas.rs +++ b/crates/gpui/src/platform/mac/atlas.rs @@ -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 { diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index 1144aeec59..f7d87a4625 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -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"] } diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index 2be5c7ffa3..184dfd4d9c 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -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>, active_entry: Option, languages: Arc, - rpc: Arc, + client: Arc, fs: Arc, } @@ -43,12 +43,12 @@ pub struct ProjectEntry { } impl Project { - pub fn new(languages: Arc, rpc: Arc, fs: Arc) -> Self { + pub fn new(languages: Arc, rpc: Arc, fs: Arc) -> Self { Self { worktrees: Default::default(), active_entry: None, languages, - rpc, + client: rpc, fs, } } @@ -70,7 +70,7 @@ impl Project { cx: &mut ModelContext, ) -> Task>> { 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, ) -> Task>> { - 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) { - 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 { 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)) } } diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 4bccc58e35..3f27b0ed3f 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -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: Arc, path: impl Into>, fs: Arc, languages: Arc, @@ -117,7 +117,7 @@ impl Worktree { } pub async fn open_remote( - rpc: Arc, + rpc: Arc, id: u64, languages: Arc, cx: &mut AsyncAppContext, @@ -128,7 +128,7 @@ impl Worktree { async fn remote( join_response: proto::JoinWorktreeResponse, - rpc: Arc, + rpc: Arc, languages: Arc, cx: &mut AsyncAppContext, ) -> Result> { @@ -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, - _: Arc, + _: Arc, cx: &mut ModelContext, ) -> Result<()> { match self { @@ -308,7 +308,7 @@ impl Worktree { pub fn handle_remove_peer( &mut self, envelope: TypedEnvelope, - _: Arc, + _: Arc, cx: &mut ModelContext, ) -> Result<()> { match self { @@ -320,7 +320,7 @@ impl Worktree { pub fn handle_update( &mut self, envelope: TypedEnvelope, - _: Arc, + _: Arc, cx: &mut ModelContext, ) -> anyhow::Result<()> { self.as_remote_mut() @@ -331,7 +331,7 @@ impl Worktree { pub fn handle_open_buffer( &mut self, envelope: TypedEnvelope, - rpc: Arc, + rpc: Arc, cx: &mut ModelContext, ) -> anyhow::Result<()> { let receipt = envelope.receipt(); @@ -357,7 +357,7 @@ impl Worktree { pub fn handle_close_buffer( &mut self, envelope: TypedEnvelope, - _: Arc, + _: Arc, cx: &mut ModelContext, ) -> anyhow::Result<()> { self.as_local_mut() @@ -413,7 +413,7 @@ impl Worktree { pub fn handle_update_buffer( &mut self, envelope: TypedEnvelope, - _: Arc, + _: Arc, cx: &mut ModelContext, ) -> Result<()> { let payload = envelope.payload.clone(); @@ -460,7 +460,7 @@ impl Worktree { pub fn handle_save_buffer( &mut self, envelope: TypedEnvelope, - rpc: Arc, + rpc: Arc, cx: &mut ModelContext, ) -> Result<()> { let sender_id = envelope.original_sender_id()?; @@ -507,7 +507,7 @@ impl Worktree { pub fn handle_buffer_saved( &mut self, envelope: TypedEnvelope, - _: Arc, + _: Arc, cx: &mut ModelContext, ) -> Result<()> { let payload = envelope.payload.clone(); @@ -533,7 +533,7 @@ impl Worktree { pub fn handle_unshare( &mut self, _: TypedEnvelope, - _: Arc, + _: Arc, cx: &mut ModelContext, ) -> Result<()> { cx.emit(Event::Closed); @@ -682,7 +682,7 @@ pub struct LocalWorktree { peers: HashMap, languages: Arc, queued_operations: Vec<(u64, Operation)>, - rpc: Arc, + rpc: Arc, fs: Arc, } @@ -693,7 +693,7 @@ struct WorktreeConfig { impl LocalWorktree { async fn new( - rpc: Arc, + rpc: Arc, path: impl Into>, fs: Arc, languages: Arc, @@ -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, - _subscriptions: Vec, + _subscriptions: Vec, } pub struct RemoteWorktree { remote_id: u64, snapshot: Snapshot, snapshot_rx: watch::Receiver, - rpc: Arc, + client: Arc, updates_tx: postage::mpsc::Sender, replica_id: ReplicaId, open_buffers: HashMap, peers: HashMap, languages: Arc, queued_operations: Vec<(u64, Operation)>, - _subscriptions: Vec, + _subscriptions: Vec, } 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(), diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index 60b877bf38..647ad6794c 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -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, _| { diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 6387d8950b..a1f645e756 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -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" diff --git a/crates/zed/src/channel.rs b/crates/zed/src/channel.rs index 48ecbb9fa2..ac23e15520 100644 --- a/crates/zed/src/channel.rs +++ b/crates/zed/src/channel.rs @@ -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>, channels: HashMap>, - rpc: Arc, + client: Arc, user_store: ModelHandle, _task: Task>, } @@ -40,9 +36,9 @@ pub struct Channel { loaded_all_messages: bool, next_pending_message_id: usize, user_store: ModelHandle, - rpc: Arc, + rpc: Arc, 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, - rpc: Arc, + rpc: Arc, cx: &mut ModelContext, ) -> 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, - rpc: Arc, + rpc: Arc, cx: &mut ModelContext, ) -> 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, - _: Arc, + message: TypedEnvelope, + _: Arc, cx: &mut ModelContext, ) -> 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)); diff --git a/crates/zed/src/chat_panel.rs b/crates/zed/src/chat_panel.rs index dc1e5f0eec..47bdd86e13 100644 --- a/crates/zed/src/chat_panel.rs +++ b/crates/zed/src/chat_panel.rs @@ -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: Arc, channel_list: ModelHandle, active_channel: Option<(ModelHandle, Subscription)>, message_list: ListState, @@ -46,7 +46,7 @@ pub fn init(cx: &mut MutableAppContext) { impl ChatPanel { pub fn new( - rpc: Arc, + rpc: Arc, channel_list: ModelHandle, settings: watch::Receiver, cx: &mut ViewContext, @@ -409,7 +409,10 @@ impl View for ChatPanel { } fn on_focus(&mut self, cx: &mut ViewContext) { - if matches!(*self.rpc.status().borrow(), rpc::Status::Connected { .. }) { + if matches!( + *self.rpc.status().borrow(), + client::Status::Connected { .. } + ) { cx.focus(&self.input_editor); } } diff --git a/crates/zed/src/file_finder.rs b/crates/zed/src/file_finder.rs index 93ca2d963b..2e9e562f6a 100644 --- a/crates/zed/src/file_finder.rs +++ b/crates/zed/src/file_finder.rs @@ -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; diff --git a/crates/zed/src/lib.rs b/crates/zed/src/lib.rs index 914939bf45..25d407791c 100644 --- a/crates/zed/src/lib.rs +++ b/crates/zed/src/lib.rs @@ -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, pub languages: Arc, pub themes: Arc, - pub rpc: Arc, + pub client: Arc, pub user_store: ModelHandle, pub fs: Arc, pub channel_list: ModelHandle, @@ -50,7 +50,7 @@ pub fn init(app_state: &Arc, 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 }) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 6be0427bac..ed87076a70 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -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), }); diff --git a/crates/zed/src/project_panel.rs b/crates/zed/src/project_panel.rs index 7fc3206f22..cbeab41ae5 100644 --- a/crates/zed/src/project_panel.rs +++ b/crates/zed/src/project_panel.rs @@ -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(), ) }); diff --git a/crates/zed/src/test.rs b/crates/zed/src/test.rs index 0fff5c2aaf..c4fae8c1dd 100644 --- a/crates/zed/src/test.rs +++ b/crates/zed/src/test.rs @@ -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 { 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()), }) diff --git a/crates/zed/src/theme_selector.rs b/crates/zed/src/theme_selector.rs index 7df045740e..f10e4c6821 100644 --- a/crates/zed/src/theme_selector.rs +++ b/crates/zed/src/theme_selector.rs @@ -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, diff --git a/crates/zed/src/user.rs b/crates/zed/src/user.rs index 3345a1811c..3058211f63 100644 --- a/crates/zed/src/user.rs +++ b/crates/zed/src/user.rs @@ -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>, current_user: watch::Receiver>>, collaborators: Arc<[Collaborator]>, - rpc: Arc, + rpc: Arc, http: Arc, _maintain_collaborators: Task<()>, _maintain_current_user: Task<()>, @@ -48,11 +48,7 @@ impl Entity for UserStore { } impl UserStore { - pub fn new( - rpc: Arc, - http: Arc, - cx: &mut ModelContext, - ) -> Self { + pub fn new(rpc: Arc, http: Arc, cx: &mut ModelContext) -> Self { let (mut current_user_tx, current_user_rx) = watch::channel(); let (mut update_collaborators_tx, mut update_collaborators_rx) = watch::channel::>(); @@ -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(); } _ => {} diff --git a/crates/zed/src/workspace.rs b/crates/zed/src/workspace.rs index 0ca10a761b..77f07c2fb1 100644 --- a/crates/zed/src/workspace.rs +++ b/crates/zed/src/workspace.rs @@ -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 { pub struct Workspace { pub settings: watch::Receiver, - rpc: Arc, + client: Arc, user_store: ModelHandle, fs: Arc, modal: Option, @@ -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 { 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(),