Rename rpc_client -> client

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-10-04 17:14:21 -07:00
parent 2f0212ee98
commit 94209d2b6d
26 changed files with 148 additions and 155 deletions

View file

@ -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"

View file

@ -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));

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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 })

View file

@ -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),
});

View file

@ -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(),
)
});

View file

@ -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()),
})

View file

@ -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,

View file

@ -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();
}
_ => {}

View file

@ -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(),