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

46
Cargo.lock generated
View file

@ -1021,6 +1021,27 @@ dependencies = [
"syn", "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]] [[package]]
name = "clock" name = "clock"
version = "0.1.0" version = "0.1.0"
@ -3685,6 +3706,7 @@ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"buffer", "buffer",
"client",
"clock", "clock",
"fsevent", "fsevent",
"futures", "futures",
@ -3698,7 +3720,6 @@ dependencies = [
"postage", "postage",
"rand 0.8.3", "rand 0.8.3",
"rpc", "rpc",
"rpc_client",
"serde 1.0.125", "serde 1.0.125",
"serde_json 1.0.64", "serde_json 1.0.64",
"smol", "smol",
@ -4166,27 +4187,6 @@ dependencies = [
"zstd", "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]] [[package]]
name = "rsa" name = "rsa"
version = "0.4.0" version = "0.4.0"
@ -6052,6 +6052,7 @@ dependencies = [
"async-tungstenite", "async-tungstenite",
"buffer", "buffer",
"cargo-bundle", "cargo-bundle",
"client",
"clock", "clock",
"crossbeam-channel", "crossbeam-channel",
"ctor", "ctor",
@ -6077,7 +6078,6 @@ dependencies = [
"project", "project",
"rand 0.8.3", "rand 0.8.3",
"rpc", "rpc",
"rpc_client",
"rsa", "rsa",
"rust-embed", "rust-embed",
"serde 1.0.125", "serde 1.0.125",

View file

@ -23,6 +23,7 @@ pub use point::*;
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub use random_char_iter::*; pub use random_char_iter::*;
pub use rope::{Chunks, Rope, TextSummary}; pub use rope::{Chunks, Rope, TextSummary};
use rpc::proto;
use seahash::SeaHasher; use seahash::SeaHasher;
pub use selection::*; pub use selection::*;
use similar::{ChangeTag, TextDiff}; use similar::{ChangeTag, TextDiff};
@ -40,10 +41,9 @@ use std::{
sync::Arc, sync::Arc,
time::{Duration, Instant, SystemTime, UNIX_EPOCH}, time::{Duration, Instant, SystemTime, UNIX_EPOCH},
}; };
use sum_tree::{self, Bias, FilterCursor, SumTree}; use sum_tree::{Bias, FilterCursor, SumTree};
pub use syntax_theme::SyntaxTheme; pub use syntax_theme::SyntaxTheme;
use tree_sitter::{InputEdit, Parser, QueryCursor}; use tree_sitter::{InputEdit, Parser, QueryCursor};
use rpc::proto;
pub trait File { pub trait File {
fn worktree_id(&self) -> usize; fn worktree_id(&self) -> usize;

View file

@ -2,7 +2,7 @@ use super::Point;
use arrayvec::ArrayString; use arrayvec::ArrayString;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{cmp, ops::Range, str}; use std::{cmp, ops::Range, str};
use sum_tree::{self, Bias, SumTree}; use sum_tree::{Bias, SumTree};
#[cfg(test)] #[cfg(test)]
const CHUNK_BASE: usize = 6; const CHUNK_BASE: usize = 6;

View file

@ -1,5 +1,5 @@
[package] [package]
name = "rpc_client" name = "client"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2018"

View file

@ -2,7 +2,7 @@ mod fold_map;
mod tab_map; mod tab_map;
mod wrap_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 fold_map::{FoldMap, ToFoldPoint as _};
use gpui::{fonts::FontId, Entity, ModelContext, ModelHandle}; use gpui::{fonts::FontId, Entity, ModelContext, ModelHandle};
use std::ops::Range; use std::ops::Range;

View file

@ -1,8 +1,4 @@
use super::{ use buffer::{Anchor, Buffer, Point, ToOffset, AnchorRangeExt, HighlightId, TextSummary};
buffer::{AnchorRangeExt, TextSummary},
Anchor, Buffer, Point, ToOffset,
};
use buffer::HighlightId;
use gpui::{AppContext, ModelHandle}; use gpui::{AppContext, ModelHandle};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{ use std::{
@ -11,7 +7,7 @@ use std::{
ops::Range, ops::Range,
sync::atomic::{AtomicUsize, Ordering::SeqCst}, sync::atomic::{AtomicUsize, Ordering::SeqCst},
}; };
use sum_tree::{self, Bias, Cursor, FilterCursor, SumTree}; use sum_tree::{Bias, Cursor, FilterCursor, SumTree};
pub trait ToFoldPoint { pub trait ToFoldPoint {
fn to_fold_point(&self, snapshot: &Snapshot, bias: Bias) -> FoldPoint; fn to_fold_point(&self, snapshot: &Snapshot, bias: Bias) -> FoldPoint;

View file

@ -7,7 +7,7 @@ use gpui::{fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, Task};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use smol::future::yield_now; use smol::future::yield_now;
use std::{collections::VecDeque, ops::Range, time::Duration}; use std::{collections::VecDeque, ops::Range, time::Duration};
use sum_tree::{self, Bias, Cursor, SumTree}; use sum_tree::{Bias, Cursor, SumTree};
pub struct WrapMap { pub struct WrapMap {
snapshot: Snapshot, snapshot: Snapshot,

View file

@ -8,7 +8,7 @@ use crate::{
SizeConstraint, SizeConstraint,
}; };
use std::{cell::RefCell, collections::VecDeque, ops::Range, rc::Rc}; use std::{cell::RefCell, collections::VecDeque, ops::Range, rc::Rc};
use sum_tree::{self, Bias, SumTree}; use sum_tree::{Bias, SumTree};
pub struct List { pub struct List {
state: ListState, state: ListState,

View file

@ -4,7 +4,7 @@ use crate::geometry::{
}; };
use etagere::BucketedAtlasAllocator; use etagere::BucketedAtlasAllocator;
use foreign_types::ForeignType; use foreign_types::ForeignType;
use metal::{self, Device, TextureDescriptor}; use metal::{Device, TextureDescriptor};
use objc::{msg_send, sel, sel_impl}; use objc::{msg_send, sel, sel_impl};
pub struct AtlasAllocator { pub struct AtlasAllocator {

View file

@ -12,7 +12,7 @@ clock = { path = "../clock" }
fsevent = { path = "../fsevent" } fsevent = { path = "../fsevent" }
fuzzy = { path = "../fuzzy" } fuzzy = { path = "../fuzzy" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
rpc_client = { path = "../rpc_client" } client = { path = "../client" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
util = { path = "../util" } util = { path = "../util" }
rpc = { path = "../rpc" } rpc = { path = "../rpc" }
@ -32,7 +32,7 @@ smol = "1.2.5"
toml = "0.5" toml = "0.5"
[dev-dependencies] [dev-dependencies]
rpc_client = { path = "../rpc_client", features = ["test-support"] } client = { path = "../client", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] } util = { path = "../util", features = ["test-support"] }
rpc = { path = "../rpc", features = ["test-support"] } rpc = { path = "../rpc", features = ["test-support"] }

View file

@ -4,10 +4,10 @@ mod worktree;
use anyhow::Result; use anyhow::Result;
use buffer::LanguageRegistry; use buffer::LanguageRegistry;
use client::Client;
use futures::Future; use futures::Future;
use fuzzy::{self, PathMatch, PathMatchCandidate, PathMatchCandidateSet}; use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task}; use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
use rpc_client as rpc;
use std::{ use std::{
path::Path, path::Path,
sync::{atomic::AtomicBool, Arc}, sync::{atomic::AtomicBool, Arc},
@ -21,7 +21,7 @@ pub struct Project {
worktrees: Vec<ModelHandle<Worktree>>, worktrees: Vec<ModelHandle<Worktree>>,
active_entry: Option<ProjectEntry>, active_entry: Option<ProjectEntry>,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
rpc: Arc<rpc::Client>, client: Arc<client::Client>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
} }
@ -43,12 +43,12 @@ pub struct ProjectEntry {
} }
impl Project { 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 { Self {
worktrees: Default::default(), worktrees: Default::default(),
active_entry: None, active_entry: None,
languages, languages,
rpc, client: rpc,
fs, fs,
} }
} }
@ -70,7 +70,7 @@ impl Project {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Task<Result<ModelHandle<Worktree>>> { ) -> Task<Result<ModelHandle<Worktree>>> {
let fs = self.fs.clone(); let fs = self.fs.clone();
let rpc = self.rpc.clone(); let rpc = self.client.clone();
let languages = self.languages.clone(); let languages = self.languages.clone();
let path = Arc::from(abs_path); let path = Arc::from(abs_path);
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
@ -87,7 +87,7 @@ impl Project {
remote_id: u64, remote_id: u64,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Task<Result<ModelHandle<Worktree>>> { ) -> Task<Result<ModelHandle<Worktree>>> {
let rpc = self.rpc.clone(); let rpc = self.client.clone();
let languages = self.languages.clone(); let languages = self.languages.clone();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
rpc.authenticate_and_connect(&cx).await?; rpc.authenticate_and_connect(&cx).await?;
@ -133,7 +133,7 @@ impl Project {
} }
pub fn share_worktree(&self, remote_id: u64, cx: &mut ModelContext<Self>) { 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| { cx.spawn(|this, mut cx| {
async move { async move {
rpc.authenticate_and_connect(&cx).await?; rpc.authenticate_and_connect(&cx).await?;
@ -407,7 +407,7 @@ mod tests {
fn build_project(cx: &mut TestAppContext) -> ModelHandle<Project> { fn build_project(cx: &mut TestAppContext) -> ModelHandle<Project> {
let languages = Arc::new(LanguageRegistry::new()); let languages = Arc::new(LanguageRegistry::new());
let fs = Arc::new(RealFs); let fs = Arc::new(RealFs);
let rpc = rpc::Client::new(); let rpc = client::Client::new();
cx.add_model(|_| Project::new(languages, rpc, fs)) cx.add_model(|_| Project::new(languages, rpc, fs))
} }
} }

View file

@ -4,7 +4,8 @@ use super::{
}; };
use ::ignore::gitignore::{Gitignore, GitignoreBuilder}; use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
use anyhow::{anyhow, Result}; 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 clock::ReplicaId;
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
use fuzzy::CharBag; use fuzzy::CharBag;
@ -18,7 +19,6 @@ use postage::{
prelude::{Sink as _, Stream as _}, prelude::{Sink as _, Stream as _},
watch, watch,
}; };
use rpc_client::{self as rpc, proto, PeerId, TypedEnvelope};
use serde::Deserialize; use serde::Deserialize;
use smol::channel::{self, Sender}; use smol::channel::{self, Sender};
use std::{ use std::{
@ -38,7 +38,7 @@ use std::{
time::{Duration, SystemTime}, time::{Duration, SystemTime},
}; };
use sum_tree::Bias; use sum_tree::Bias;
use sum_tree::{self, Edit, SeekTarget, SumTree}; use sum_tree::{Edit, SeekTarget, SumTree};
use util::TryFutureExt; use util::TryFutureExt;
lazy_static! { lazy_static! {
@ -78,7 +78,7 @@ impl Entity for Worktree {
} }
} }
Self::Remote(tree) => { Self::Remote(tree) => {
let rpc = tree.rpc.clone(); let rpc = tree.client.clone();
let worktree_id = tree.remote_id; let worktree_id = tree.remote_id;
cx.spawn(|_| async move { cx.spawn(|_| async move {
if let Err(err) = rpc.send(proto::LeaveWorktree { worktree_id }).await { if let Err(err) = rpc.send(proto::LeaveWorktree { worktree_id }).await {
@ -93,7 +93,7 @@ impl Entity for Worktree {
impl Worktree { impl Worktree {
pub async fn open_local( pub async fn open_local(
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
path: impl Into<Arc<Path>>, path: impl Into<Arc<Path>>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
@ -117,7 +117,7 @@ impl Worktree {
} }
pub async fn open_remote( pub async fn open_remote(
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
id: u64, id: u64,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
@ -128,7 +128,7 @@ impl Worktree {
async fn remote( async fn remote(
join_response: proto::JoinWorktreeResponse, join_response: proto::JoinWorktreeResponse,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
) -> Result<ModelHandle<Self>> { ) -> Result<ModelHandle<Self>> {
@ -232,7 +232,7 @@ impl Worktree {
snapshot, snapshot,
snapshot_rx, snapshot_rx,
updates_tx, updates_tx,
rpc: rpc.clone(), client: rpc.clone(),
open_buffers: Default::default(), open_buffers: Default::default(),
peers: peers peers: peers
.into_iter() .into_iter()
@ -296,7 +296,7 @@ impl Worktree {
pub fn handle_add_peer( pub fn handle_add_peer(
&mut self, &mut self,
envelope: TypedEnvelope<proto::AddPeer>, envelope: TypedEnvelope<proto::AddPeer>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
match self { match self {
@ -308,7 +308,7 @@ impl Worktree {
pub fn handle_remove_peer( pub fn handle_remove_peer(
&mut self, &mut self,
envelope: TypedEnvelope<proto::RemovePeer>, envelope: TypedEnvelope<proto::RemovePeer>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
match self { match self {
@ -320,7 +320,7 @@ impl Worktree {
pub fn handle_update( pub fn handle_update(
&mut self, &mut self,
envelope: TypedEnvelope<proto::UpdateWorktree>, envelope: TypedEnvelope<proto::UpdateWorktree>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.as_remote_mut() self.as_remote_mut()
@ -331,7 +331,7 @@ impl Worktree {
pub fn handle_open_buffer( pub fn handle_open_buffer(
&mut self, &mut self,
envelope: TypedEnvelope<proto::OpenBuffer>, envelope: TypedEnvelope<proto::OpenBuffer>,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let receipt = envelope.receipt(); let receipt = envelope.receipt();
@ -357,7 +357,7 @@ impl Worktree {
pub fn handle_close_buffer( pub fn handle_close_buffer(
&mut self, &mut self,
envelope: TypedEnvelope<proto::CloseBuffer>, envelope: TypedEnvelope<proto::CloseBuffer>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.as_local_mut() self.as_local_mut()
@ -413,7 +413,7 @@ impl Worktree {
pub fn handle_update_buffer( pub fn handle_update_buffer(
&mut self, &mut self,
envelope: TypedEnvelope<proto::UpdateBuffer>, envelope: TypedEnvelope<proto::UpdateBuffer>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
let payload = envelope.payload.clone(); let payload = envelope.payload.clone();
@ -460,7 +460,7 @@ impl Worktree {
pub fn handle_save_buffer( pub fn handle_save_buffer(
&mut self, &mut self,
envelope: TypedEnvelope<proto::SaveBuffer>, envelope: TypedEnvelope<proto::SaveBuffer>,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
let sender_id = envelope.original_sender_id()?; let sender_id = envelope.original_sender_id()?;
@ -507,7 +507,7 @@ impl Worktree {
pub fn handle_buffer_saved( pub fn handle_buffer_saved(
&mut self, &mut self,
envelope: TypedEnvelope<proto::BufferSaved>, envelope: TypedEnvelope<proto::BufferSaved>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
let payload = envelope.payload.clone(); let payload = envelope.payload.clone();
@ -533,7 +533,7 @@ impl Worktree {
pub fn handle_unshare( pub fn handle_unshare(
&mut self, &mut self,
_: TypedEnvelope<proto::UnshareWorktree>, _: TypedEnvelope<proto::UnshareWorktree>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
cx.emit(Event::Closed); cx.emit(Event::Closed);
@ -682,7 +682,7 @@ pub struct LocalWorktree {
peers: HashMap<PeerId, ReplicaId>, peers: HashMap<PeerId, ReplicaId>,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
queued_operations: Vec<(u64, Operation)>, queued_operations: Vec<(u64, Operation)>,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
} }
@ -693,7 +693,7 @@ struct WorktreeConfig {
impl LocalWorktree { impl LocalWorktree {
async fn new( async fn new(
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
path: impl Into<Arc<Path>>, path: impl Into<Arc<Path>>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
@ -753,7 +753,7 @@ impl LocalWorktree {
let mut status = rpc.status(); let mut status = rpc.status();
while let Some(status) = status.recv().await { while let Some(status) = status.recv().await {
if let Some(this) = this.upgrade(&cx) { 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, _| { let collaborator_logins = this.read_with(&cx, |this, _| {
this.as_local().unwrap().config.collaborators.clone() this.as_local().unwrap().config.collaborators.clone()
}); });
@ -1217,21 +1217,21 @@ impl fmt::Debug for LocalWorktree {
struct ShareState { struct ShareState {
snapshots_tx: Sender<Snapshot>, snapshots_tx: Sender<Snapshot>,
_subscriptions: Vec<rpc::Subscription>, _subscriptions: Vec<client::Subscription>,
} }
pub struct RemoteWorktree { pub struct RemoteWorktree {
remote_id: u64, remote_id: u64,
snapshot: Snapshot, snapshot: Snapshot,
snapshot_rx: watch::Receiver<Snapshot>, snapshot_rx: watch::Receiver<Snapshot>,
rpc: Arc<rpc::Client>, client: Arc<Client>,
updates_tx: postage::mpsc::Sender<proto::UpdateWorktree>, updates_tx: postage::mpsc::Sender<proto::UpdateWorktree>,
replica_id: ReplicaId, replica_id: ReplicaId,
open_buffers: HashMap<usize, RemoteBuffer>, open_buffers: HashMap<usize, RemoteBuffer>,
peers: HashMap<PeerId, ReplicaId>, peers: HashMap<PeerId, ReplicaId>,
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
queued_operations: Vec<(u64, Operation)>, queued_operations: Vec<(u64, Operation)>,
_subscriptions: Vec<rpc::Subscription>, _subscriptions: Vec<client::Subscription>,
} }
impl RemoteWorktree { 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 replica_id = self.replica_id;
let remote_worktree_id = self.remote_id; let remote_worktree_id = self.remote_id;
let path = path.to_string_lossy().to_string(); let path = path.to_string_lossy().to_string();
@ -1867,7 +1867,7 @@ impl buffer::File for File {
}) })
} }
Worktree::Remote(worktree) => { Worktree::Remote(worktree) => {
let rpc = worktree.rpc.clone(); let rpc = worktree.client.clone();
let worktree_id = worktree.remote_id; let worktree_id = worktree.remote_id;
cx.foreground().spawn(async move { cx.foreground().spawn(async move {
let response = rpc let response = rpc
@ -1894,7 +1894,7 @@ impl buffer::File for File {
.remote_id .remote_id
.borrow() .borrow()
.map(|id| (worktree.rpc.clone(), id)), .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 { cx.spawn(|worktree, mut cx| async move {
if let Err(error) = rpc if let Err(error) = rpc
@ -1924,7 +1924,7 @@ impl buffer::File for File {
self.worktree.update(cx, |worktree, cx| { self.worktree.update(cx, |worktree, cx| {
if let Worktree::Remote(worktree) = worktree { if let Worktree::Remote(worktree) = worktree {
let worktree_id = worktree.remote_id; let worktree_id = worktree.remote_id;
let rpc = worktree.rpc.clone(); let rpc = worktree.client.clone();
cx.background() cx.background()
.spawn(async move { .spawn(async move {
if let Err(error) = rpc if let Err(error) = rpc
@ -2832,9 +2832,9 @@ mod tests {
use super::*; use super::*;
use crate::fs::FakeFs; use crate::fs::FakeFs;
use anyhow::Result; use anyhow::Result;
use client::test::FakeServer;
use fs::RealFs; use fs::RealFs;
use rand::prelude::*; use rand::prelude::*;
use rpc_client::test::FakeServer;
use serde_json::json; use serde_json::json;
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use std::{ use std::{
@ -2860,7 +2860,7 @@ mod tests {
.await; .await;
let tree = Worktree::open_local( let tree = Worktree::open_local(
rpc::Client::new(), Client::new(),
Arc::from(Path::new("/root")), Arc::from(Path::new("/root")),
Arc::new(fs), Arc::new(fs),
Default::default(), Default::default(),
@ -2892,7 +2892,7 @@ mod tests {
"file1": "the old contents", "file1": "the old contents",
})); }));
let tree = Worktree::open_local( let tree = Worktree::open_local(
rpc::Client::new(), Client::new(),
dir.path(), dir.path(),
Arc::new(RealFs), Arc::new(RealFs),
Default::default(), Default::default(),
@ -2922,7 +2922,7 @@ mod tests {
let file_path = dir.path().join("file1"); let file_path = dir.path().join("file1");
let tree = Worktree::open_local( let tree = Worktree::open_local(
rpc::Client::new(), Client::new(),
file_path.clone(), file_path.clone(),
Arc::new(RealFs), Arc::new(RealFs),
Default::default(), Default::default(),
@ -2965,7 +2965,7 @@ mod tests {
})); }));
let user_id = 5; 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 server = FakeServer::for_client(user_id, &mut client, &cx).await;
let tree = Worktree::open_local( let tree = Worktree::open_local(
client, client,
@ -3022,7 +3022,7 @@ mod tests {
replica_id: 1, replica_id: 1,
peers: Vec::new(), peers: Vec::new(),
}, },
rpc::Client::new(), Client::new(),
Default::default(), Default::default(),
&mut cx.to_async(), &mut cx.to_async(),
) )
@ -3128,7 +3128,7 @@ mod tests {
})); }));
let tree = Worktree::open_local( let tree = Worktree::open_local(
rpc::Client::new(), Client::new(),
dir.path(), dir.path(),
Arc::new(RealFs), Arc::new(RealFs),
Default::default(), Default::default(),
@ -3164,7 +3164,7 @@ mod tests {
#[gpui::test] #[gpui::test]
async fn test_open_and_share_worktree(mut cx: gpui::TestAppContext) { async fn test_open_and_share_worktree(mut cx: gpui::TestAppContext) {
let user_id = 100; 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 server = FakeServer::for_client(user_id, &mut client, &cx).await;
let fs = Arc::new(FakeFs::new()); let fs = Arc::new(FakeFs::new());
@ -3230,7 +3230,7 @@ mod tests {
"file3": "ghi", "file3": "ghi",
})); }));
let tree = Worktree::open_local( let tree = Worktree::open_local(
rpc::Client::new(), Client::new(),
dir.path(), dir.path(),
Arc::new(RealFs), Arc::new(RealFs),
Default::default(), Default::default(),
@ -3363,7 +3363,7 @@ mod tests {
let initial_contents = "aaa\nbbbbb\nc\n"; let initial_contents = "aaa\nbbbbb\nc\n";
let dir = temp_tree(json!({ "the-file": initial_contents })); let dir = temp_tree(json!({ "the-file": initial_contents }));
let tree = Worktree::open_local( let tree = Worktree::open_local(
rpc::Client::new(), Client::new(),
dir.path(), dir.path(),
Arc::new(RealFs), Arc::new(RealFs),
Default::default(), Default::default(),

View file

@ -978,11 +978,11 @@ mod tests {
use zed::{ use zed::{
buffer::LanguageRegistry, buffer::LanguageRegistry,
channel::{Channel, ChannelDetails, ChannelList}, channel::{Channel, ChannelDetails, ChannelList},
client::{self, Client, Credentials, EstablishConnectionError},
editor::{Editor, EditorSettings, Insert}, editor::{Editor, EditorSettings, Insert},
fs::{FakeFs, Fs as _}, fs::{FakeFs, Fs as _},
people_panel::JoinWorktree, people_panel::JoinWorktree,
project::{ProjectPath, Worktree}, project::{ProjectPath, Worktree},
rpc::{self, Client, Credentials, EstablishConnectionError},
test::FakeHttpClient, test::FakeHttpClient,
user::UserStore, user::UserStore,
workspace::Workspace, workspace::Workspace,
@ -1103,7 +1103,7 @@ mod tests {
let (client_a, _) = server.create_client(&mut cx_a, "user_a").await; 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 (client_b, user_store_b) = server.create_client(&mut cx_b, "user_b").await;
let app_state_b = zed::AppState { let app_state_b = zed::AppState {
rpc: client_b, client: client_b,
user_store: user_store_b, user_store: user_store_b,
..Arc::try_unwrap(cx_b.update(zed::test::test_app_state)) ..Arc::try_unwrap(cx_b.update(zed::test::test_app_state))
.ok() .ok()
@ -1889,7 +1889,7 @@ mod tests {
server.disconnect_client(current_user_id(&user_store_b, &cx_b)); server.disconnect_client(current_user_id(&user_store_b, &cx_b));
while !matches!( while !matches!(
status_b.recv().await, status_b.recv().await,
Some(rpc::Status::ReconnectionError { .. }) Some(client::Status::ReconnectionError { .. })
) {} ) {}
channels_b.read_with(&cx_b, |channels, _| { channels_b.read_with(&cx_b, |channels, _| {

View file

@ -16,15 +16,16 @@ path = "src/main.rs"
[features] [features]
test-support = [ test-support = [
"buffer/test-support", "buffer/test-support",
"client/test-support",
"gpui/test-support", "gpui/test-support",
"project/test-support", "project/test-support",
"rpc/test-support", "rpc/test-support",
"rpc_client/test-support",
"tempdir", "tempdir",
] ]
[dependencies] [dependencies]
buffer = { path = "../buffer" } buffer = { path = "../buffer" }
client = { path = "../client" }
clock = { path = "../clock" } clock = { path = "../clock" }
fsevent = { path = "../fsevent" } fsevent = { path = "../fsevent" }
fuzzy = { path = "../fuzzy" } fuzzy = { path = "../fuzzy" }
@ -32,7 +33,6 @@ editor = { path = "../editor" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
project = { path = "../project" } project = { path = "../project" }
rpc = { path = "../rpc" } rpc = { path = "../rpc" }
rpc_client = { path = "../rpc_client" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
util = { path = "../util" } util = { path = "../util" }
@ -81,7 +81,7 @@ editor = { path = "../editor", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }
project = { path = "../project", features = ["test-support"] } project = { path = "../project", features = ["test-support"] }
rpc = { path = "../rpc", 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"] } util = { path = "../util", features = ["test-support"] }
cargo-bundle = "0.5.0" cargo-bundle = "0.5.0"

View file

@ -1,29 +1,25 @@
use crate::user::{User, UserStore}; use crate::user::{User, UserStore};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use client::{proto, Client, TypedEnvelope};
use gpui::{ use gpui::{
AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakModelHandle, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakModelHandle,
}; };
use postage::prelude::Stream; use postage::prelude::Stream;
use rand::prelude::*; use rand::prelude::*;
use rpc_client::{
self as rpc,
proto::{self, ChannelMessageSent},
TypedEnvelope,
};
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
mem, mem,
ops::Range, ops::Range,
sync::Arc, sync::Arc,
}; };
use sum_tree::{self, Bias, SumTree}; use sum_tree::{Bias, SumTree};
use time::OffsetDateTime; use time::OffsetDateTime;
use util::{post_inc, TryFutureExt}; use util::{post_inc, TryFutureExt};
pub struct ChannelList { pub struct ChannelList {
available_channels: Option<Vec<ChannelDetails>>, available_channels: Option<Vec<ChannelDetails>>,
channels: HashMap<u64, WeakModelHandle<Channel>>, channels: HashMap<u64, WeakModelHandle<Channel>>,
rpc: Arc<rpc::Client>, client: Arc<Client>,
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
_task: Task<Option<()>>, _task: Task<Option<()>>,
} }
@ -40,9 +36,9 @@ pub struct Channel {
loaded_all_messages: bool, loaded_all_messages: bool,
next_pending_message_id: usize, next_pending_message_id: usize,
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
rng: StdRng, rng: StdRng,
_subscription: rpc::Subscription, _subscription: client::Subscription,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -86,7 +82,7 @@ impl Entity for ChannelList {
impl ChannelList { impl ChannelList {
pub fn new( pub fn new(
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Self { ) -> Self {
let _task = cx.spawn_weak(|this, mut cx| { let _task = cx.spawn_weak(|this, mut cx| {
@ -95,7 +91,7 @@ impl ChannelList {
let mut status = rpc.status(); let mut status = rpc.status();
while let Some((status, this)) = status.recv().await.zip(this.upgrade(&cx)) { while let Some((status, this)) = status.recv().await.zip(this.upgrade(&cx)) {
match status { match status {
rpc::Status::Connected { .. } => { client::Status::Connected { .. } => {
let response = rpc let response = rpc
.request(proto::GetChannels {}) .request(proto::GetChannels {})
.await .await
@ -119,7 +115,7 @@ impl ChannelList {
cx.notify(); cx.notify();
}); });
} }
rpc::Status::SignedOut { .. } => { client::Status::SignedOut { .. } => {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.available_channels = None; this.available_channels = None;
this.channels.clear(); this.channels.clear();
@ -138,7 +134,7 @@ impl ChannelList {
available_channels: None, available_channels: None,
channels: Default::default(), channels: Default::default(),
user_store, user_store,
rpc, client: rpc,
_task, _task,
} }
} }
@ -158,8 +154,9 @@ impl ChannelList {
let channels = self.available_channels.as_ref()?; let channels = self.available_channels.as_ref()?;
let details = channels.iter().find(|details| details.id == id)?.clone(); let details = channels.iter().find(|details| details.id == id)?.clone();
let channel = let channel = cx.add_model(|cx| {
cx.add_model(|cx| Channel::new(details, self.user_store.clone(), self.rpc.clone(), cx)); Channel::new(details, self.user_store.clone(), self.client.clone(), cx)
});
self.channels.insert(id, channel.downgrade()); self.channels.insert(id, channel.downgrade());
Some(channel) Some(channel)
} }
@ -185,7 +182,7 @@ impl Channel {
pub fn new( pub fn new(
details: ChannelDetails, details: ChannelDetails,
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Self { ) -> Self {
let _subscription = rpc.subscribe_to_entity(details.id, cx, Self::handle_message_sent); let _subscription = rpc.subscribe_to_entity(details.id, cx, Self::handle_message_sent);
@ -404,8 +401,8 @@ impl Channel {
fn handle_message_sent( fn handle_message_sent(
&mut self, &mut self,
message: TypedEnvelope<ChannelMessageSent>, message: TypedEnvelope<proto::ChannelMessageSent>,
_: Arc<rpc::Client>, _: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
let user_store = self.user_store.clone(); let user_store = self.user_store.clone();
@ -593,14 +590,14 @@ impl<'a> sum_tree::Dimension<'a, ChannelMessageSummary> for Count {
mod tests { mod tests {
use super::*; use super::*;
use crate::test::FakeHttpClient; use crate::test::FakeHttpClient;
use client::test::FakeServer;
use gpui::TestAppContext; use gpui::TestAppContext;
use rpc_client::test::FakeServer;
use surf::http::Response; use surf::http::Response;
#[gpui::test] #[gpui::test]
async fn test_channel_messages(mut cx: TestAppContext) { async fn test_channel_messages(mut cx: TestAppContext) {
let user_id = 5; 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 http_client = FakeHttpClient::new(|_| async move { Ok(Response::new(404)) });
let server = FakeServer::for_client(user_id, &mut client, &cx).await; 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)); 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}, channel::{Channel, ChannelEvent, ChannelList, ChannelMessage},
theme, Settings, theme, Settings,
}; };
use client::Client;
use editor::{Editor, EditorSettings}; use editor::{Editor, EditorSettings};
use gpui::{ use gpui::{
action, action,
@ -13,7 +14,6 @@ use gpui::{
ViewContext, ViewHandle, ViewContext, ViewHandle,
}; };
use postage::{prelude::Stream, watch}; use postage::{prelude::Stream, watch};
use rpc_client as rpc;
use std::sync::Arc; use std::sync::Arc;
use time::{OffsetDateTime, UtcOffset}; use time::{OffsetDateTime, UtcOffset};
use util::{ResultExt, TryFutureExt}; use util::{ResultExt, TryFutureExt};
@ -21,7 +21,7 @@ use util::{ResultExt, TryFutureExt};
const MESSAGE_LOADING_THRESHOLD: usize = 50; const MESSAGE_LOADING_THRESHOLD: usize = 50;
pub struct ChatPanel { pub struct ChatPanel {
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
channel_list: ModelHandle<ChannelList>, channel_list: ModelHandle<ChannelList>,
active_channel: Option<(ModelHandle<Channel>, Subscription)>, active_channel: Option<(ModelHandle<Channel>, Subscription)>,
message_list: ListState, message_list: ListState,
@ -46,7 +46,7 @@ pub fn init(cx: &mut MutableAppContext) {
impl ChatPanel { impl ChatPanel {
pub fn new( pub fn new(
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
channel_list: ModelHandle<ChannelList>, channel_list: ModelHandle<ChannelList>,
settings: watch::Receiver<Settings>, settings: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
@ -409,7 +409,10 @@ impl View for ChatPanel {
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { 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); cx.focus(&self.input_editor);
} }
} }

View file

@ -1,5 +1,5 @@
use crate::{settings::Settings, workspace::Workspace}; use crate::{settings::Settings, workspace::Workspace};
use editor::{self, Editor, EditorSettings}; use editor::{Editor, EditorSettings};
use fuzzy::PathMatch; use fuzzy::PathMatch;
use gpui::{ use gpui::{
action, action,
@ -423,7 +423,7 @@ impl FileFinder {
mod tests { mod tests {
use super::*; use super::*;
use crate::{test::test_app_state, workspace::Workspace}; use crate::{test::test_app_state, workspace::Workspace};
use editor::{self, Insert}; use editor::Insert;
use project::fs::FakeFs; use project::fs::FakeFs;
use serde_json::json; use serde_json::json;
use std::path::PathBuf; use std::path::PathBuf;

View file

@ -18,12 +18,12 @@ pub mod workspace;
pub use buffer; pub use buffer;
use buffer::LanguageRegistry; use buffer::LanguageRegistry;
use channel::ChannelList; use channel::ChannelList;
pub use client;
pub use editor; pub use editor;
use gpui::{action, keymap::Binding, ModelHandle}; use gpui::{action, keymap::Binding, ModelHandle};
use parking_lot::Mutex; use parking_lot::Mutex;
use postage::watch; use postage::watch;
pub use project::{self, fs}; pub use project::{self, fs};
pub use rpc_client as rpc;
pub use settings::Settings; pub use settings::Settings;
use std::sync::Arc; use std::sync::Arc;
use util::TryFutureExt; use util::TryFutureExt;
@ -40,7 +40,7 @@ pub struct AppState {
pub settings: watch::Receiver<Settings>, pub settings: watch::Receiver<Settings>,
pub languages: Arc<LanguageRegistry>, pub languages: Arc<LanguageRegistry>,
pub themes: Arc<settings::ThemeRegistry>, pub themes: Arc<settings::ThemeRegistry>,
pub rpc: Arc<rpc::Client>, pub client: Arc<client::Client>,
pub user_store: ModelHandle<user::UserStore>, pub user_store: ModelHandle<user::UserStore>,
pub fs: Arc<dyn fs::Fs>, pub fs: Arc<dyn fs::Fs>,
pub channel_list: ModelHandle<ChannelList>, 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(quit);
cx.add_global_action({ cx.add_global_action({
let rpc = app_state.rpc.clone(); let rpc = app_state.client.clone();
move |_: &Authenticate, cx| { move |_: &Authenticate, cx| {
let rpc = rpc.clone(); let rpc = rpc.clone();
cx.spawn(|cx| async move { rpc.authenticate_and_connect(&cx).log_err().await }) cx.spawn(|cx| async move { rpc.authenticate_and_connect(&cx).log_err().await })

View file

@ -11,9 +11,9 @@ use zed::{
self, self,
assets::Assets, assets::Assets,
channel::ChannelList, channel::ChannelList,
chat_panel, editor, file_finder, chat_panel, client, editor, file_finder,
fs::RealFs, fs::RealFs,
http, language, menus, project_panel, rpc, settings, theme_selector, http, language, menus, project_panel, settings, theme_selector,
user::UserStore, user::UserStore,
workspace::{self, OpenNew, OpenParams, OpenPaths}, workspace::{self, OpenNew, OpenParams, OpenPaths},
AppState, AppState,
@ -36,16 +36,17 @@ fn main() {
languages.set_theme(&settings.borrow().theme.editor.syntax); languages.set_theme(&settings.borrow().theme.editor.syntax);
app.run(move |cx| { app.run(move |cx| {
let rpc = rpc::Client::new(); let client = client::Client::new();
let http = http::client(); 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 { let app_state = Arc::new(AppState {
languages: languages.clone(), languages: languages.clone(),
settings_tx: Arc::new(Mutex::new(settings_tx)), settings_tx: Arc::new(Mutex::new(settings_tx)),
settings, settings,
themes, themes,
channel_list: cx.add_model(|cx| ChannelList::new(user_store.clone(), rpc.clone(), cx)), channel_list: cx
rpc, .add_model(|cx| ChannelList::new(user_store.clone(), client.clone(), cx)),
client,
user_store, user_store,
fs: Arc::new(RealFs), fs: Arc::new(RealFs),
}); });

View file

@ -626,7 +626,7 @@ mod tests {
let project = cx.add_model(|_| { let project = cx.add_model(|_| {
Project::new( Project::new(
app_state.languages.clone(), app_state.languages.clone(),
app_state.rpc.clone(), app_state.client.clone(),
app_state.fs.clone(), app_state.fs.clone(),
) )
}); });

View file

@ -9,11 +9,11 @@ use crate::{
}; };
use anyhow::Result; use anyhow::Result;
use buffer::LanguageRegistry; use buffer::LanguageRegistry;
use client::Client;
use futures::{future::BoxFuture, Future}; use futures::{future::BoxFuture, Future};
use gpui::MutableAppContext; use gpui::MutableAppContext;
use parking_lot::Mutex; use parking_lot::Mutex;
use project::fs::FakeFs; use project::fs::FakeFs;
use rpc_client as rpc;
use std::{fmt, sync::Arc}; use std::{fmt, sync::Arc};
#[cfg(test)] #[cfg(test)]
@ -27,16 +27,16 @@ pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
let mut languages = LanguageRegistry::new(); let mut languages = LanguageRegistry::new();
languages.add(Arc::new(language::rust())); languages.add(Arc::new(language::rust()));
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone()); 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 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 { Arc::new(AppState {
settings_tx: Arc::new(Mutex::new(settings_tx)), settings_tx: Arc::new(Mutex::new(settings_tx)),
settings, settings,
themes, themes,
languages: Arc::new(languages), languages: Arc::new(languages),
channel_list: cx.add_model(|cx| ChannelList::new(user_store.clone(), rpc.clone(), cx)), channel_list: cx.add_model(|cx| ChannelList::new(user_store.clone(), client.clone(), cx)),
rpc, client,
user_store, user_store,
fs: Arc::new(FakeFs::new()), fs: Arc::new(FakeFs::new()),
}) })

View file

@ -1,5 +1,5 @@
use crate::{settings::ThemeRegistry, workspace::Workspace, AppState, Settings}; use crate::{settings::ThemeRegistry, workspace::Workspace, AppState, Settings};
use editor::{self, Editor, EditorSettings}; use editor::{Editor, EditorSettings};
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
action, action,

View file

@ -1,9 +1,9 @@
use crate::http::{HttpClient, Method, Request, Url}; use crate::http::{HttpClient, Method, Request, Url};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use client::{proto, Client, TypedEnvelope};
use futures::future; use futures::future;
use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task}; use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task};
use postage::{prelude::Stream, sink::Sink, watch}; use postage::{prelude::Stream, sink::Sink, watch};
use rpc_client::{self as rpc, proto, TypedEnvelope};
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
sync::Arc, sync::Arc,
@ -35,7 +35,7 @@ pub struct UserStore {
users: HashMap<u64, Arc<User>>, users: HashMap<u64, Arc<User>>,
current_user: watch::Receiver<Option<Arc<User>>>, current_user: watch::Receiver<Option<Arc<User>>>,
collaborators: Arc<[Collaborator]>, collaborators: Arc<[Collaborator]>,
rpc: Arc<rpc::Client>, rpc: Arc<Client>,
http: Arc<dyn HttpClient>, http: Arc<dyn HttpClient>,
_maintain_collaborators: Task<()>, _maintain_collaborators: Task<()>,
_maintain_current_user: Task<()>, _maintain_current_user: Task<()>,
@ -48,11 +48,7 @@ impl Entity for UserStore {
} }
impl UserStore { impl UserStore {
pub fn new( pub fn new(rpc: Arc<Client>, http: Arc<dyn HttpClient>, cx: &mut ModelContext<Self>) -> Self {
rpc: Arc<rpc::Client>,
http: Arc<dyn HttpClient>,
cx: &mut ModelContext<Self>,
) -> Self {
let (mut current_user_tx, current_user_rx) = watch::channel(); let (mut current_user_tx, current_user_rx) = watch::channel();
let (mut update_collaborators_tx, mut update_collaborators_rx) = let (mut update_collaborators_tx, mut update_collaborators_rx) =
watch::channel::<Option<proto::UpdateCollaborators>>(); watch::channel::<Option<proto::UpdateCollaborators>>();
@ -83,7 +79,7 @@ impl UserStore {
let mut status = rpc.status(); let mut status = rpc.status();
while let Some(status) = status.recv().await { while let Some(status) = status.recv().await {
match status { match status {
rpc::Status::Connected { .. } => { client::Status::Connected { .. } => {
if let Some((this, user_id)) = this.upgrade(&cx).zip(rpc.user_id()) { if let Some((this, user_id)) = this.upgrade(&cx).zip(rpc.user_id()) {
let user = this let user = this
.update(&mut cx, |this, cx| this.fetch_user(user_id, cx)) .update(&mut cx, |this, cx| this.fetch_user(user_id, cx))
@ -92,7 +88,7 @@ impl UserStore {
current_user_tx.send(user).await.ok(); current_user_tx.send(user).await.ok();
} }
} }
rpc::Status::SignedOut => { client::Status::SignedOut => {
current_user_tx.send(None).await.ok(); current_user_tx.send(None).await.ok();
} }
_ => {} _ => {}

View file

@ -9,7 +9,6 @@ use crate::{
people_panel::{JoinWorktree, LeaveWorktree, PeoplePanel, ShareWorktree, UnshareWorktree}, people_panel::{JoinWorktree, LeaveWorktree, PeoplePanel, ShareWorktree, UnshareWorktree},
project::{Project, ProjectPath}, project::{Project, ProjectPath},
project_panel::ProjectPanel, project_panel::ProjectPanel,
rpc,
settings::Settings, settings::Settings,
user, user,
workspace::sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus}, workspace::sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus},
@ -17,6 +16,7 @@ use crate::{
}; };
use anyhow::Result; use anyhow::Result;
use buffer::Buffer; use buffer::Buffer;
use client::Client;
use gpui::{ use gpui::{
action, action,
elements::*, elements::*,
@ -356,7 +356,7 @@ impl Clone for Box<dyn ItemHandle> {
pub struct Workspace { pub struct Workspace {
pub settings: watch::Receiver<Settings>, pub settings: watch::Receiver<Settings>,
rpc: Arc<rpc::Client>, client: Arc<Client>,
user_store: ModelHandle<user::UserStore>, user_store: ModelHandle<user::UserStore>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
modal: Option<AnyViewHandle>, modal: Option<AnyViewHandle>,
@ -379,7 +379,7 @@ impl Workspace {
let project = cx.add_model(|_| { let project = cx.add_model(|_| {
Project::new( Project::new(
app_state.languages.clone(), app_state.languages.clone(),
app_state.rpc.clone(), app_state.client.clone(),
app_state.fs.clone(), app_state.fs.clone(),
) )
}); });
@ -417,7 +417,7 @@ impl Workspace {
"icons/comment-16.svg", "icons/comment-16.svg",
cx.add_view(|cx| { cx.add_view(|cx| {
ChatPanel::new( ChatPanel::new(
app_state.rpc.clone(), app_state.client.clone(),
app_state.channel_list.clone(), app_state.channel_list.clone(),
app_state.settings.clone(), app_state.settings.clone(),
cx, cx,
@ -427,7 +427,7 @@ impl Workspace {
); );
let mut current_user = app_state.user_store.read(cx).watch_current_user().clone(); 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 { let _observe_current_user = cx.spawn_weak(|this, mut cx| async move {
current_user.recv().await; current_user.recv().await;
connection_status.recv().await; connection_status.recv().await;
@ -449,7 +449,7 @@ impl Workspace {
panes: vec![pane.clone()], panes: vec![pane.clone()],
active_pane: pane.clone(), active_pane: pane.clone(),
settings: app_state.settings.clone(), settings: app_state.settings.clone(),
rpc: app_state.rpc.clone(), client: app_state.client.clone(),
user_store: app_state.user_store.clone(), user_store: app_state.user_store.clone(),
fs: app_state.fs.clone(), fs: app_state.fs.clone(),
left_sidebar, left_sidebar,
@ -981,12 +981,12 @@ impl Workspace {
fn render_connection_status(&self) -> Option<ElementBox> { fn render_connection_status(&self) -> Option<ElementBox> {
let theme = &self.settings.borrow().theme; let theme = &self.settings.borrow().theme;
match &*self.rpc.status().borrow() { match &*self.client.status().borrow() {
rpc::Status::ConnectionError client::Status::ConnectionError
| rpc::Status::ConnectionLost | client::Status::ConnectionLost
| rpc::Status::Reauthenticating | client::Status::Reauthenticating
| rpc::Status::Reconnecting { .. } | client::Status::Reconnecting { .. }
| rpc::Status::ReconnectionError { .. } => Some( | client::Status::ReconnectionError { .. } => Some(
Container::new( Container::new(
Align::new( Align::new(
ConstrainedBox::new( ConstrainedBox::new(
@ -1002,7 +1002,7 @@ impl Workspace {
.with_style(theme.workspace.titlebar.offline_icon.container) .with_style(theme.workspace.titlebar.offline_icon.container)
.boxed(), .boxed(),
), ),
rpc::Status::UpgradeRequired => Some( client::Status::UpgradeRequired => Some(
Label::new( Label::new(
"Please update Zed to collaborate".to_string(), "Please update Zed to collaborate".to_string(),
theme.workspace.titlebar.outdated_warning.text.clone(), theme.workspace.titlebar.outdated_warning.text.clone(),