diff --git a/Cargo.lock b/Cargo.lock index e18a854fba97971635b7c612a96dd4d3991117ce..173ffeb2605d99b299c97edc1467608b6ce44981 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1028,7 +1028,9 @@ dependencies = [ "anyhow", "async-recursion", "async-tungstenite", + "futures", "gpui", + "image 0.23.14", "lazy_static", "log", "parking_lot", @@ -1036,8 +1038,10 @@ dependencies = [ "rand 0.8.3", "rpc", "smol", + "sum_tree", "surf", "thiserror", + "time 0.3.2", "tiny_http", "util", ] diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 0931de7c312143576374294c04bbafbb719ea86d..e71d7d45109d6b68e2e3761218972b63a89f48e2 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -10,10 +10,13 @@ test-support = [] gpui = { path = "../gpui" } util = { path = "../util" } rpc = { path = "../rpc" } +sum_tree = { path = "../sum_tree" } anyhow = "1.0.38" async-recursion = "0.3" async-tungstenite = { version = "0.14", features = ["async-tls"] } +futures = "0.3" +image = "0.23" lazy_static = "1.4.0" log = "0.4" parking_lot = "0.11.1" @@ -22,4 +25,5 @@ rand = "0.8.3" smol = "1.2.5" surf = "2.2" thiserror = "1.0.29" +time = "0.3" tiny_http = "0.8" diff --git a/crates/zed/src/channel.rs b/crates/client/src/channel.rs similarity index 98% rename from crates/zed/src/channel.rs rename to crates/client/src/channel.rs index ac23e15520f4f962f1dadada0b6aacb256376ffd..90b5bbe425ba35ff3c6bad597b7cf7194c1f3880 100644 --- a/crates/zed/src/channel.rs +++ b/crates/client/src/channel.rs @@ -1,6 +1,9 @@ -use crate::user::{User, UserStore}; +use super::{ + proto, + user::{User, UserStore}, + Client, Status, Subscription, TypedEnvelope, +}; use anyhow::{anyhow, Context, Result}; -use client::{proto, Client, TypedEnvelope}; use gpui::{ AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakModelHandle, }; @@ -38,7 +41,7 @@ pub struct Channel { user_store: ModelHandle, rpc: Arc, rng: StdRng, - _subscription: client::Subscription, + _subscription: Subscription, } #[derive(Clone, Debug)] @@ -91,7 +94,7 @@ impl ChannelList { let mut status = rpc.status(); while let Some((status, this)) = status.recv().await.zip(this.upgrade(&cx)) { match status { - client::Status::Connected { .. } => { + Status::Connected { .. } => { let response = rpc .request(proto::GetChannels {}) .await @@ -115,7 +118,7 @@ impl ChannelList { cx.notify(); }); } - client::Status::SignedOut { .. } => { + Status::SignedOut { .. } => { this.update(&mut cx, |this, cx| { this.available_channels = None; this.channels.clear(); @@ -589,8 +592,7 @@ impl<'a> sum_tree::Dimension<'a, ChannelMessageSummary> for Count { #[cfg(test)] mod tests { use super::*; - use crate::test::FakeHttpClient; - use client::test::FakeServer; + use crate::test::{FakeHttpClient, FakeServer}; use gpui::TestAppContext; use surf::http::Response; diff --git a/crates/zed/src/http.rs b/crates/client/src/http.rs similarity index 100% rename from crates/zed/src/http.rs rename to crates/client/src/http.rs diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index b62697b19593738ac4bbb05c9ff4fd3cb7f563fc..c3eb6807d41d4db47f98311f58551058ba7f61e2 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -1,6 +1,10 @@ #[cfg(any(test, feature = "test-support"))] pub mod test; +pub mod channel; +pub mod http; +pub mod user; + use anyhow::{anyhow, Context, Result}; use async_recursion::async_recursion; use async_tungstenite::tungstenite::{ @@ -26,7 +30,9 @@ use surf::Url; use thiserror::Error; use util::ResultExt; +pub use channel::*; pub use rpc::*; +pub use user::*; lazy_static! { static ref ZED_SERVER_URL: String = diff --git a/crates/client/src/test.rs b/crates/client/src/test.rs index ec4a30465c2cd5d1f58c290895b2352bd957af6c..e471398b53178c9bbac94ebebabf21781278e422 100644 --- a/crates/client/src/test.rs +++ b/crates/client/src/test.rs @@ -1,11 +1,13 @@ -use super::*; -use std::sync::atomic::Ordering::SeqCst; - use super::Client; +use super::*; +use crate::http::{HttpClient, Request, Response, ServerResponse}; +use futures::{future::BoxFuture, Future}; use gpui::TestAppContext; use parking_lot::Mutex; use postage::{mpsc, prelude::Stream}; use rpc::{proto, ConnectionId, Peer, Receipt, TypedEnvelope}; +use std::fmt; +use std::sync::atomic::Ordering::SeqCst; use std::sync::{ atomic::{AtomicBool, AtomicUsize}, Arc, @@ -154,3 +156,33 @@ impl FakeServer { self.connection_id.lock().expect("not connected") } } + +pub struct FakeHttpClient { + handler: + Box BoxFuture<'static, Result>>, +} + +impl FakeHttpClient { + pub fn new(handler: F) -> Arc + where + Fut: 'static + Send + Future>, + F: 'static + Send + Sync + Fn(Request) -> Fut, + { + Arc::new(Self { + handler: Box::new(move |req| Box::pin(handler(req))), + }) + } +} + +impl fmt::Debug for FakeHttpClient { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FakeHttpClient").finish() + } +} + +impl HttpClient for FakeHttpClient { + fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result> { + let future = (self.handler)(req); + Box::pin(async move { future.await.map(Into::into) }) + } +} diff --git a/crates/zed/src/user.rs b/crates/client/src/user.rs similarity index 97% rename from crates/zed/src/user.rs rename to crates/client/src/user.rs index 3058211f633c118bb10d0eebbaacbb36c495bdd2..47ea9ae55c087603137a5c0a573e65b883dff6b4 100644 --- a/crates/zed/src/user.rs +++ b/crates/client/src/user.rs @@ -1,6 +1,8 @@ -use crate::http::{HttpClient, Method, Request, Url}; +use super::{ + http::{HttpClient, Method, Request, Url}, + proto, Client, Status, TypedEnvelope, +}; 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}; @@ -79,7 +81,7 @@ impl UserStore { let mut status = rpc.status(); while let Some(status) = status.recv().await { match status { - client::Status::Connected { .. } => { + 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)) @@ -88,7 +90,7 @@ impl UserStore { current_user_tx.send(user).await.ok(); } } - client::Status::SignedOut => { + Status::SignedOut => { current_user_tx.send(None).await.ok(); } _ => {} diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index 647ad6794c25593c60ceb7eb182587189ba0c939..1261671c85f0c988160bf0f4106f4de33fa3ecfb 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -977,14 +977,14 @@ mod tests { }; use zed::{ buffer::LanguageRegistry, - channel::{Channel, ChannelDetails, ChannelList}, - client::{self, Client, Credentials, EstablishConnectionError}, + client::{ + self, test::FakeHttpClient, Channel, ChannelDetails, ChannelList, Client, Credentials, + EstablishConnectionError, UserStore, + }, editor::{Editor, EditorSettings, Insert}, fs::{FakeFs, Fs as _}, people_panel::JoinWorktree, project::{ProjectPath, Worktree}, - test::FakeHttpClient, - user::UserStore, workspace::Workspace, }; diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index a1f645e756e45513573ffefac734aa877cb4ecae..b024560a0c125cb6c8f5b300709c0d7433532480 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -68,7 +68,7 @@ smol = "1.2.5" surf = "2.2" tempdir = { version = "0.3.7", optional = true } thiserror = "1.0.29" -time = { version = "0.3" } +time = "0.3" tiny_http = "0.8" toml = "0.5" tree-sitter = "0.19.5" diff --git a/crates/zed/src/chat_panel.rs b/crates/zed/src/chat_panel.rs index 47bdd86e139b6f0bbf36c1a5f4d037fe30f1cd58..e81946ed6a11a18faedcf985cb859f9c8ba912b7 100644 --- a/crates/zed/src/chat_panel.rs +++ b/crates/zed/src/chat_panel.rs @@ -1,8 +1,8 @@ -use crate::{ +use crate::{theme, Settings}; +use client::{ channel::{Channel, ChannelEvent, ChannelList, ChannelMessage}, - theme, Settings, + Client, }; -use client::Client; use editor::{Editor, EditorSettings}; use gpui::{ action, diff --git a/crates/zed/src/lib.rs b/crates/zed/src/lib.rs index 25d407791c88eb7cc18e18ea10715d078ae03453..6d5be2f0a6b2d385d1af6ab53708b429aaf63242 100644 --- a/crates/zed/src/lib.rs +++ b/crates/zed/src/lib.rs @@ -1,8 +1,6 @@ pub mod assets; -pub mod channel; pub mod chat_panel; pub mod file_finder; -pub mod http; pub mod language; pub mod menus; pub mod people_panel; @@ -12,12 +10,10 @@ pub mod settings; pub mod test; pub mod theme; pub mod theme_selector; -pub mod user; pub mod workspace; pub use buffer; use buffer::LanguageRegistry; -use channel::ChannelList; pub use client; pub use editor; use gpui::{action, keymap::Binding, ModelHandle}; @@ -41,9 +37,9 @@ pub struct AppState { pub languages: Arc, pub themes: Arc, pub client: Arc, - pub user_store: ModelHandle, + pub user_store: ModelHandle, pub fs: Arc, - pub channel_list: ModelHandle, + pub channel_list: ModelHandle, } pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index ed87076a708c4520636a34314acf9a2d7a2bc0a8..95b53bbde30c7337ea0fb0a6953fb396d552b53c 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -10,11 +10,11 @@ use std::{fs, path::PathBuf, sync::Arc}; use zed::{ self, assets::Assets, - channel::ChannelList, - chat_panel, client, editor, file_finder, + chat_panel, client, + client::{http, ChannelList, UserStore}, + editor, file_finder, fs::RealFs, - http, language, menus, project_panel, settings, theme_selector, - user::UserStore, + language, menus, project_panel, settings, theme_selector, workspace::{self, OpenNew, OpenParams, OpenPaths}, AppState, }; diff --git a/crates/zed/src/people_panel.rs b/crates/zed/src/people_panel.rs index 10d3bdaa0274cd883cf3504014d7ae22f44d2fdd..d59ec5c2b2d85f15cd8e7df78102e4380e9efdc0 100644 --- a/crates/zed/src/people_panel.rs +++ b/crates/zed/src/people_panel.rs @@ -1,8 +1,5 @@ -use crate::{ - theme::Theme, - user::{Collaborator, UserStore}, - Settings, -}; +use crate::{theme::Theme, Settings}; +use client::{Collaborator, UserStore}; use gpui::{ action, elements::*, diff --git a/crates/zed/src/test.rs b/crates/zed/src/test.rs index c4fae8c1ddb7932cda72df957604ae3b00bb0c30..37ac9a869d4da718445dc06e733ef3ccb9df0da7 100644 --- a/crates/zed/src/test.rs +++ b/crates/zed/src/test.rs @@ -1,20 +1,15 @@ use crate::{ assets::Assets, - channel::ChannelList, - http::{HttpClient, Request, Response, ServerResponse}, language, settings::{self, ThemeRegistry}, - user::UserStore, AppState, }; -use anyhow::Result; use buffer::LanguageRegistry; -use client::Client; -use futures::{future::BoxFuture, Future}; +use client::{http::ServerResponse, test::FakeHttpClient, ChannelList, Client, UserStore}; use gpui::MutableAppContext; use parking_lot::Mutex; use project::fs::FakeFs; -use std::{fmt, sync::Arc}; +use std::sync::Arc; #[cfg(test)] #[ctor::ctor] @@ -41,33 +36,3 @@ pub fn test_app_state(cx: &mut MutableAppContext) -> Arc { fs: Arc::new(FakeFs::new()), }) } - -pub struct FakeHttpClient { - handler: - Box BoxFuture<'static, Result>>, -} - -impl FakeHttpClient { - pub fn new(handler: F) -> Arc - where - Fut: 'static + Send + Future>, - F: 'static + Send + Sync + Fn(Request) -> Fut, - { - Arc::new(Self { - handler: Box::new(move |req| Box::pin(handler(req))), - }) - } -} - -impl fmt::Debug for FakeHttpClient { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("FakeHttpClient").finish() - } -} - -impl HttpClient for FakeHttpClient { - fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result> { - let future = (self.handler)(req); - Box::pin(async move { future.await.map(Into::into) }) - } -} diff --git a/crates/zed/src/workspace.rs b/crates/zed/src/workspace.rs index 77f07c2fb17a5493e6b4be0413bdf74f0ef12946..770bc838aed789a7cf59ac0a2110bfe87d7e5e41 100644 --- a/crates/zed/src/workspace.rs +++ b/crates/zed/src/workspace.rs @@ -10,7 +10,6 @@ use crate::{ project::{Project, ProjectPath}, project_panel::ProjectPanel, settings::Settings, - user, workspace::sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus}, AppState, Authenticate, }; @@ -357,7 +356,7 @@ impl Clone for Box { pub struct Workspace { pub settings: watch::Receiver, client: Arc, - user_store: ModelHandle, + user_store: ModelHandle, fs: Arc, modal: Option, center: PaneGroup,