Merge pull request #260 from zed-industries/show-collaborators
Show collaborators for the active worktree in the titlebar
This commit is contained in:
commit
e0998dbfda
21 changed files with 855 additions and 482 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -1109,6 +1109,17 @@ version = "0.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "contacts_panel"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"client",
|
||||||
|
"gpui",
|
||||||
|
"postage",
|
||||||
|
"theme",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cookie"
|
name = "cookie"
|
||||||
version = "0.14.4"
|
version = "0.14.4"
|
||||||
|
@ -3197,17 +3208,6 @@ dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "people_panel"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"client",
|
|
||||||
"gpui",
|
|
||||||
"postage",
|
|
||||||
"theme",
|
|
||||||
"workspace",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
|
@ -5673,6 +5673,7 @@ dependencies = [
|
||||||
"chat_panel",
|
"chat_panel",
|
||||||
"client",
|
"client",
|
||||||
"clock",
|
"clock",
|
||||||
|
"contacts_panel",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"ctor",
|
"ctor",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
@ -5697,7 +5698,6 @@ dependencies = [
|
||||||
"lsp",
|
"lsp",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"people_panel",
|
|
||||||
"postage",
|
"postage",
|
||||||
"project",
|
"project",
|
||||||
"project_panel",
|
"project_panel",
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::Client;
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::http::{HttpClient, Request, Response, ServerResponse};
|
use crate::http::{HttpClient, Request, Response, ServerResponse};
|
||||||
use futures::{future::BoxFuture, Future};
|
use futures::{future::BoxFuture, Future};
|
||||||
use gpui::TestAppContext;
|
use gpui::{ModelHandle, TestAppContext};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use postage::{mpsc, prelude::Stream};
|
use postage::{mpsc, prelude::Stream};
|
||||||
use rpc::{proto, ConnectionId, Peer, Receipt, TypedEnvelope};
|
use rpc::{proto, ConnectionId, Peer, Receipt, TypedEnvelope};
|
||||||
|
@ -155,6 +155,24 @@ impl FakeServer {
|
||||||
fn connection_id(&self) -> ConnectionId {
|
fn connection_id(&self) -> ConnectionId {
|
||||||
self.connection_id.lock().expect("not connected")
|
self.connection_id.lock().expect("not connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn build_user_store(
|
||||||
|
&self,
|
||||||
|
client: Arc<Client>,
|
||||||
|
cx: &mut TestAppContext,
|
||||||
|
) -> ModelHandle<UserStore> {
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client, http_client, cx));
|
||||||
|
assert_eq!(
|
||||||
|
self.receive::<proto::GetUsers>()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.payload
|
||||||
|
.user_ids,
|
||||||
|
&[self.user_id]
|
||||||
|
);
|
||||||
|
user_store
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FakeHttpClient {
|
pub struct FakeHttpClient {
|
||||||
|
@ -172,6 +190,10 @@ impl FakeHttpClient {
|
||||||
handler: Box::new(move |req| Box::pin(handler(req))),
|
handler: Box::new(move |req| Box::pin(handler(req))),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_404_response() -> Arc<dyn HttpClient> {
|
||||||
|
Self::new(|_| async move { Ok(ServerResponse::new(404)) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for FakeHttpClient {
|
impl fmt::Debug for FakeHttpClient {
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct User {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Collaborator {
|
pub struct Contact {
|
||||||
pub user: Arc<User>,
|
pub user: Arc<User>,
|
||||||
pub worktrees: Vec<WorktreeMetadata>,
|
pub worktrees: Vec<WorktreeMetadata>,
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,10 @@ pub struct WorktreeMetadata {
|
||||||
pub struct UserStore {
|
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]>,
|
contacts: Arc<[Contact]>,
|
||||||
rpc: Arc<Client>,
|
client: Arc<Client>,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
_maintain_collaborators: Task<()>,
|
_maintain_contacts: Task<()>,
|
||||||
_maintain_current_user: Task<()>,
|
_maintain_current_user: Task<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,39 +50,43 @@ impl Entity for UserStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserStore {
|
impl UserStore {
|
||||||
pub fn new(rpc: Arc<Client>, http: Arc<dyn HttpClient>, cx: &mut ModelContext<Self>) -> Self {
|
pub fn new(
|
||||||
|
client: Arc<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_contacts_tx, mut update_contacts_rx) =
|
||||||
watch::channel::<Option<proto::UpdateCollaborators>>();
|
watch::channel::<Option<proto::UpdateContacts>>();
|
||||||
let update_collaborators_subscription = rpc.subscribe(
|
let update_contacts_subscription = client.subscribe(
|
||||||
cx,
|
cx,
|
||||||
move |_: &mut Self, msg: TypedEnvelope<proto::UpdateCollaborators>, _, _| {
|
move |_: &mut Self, msg: TypedEnvelope<proto::UpdateContacts>, _, _| {
|
||||||
let _ = update_collaborators_tx.blocking_send(Some(msg.payload));
|
let _ = update_contacts_tx.blocking_send(Some(msg.payload));
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Self {
|
Self {
|
||||||
users: Default::default(),
|
users: Default::default(),
|
||||||
current_user: current_user_rx,
|
current_user: current_user_rx,
|
||||||
collaborators: Arc::from([]),
|
contacts: Arc::from([]),
|
||||||
rpc: rpc.clone(),
|
client: client.clone(),
|
||||||
http,
|
http,
|
||||||
_maintain_collaborators: cx.spawn_weak(|this, mut cx| async move {
|
_maintain_contacts: cx.spawn_weak(|this, mut cx| async move {
|
||||||
let _subscription = update_collaborators_subscription;
|
let _subscription = update_contacts_subscription;
|
||||||
while let Some(message) = update_collaborators_rx.recv().await {
|
while let Some(message) = update_contacts_rx.recv().await {
|
||||||
if let Some((message, this)) = message.zip(this.upgrade(&cx)) {
|
if let Some((message, this)) = message.zip(this.upgrade(&cx)) {
|
||||||
this.update(&mut cx, |this, cx| this.update_collaborators(message, cx))
|
this.update(&mut cx, |this, cx| this.update_contacts(message, cx))
|
||||||
.log_err()
|
.log_err()
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
_maintain_current_user: cx.spawn_weak(|this, mut cx| async move {
|
_maintain_current_user: cx.spawn_weak(|this, mut cx| async move {
|
||||||
let mut status = rpc.status();
|
let mut status = client.status();
|
||||||
while let Some(status) = status.recv().await {
|
while let Some(status) = status.recv().await {
|
||||||
match status {
|
match status {
|
||||||
Status::Connected { .. } => {
|
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(client.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))
|
||||||
.log_err()
|
.log_err()
|
||||||
|
@ -100,35 +104,29 @@ impl UserStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_collaborators(
|
fn update_contacts(
|
||||||
&mut self,
|
&mut self,
|
||||||
message: proto::UpdateCollaborators,
|
message: proto::UpdateContacts,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
let mut user_ids = HashSet::new();
|
let mut user_ids = HashSet::new();
|
||||||
for collaborator in &message.collaborators {
|
for contact in &message.contacts {
|
||||||
user_ids.insert(collaborator.user_id);
|
user_ids.insert(contact.user_id);
|
||||||
user_ids.extend(
|
user_ids.extend(contact.worktrees.iter().flat_map(|w| &w.guests).copied());
|
||||||
collaborator
|
|
||||||
.worktrees
|
|
||||||
.iter()
|
|
||||||
.flat_map(|w| &w.guests)
|
|
||||||
.copied(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let load_users = self.load_users(user_ids.into_iter().collect(), cx);
|
let load_users = self.load_users(user_ids.into_iter().collect(), cx);
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
load_users.await?;
|
load_users.await?;
|
||||||
|
|
||||||
let mut collaborators = Vec::new();
|
let mut contacts = Vec::new();
|
||||||
for collaborator in message.collaborators {
|
for contact in message.contacts {
|
||||||
collaborators.push(Collaborator::from_proto(collaborator, &this, &mut cx).await?);
|
contacts.push(Contact::from_proto(contact, &this, &mut cx).await?);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
collaborators.sort_by(|a, b| a.user.github_login.cmp(&b.user.github_login));
|
contacts.sort_by(|a, b| a.user.github_login.cmp(&b.user.github_login));
|
||||||
this.collaborators = collaborators.into();
|
this.contacts = contacts.into();
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -136,8 +134,8 @@ impl UserStore {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collaborators(&self) -> &Arc<[Collaborator]> {
|
pub fn contacts(&self) -> &Arc<[Contact]> {
|
||||||
&self.collaborators
|
&self.contacts
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_users(
|
pub fn load_users(
|
||||||
|
@ -145,7 +143,7 @@ impl UserStore {
|
||||||
mut user_ids: Vec<u64>,
|
mut user_ids: Vec<u64>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
let rpc = self.rpc.clone();
|
let rpc = self.client.clone();
|
||||||
let http = self.http.clone();
|
let http = self.http.clone();
|
||||||
user_ids.retain(|id| !self.users.contains_key(id));
|
user_ids.retain(|id| !self.users.contains_key(id));
|
||||||
cx.spawn_weak(|this, mut cx| async move {
|
cx.spawn_weak(|this, mut cx| async move {
|
||||||
|
@ -212,19 +210,19 @@ impl User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collaborator {
|
impl Contact {
|
||||||
async fn from_proto(
|
async fn from_proto(
|
||||||
collaborator: proto::Collaborator,
|
contact: proto::Contact,
|
||||||
user_store: &ModelHandle<UserStore>,
|
user_store: &ModelHandle<UserStore>,
|
||||||
cx: &mut AsyncAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let user = user_store
|
let user = user_store
|
||||||
.update(cx, |user_store, cx| {
|
.update(cx, |user_store, cx| {
|
||||||
user_store.fetch_user(collaborator.user_id, cx)
|
user_store.fetch_user(contact.user_id, cx)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
let mut worktrees = Vec::new();
|
let mut worktrees = Vec::new();
|
||||||
for worktree in collaborator.worktrees {
|
for worktree in contact.worktrees {
|
||||||
let mut guests = Vec::new();
|
let mut guests = Vec::new();
|
||||||
for participant_id in worktree.guests {
|
for participant_id in worktree.guests {
|
||||||
guests.push(
|
guests.push(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "people_panel"
|
name = "contacts_panel"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use client::{Collaborator, UserStore};
|
use client::{Contact, UserStore};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action,
|
action,
|
||||||
elements::*,
|
elements::*,
|
||||||
|
@ -17,28 +17,28 @@ action!(ShareWorktree, u64);
|
||||||
action!(UnshareWorktree, u64);
|
action!(UnshareWorktree, u64);
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(PeoplePanel::share_worktree);
|
cx.add_action(ContactsPanel::share_worktree);
|
||||||
cx.add_action(PeoplePanel::unshare_worktree);
|
cx.add_action(ContactsPanel::unshare_worktree);
|
||||||
cx.add_action(PeoplePanel::join_worktree);
|
cx.add_action(ContactsPanel::join_worktree);
|
||||||
cx.add_action(PeoplePanel::leave_worktree);
|
cx.add_action(ContactsPanel::leave_worktree);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PeoplePanel {
|
pub struct ContactsPanel {
|
||||||
collaborators: ListState,
|
contacts: ListState,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
settings: watch::Receiver<Settings>,
|
settings: watch::Receiver<Settings>,
|
||||||
_maintain_collaborators: Subscription,
|
_maintain_contacts: Subscription,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PeoplePanel {
|
impl ContactsPanel {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
settings: watch::Receiver<Settings>,
|
settings: watch::Receiver<Settings>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
collaborators: ListState::new(
|
contacts: ListState::new(
|
||||||
user_store.read(cx).collaborators().len(),
|
user_store.read(cx).contacts().len(),
|
||||||
Orientation::Top,
|
Orientation::Top,
|
||||||
1000.,
|
1000.,
|
||||||
{
|
{
|
||||||
|
@ -46,10 +46,10 @@ impl PeoplePanel {
|
||||||
let settings = settings.clone();
|
let settings = settings.clone();
|
||||||
move |ix, cx| {
|
move |ix, cx| {
|
||||||
let user_store = user_store.read(cx);
|
let user_store = user_store.read(cx);
|
||||||
let collaborators = user_store.collaborators().clone();
|
let contacts = user_store.contacts().clone();
|
||||||
let current_user_id = user_store.current_user().map(|user| user.id);
|
let current_user_id = user_store.current_user().map(|user| user.id);
|
||||||
Self::render_collaborator(
|
Self::render_collaborator(
|
||||||
&collaborators[ix],
|
&contacts[ix],
|
||||||
current_user_id,
|
current_user_id,
|
||||||
&settings.borrow().theme,
|
&settings.borrow().theme,
|
||||||
cx,
|
cx,
|
||||||
|
@ -57,7 +57,7 @@ impl PeoplePanel {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_maintain_collaborators: cx.observe(&user_store, Self::update_collaborators),
|
_maintain_contacts: cx.observe(&user_store, Self::update_contacts),
|
||||||
user_store,
|
user_store,
|
||||||
settings,
|
settings,
|
||||||
}
|
}
|
||||||
|
@ -103,19 +103,19 @@ impl PeoplePanel {
|
||||||
.update(cx, |p, cx| p.close_remote_worktree(action.0, cx));
|
.update(cx, |p, cx| p.close_remote_worktree(action.0, cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_collaborators(&mut self, _: ModelHandle<UserStore>, cx: &mut ViewContext<Self>) {
|
fn update_contacts(&mut self, _: ModelHandle<UserStore>, cx: &mut ViewContext<Self>) {
|
||||||
self.collaborators
|
self.contacts
|
||||||
.reset(self.user_store.read(cx).collaborators().len());
|
.reset(self.user_store.read(cx).contacts().len());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_collaborator(
|
fn render_collaborator(
|
||||||
collaborator: &Collaborator,
|
collaborator: &Contact,
|
||||||
current_user_id: Option<u64>,
|
current_user_id: Option<u64>,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
cx: &mut LayoutContext,
|
cx: &mut LayoutContext,
|
||||||
) -> ElementBox {
|
) -> ElementBox {
|
||||||
let theme = &theme.people_panel;
|
let theme = &theme.contacts_panel;
|
||||||
let worktree_count = collaborator.worktrees.len();
|
let worktree_count = collaborator.worktrees.len();
|
||||||
let font_cache = cx.font_cache();
|
let font_cache = cx.font_cache();
|
||||||
let line_height = theme.unshared_worktree.name.text.line_height(font_cache);
|
let line_height = theme.unshared_worktree.name.text.line_height(font_cache);
|
||||||
|
@ -216,7 +216,7 @@ impl PeoplePanel {
|
||||||
.any(|guest| Some(guest.id) == current_user_id);
|
.any(|guest| Some(guest.id) == current_user_id);
|
||||||
let is_shared = worktree.is_shared;
|
let is_shared = worktree.is_shared;
|
||||||
|
|
||||||
MouseEventHandler::new::<PeoplePanel, _, _, _>(
|
MouseEventHandler::new::<ContactsPanel, _, _, _>(
|
||||||
worktree_id as usize,
|
worktree_id as usize,
|
||||||
cx,
|
cx,
|
||||||
|mouse_state, _| {
|
|mouse_state, _| {
|
||||||
|
@ -294,18 +294,18 @@ impl PeoplePanel {
|
||||||
|
|
||||||
pub enum Event {}
|
pub enum Event {}
|
||||||
|
|
||||||
impl Entity for PeoplePanel {
|
impl Entity for ContactsPanel {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View for PeoplePanel {
|
impl View for ContactsPanel {
|
||||||
fn ui_name() -> &'static str {
|
fn ui_name() -> &'static str {
|
||||||
"PeoplePanel"
|
"ContactsPanel"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
|
fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
|
||||||
let theme = &self.settings.borrow().theme.people_panel;
|
let theme = &self.settings.borrow().theme.contacts_panel;
|
||||||
Container::new(List::new(self.collaborators.clone()).boxed())
|
Container::new(List::new(self.contacts.clone()).boxed())
|
||||||
.with_style(theme.container)
|
.with_style(theme.container)
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
|
@ -371,12 +371,7 @@ impl EditorElement {
|
||||||
let content_origin = bounds.origin() + layout.text_offset;
|
let content_origin = bounds.origin() + layout.text_offset;
|
||||||
|
|
||||||
for (replica_id, selections) in &layout.selections {
|
for (replica_id, selections) in &layout.selections {
|
||||||
let style_ix = *replica_id as usize % (style.guest_selections.len() + 1);
|
let style = style.replica_selection_style(*replica_id);
|
||||||
let style = if style_ix == 0 {
|
|
||||||
&style.selection
|
|
||||||
} else {
|
|
||||||
&style.guest_selections[style_ix - 1]
|
|
||||||
};
|
|
||||||
|
|
||||||
for selection in selections {
|
for selection in selections {
|
||||||
if selection.start != selection.end {
|
if selection.start != selection.end {
|
||||||
|
|
|
@ -25,6 +25,11 @@ impl Align {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bottom(mut self) -> Self {
|
||||||
|
self.alignment.set_y(1.0);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn left(mut self) -> Self {
|
pub fn left(mut self) -> Self {
|
||||||
self.alignment.set_x(-1.0);
|
self.alignment.set_x(-1.0);
|
||||||
self
|
self
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod ignore;
|
||||||
mod worktree;
|
mod worktree;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use client::Client;
|
use client::{Client, UserStore};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
|
use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
|
||||||
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
||||||
|
@ -19,9 +19,11 @@ pub use worktree::*;
|
||||||
|
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
worktrees: Vec<ModelHandle<Worktree>>,
|
worktrees: Vec<ModelHandle<Worktree>>,
|
||||||
|
active_worktree: Option<usize>,
|
||||||
active_entry: Option<ProjectEntry>,
|
active_entry: Option<ProjectEntry>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
client: Arc<client::Client>,
|
client: Arc<client::Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,12 +45,19 @@ pub struct ProjectEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Project {
|
impl Project {
|
||||||
pub fn new(languages: Arc<LanguageRegistry>, rpc: Arc<Client>, fs: Arc<dyn Fs>) -> Self {
|
pub fn new(
|
||||||
|
languages: Arc<LanguageRegistry>,
|
||||||
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
|
fs: Arc<dyn Fs>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
worktrees: Default::default(),
|
worktrees: Default::default(),
|
||||||
|
active_worktree: None,
|
||||||
active_entry: None,
|
active_entry: None,
|
||||||
languages,
|
languages,
|
||||||
client: rpc,
|
client,
|
||||||
|
user_store,
|
||||||
fs,
|
fs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,11 +79,13 @@ 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.client.clone();
|
let client = self.client.clone();
|
||||||
|
let user_store = self.user_store.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 {
|
||||||
let worktree = Worktree::open_local(rpc, path, fs, languages, &mut cx).await?;
|
let worktree =
|
||||||
|
Worktree::open_local(client, user_store, path, fs, languages, &mut cx).await?;
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.add_worktree(worktree.clone(), cx);
|
this.add_worktree(worktree.clone(), cx);
|
||||||
});
|
});
|
||||||
|
@ -89,10 +100,12 @@ impl Project {
|
||||||
) -> Task<Result<ModelHandle<Worktree>>> {
|
) -> Task<Result<ModelHandle<Worktree>>> {
|
||||||
let rpc = self.client.clone();
|
let rpc = self.client.clone();
|
||||||
let languages = self.languages.clone();
|
let languages = self.languages.clone();
|
||||||
|
let user_store = self.user_store.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?;
|
||||||
let worktree =
|
let worktree =
|
||||||
Worktree::open_remote(rpc.clone(), remote_id, languages, &mut cx).await?;
|
Worktree::open_remote(rpc.clone(), remote_id, languages, user_store, &mut cx)
|
||||||
|
.await?;
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
cx.subscribe(&worktree, move |this, _, event, cx| match event {
|
cx.subscribe(&worktree, move |this, _, event, cx| match event {
|
||||||
worktree::Event::Closed => {
|
worktree::Event::Closed => {
|
||||||
|
@ -109,10 +122,25 @@ impl Project {
|
||||||
|
|
||||||
fn add_worktree(&mut self, worktree: ModelHandle<Worktree>, cx: &mut ModelContext<Self>) {
|
fn add_worktree(&mut self, worktree: ModelHandle<Worktree>, cx: &mut ModelContext<Self>) {
|
||||||
cx.observe(&worktree, |_, _, cx| cx.notify()).detach();
|
cx.observe(&worktree, |_, _, cx| cx.notify()).detach();
|
||||||
|
if self.active_worktree.is_none() {
|
||||||
|
self.set_active_worktree(Some(worktree.id()), cx);
|
||||||
|
}
|
||||||
self.worktrees.push(worktree);
|
self.worktrees.push(worktree);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_active_worktree(&mut self, worktree_id: Option<usize>, cx: &mut ModelContext<Self>) {
|
||||||
|
if self.active_worktree != worktree_id {
|
||||||
|
self.active_worktree = worktree_id;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn active_worktree(&self) -> Option<ModelHandle<Worktree>> {
|
||||||
|
self.active_worktree
|
||||||
|
.and_then(|worktree_id| self.worktree_for_id(worktree_id))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_active_path(&mut self, entry: Option<ProjectPath>, cx: &mut ModelContext<Self>) {
|
pub fn set_active_path(&mut self, entry: Option<ProjectPath>, cx: &mut ModelContext<Self>) {
|
||||||
let new_active_entry = entry.and_then(|project_path| {
|
let new_active_entry = entry.and_then(|project_path| {
|
||||||
let worktree = self.worktree_for_id(project_path.worktree_id)?;
|
let worktree = self.worktree_for_id(project_path.worktree_id)?;
|
||||||
|
@ -123,6 +151,9 @@ impl Project {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
if new_active_entry != self.active_entry {
|
if new_active_entry != self.active_entry {
|
||||||
|
if let Some(worktree_id) = new_active_entry.map(|e| e.worktree_id) {
|
||||||
|
self.set_active_worktree(Some(worktree_id), cx);
|
||||||
|
}
|
||||||
self.active_entry = new_active_entry;
|
self.active_entry = new_active_entry;
|
||||||
cx.emit(Event::ActiveEntryChanged(new_active_entry));
|
cx.emit(Event::ActiveEntryChanged(new_active_entry));
|
||||||
}
|
}
|
||||||
|
@ -184,6 +215,7 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_remote_worktree(&mut self, id: u64, cx: &mut ModelContext<Self>) {
|
pub fn close_remote_worktree(&mut self, id: u64, cx: &mut ModelContext<Self>) {
|
||||||
|
let mut reset_active = None;
|
||||||
self.worktrees.retain(|worktree| {
|
self.worktrees.retain(|worktree| {
|
||||||
let keep = worktree.update(cx, |worktree, cx| {
|
let keep = worktree.update(cx, |worktree, cx| {
|
||||||
if let Some(worktree) = worktree.as_remote_mut() {
|
if let Some(worktree) = worktree.as_remote_mut() {
|
||||||
|
@ -196,9 +228,15 @@ impl Project {
|
||||||
});
|
});
|
||||||
if !keep {
|
if !keep {
|
||||||
cx.emit(Event::WorktreeRemoved(worktree.id()));
|
cx.emit(Event::WorktreeRemoved(worktree.id()));
|
||||||
|
reset_active = Some(worktree.id());
|
||||||
}
|
}
|
||||||
keep
|
keep
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if self.active_worktree == reset_active {
|
||||||
|
self.active_worktree = self.worktrees.first().map(|w| w.id());
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn match_paths<'a>(
|
pub fn match_paths<'a>(
|
||||||
|
@ -302,6 +340,7 @@ impl Entity for Project {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use client::{http::ServerResponse, test::FakeHttpClient};
|
||||||
use fs::RealFs;
|
use fs::RealFs;
|
||||||
use gpui::TestAppContext;
|
use gpui::TestAppContext;
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
|
@ -407,7 +446,9 @@ 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 = client::Client::new();
|
let client = client::Client::new();
|
||||||
cx.add_model(|_| Project::new(languages, rpc, fs))
|
let http_client = FakeHttpClient::new(|_| async move { Ok(ServerResponse::new(404)) });
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
cx.add_model(|_| Project::new(languages, client, user_store, fs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
|
use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use client::{proto, Client, PeerId, TypedEnvelope};
|
use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore};
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use fuzzy::CharBag;
|
use fuzzy::CharBag;
|
||||||
|
@ -63,6 +63,33 @@ pub enum Event {
|
||||||
Closed,
|
Closed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Collaborator {
|
||||||
|
pub user: Arc<User>,
|
||||||
|
pub peer_id: PeerId,
|
||||||
|
pub replica_id: ReplicaId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Collaborator {
|
||||||
|
fn from_proto(
|
||||||
|
message: proto::Collaborator,
|
||||||
|
user_store: &ModelHandle<UserStore>,
|
||||||
|
cx: &mut AsyncAppContext,
|
||||||
|
) -> impl Future<Output = Result<Self>> {
|
||||||
|
let user = user_store.update(cx, |user_store, cx| {
|
||||||
|
user_store.fetch_user(message.user_id, cx)
|
||||||
|
});
|
||||||
|
|
||||||
|
async move {
|
||||||
|
Ok(Self {
|
||||||
|
peer_id: PeerId(message.peer_id),
|
||||||
|
user: user.await?,
|
||||||
|
replica_id: message.replica_id as ReplicaId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Entity for Worktree {
|
impl Entity for Worktree {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
|
|
||||||
|
@ -70,7 +97,7 @@ impl Entity for Worktree {
|
||||||
match self {
|
match self {
|
||||||
Self::Local(tree) => {
|
Self::Local(tree) => {
|
||||||
if let Some(worktree_id) = *tree.remote_id.borrow() {
|
if let Some(worktree_id) = *tree.remote_id.borrow() {
|
||||||
let rpc = tree.rpc.clone();
|
let rpc = tree.client.clone();
|
||||||
cx.spawn(|_| async move {
|
cx.spawn(|_| async move {
|
||||||
if let Err(err) = rpc.send(proto::CloseWorktree { worktree_id }).await {
|
if let Err(err) = rpc.send(proto::CloseWorktree { worktree_id }).await {
|
||||||
log::error!("error closing worktree: {}", err);
|
log::error!("error closing worktree: {}", err);
|
||||||
|
@ -118,14 +145,15 @@ impl Entity for Worktree {
|
||||||
|
|
||||||
impl Worktree {
|
impl Worktree {
|
||||||
pub async fn open_local(
|
pub async fn open_local(
|
||||||
rpc: Arc<Client>,
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
path: impl Into<Arc<Path>>,
|
path: impl Into<Arc<Path>>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
cx: &mut AsyncAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
) -> Result<ModelHandle<Self>> {
|
) -> Result<ModelHandle<Self>> {
|
||||||
let (tree, scan_states_tx) =
|
let (tree, scan_states_tx) =
|
||||||
LocalWorktree::new(rpc, path, fs.clone(), languages, cx).await?;
|
LocalWorktree::new(client, user_store, path, fs.clone(), languages, cx).await?;
|
||||||
tree.update(cx, |tree, cx| {
|
tree.update(cx, |tree, cx| {
|
||||||
let tree = tree.as_local_mut().unwrap();
|
let tree = tree.as_local_mut().unwrap();
|
||||||
let abs_path = tree.snapshot.abs_path.clone();
|
let abs_path = tree.snapshot.abs_path.clone();
|
||||||
|
@ -142,18 +170,22 @@ impl Worktree {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn open_remote(
|
pub async fn open_remote(
|
||||||
rpc: Arc<Client>,
|
client: Arc<Client>,
|
||||||
id: u64,
|
id: u64,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
cx: &mut AsyncAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
) -> Result<ModelHandle<Self>> {
|
) -> Result<ModelHandle<Self>> {
|
||||||
let response = rpc.request(proto::JoinWorktree { worktree_id: id }).await?;
|
let response = client
|
||||||
Worktree::remote(response, rpc, languages, cx).await
|
.request(proto::JoinWorktree { worktree_id: id })
|
||||||
|
.await?;
|
||||||
|
Worktree::remote(response, client, user_store, languages, cx).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn remote(
|
async fn remote(
|
||||||
join_response: proto::JoinWorktreeResponse,
|
join_response: proto::JoinWorktreeResponse,
|
||||||
rpc: Arc<Client>,
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
cx: &mut AsyncAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
) -> Result<ModelHandle<Self>> {
|
) -> Result<ModelHandle<Self>> {
|
||||||
|
@ -163,7 +195,6 @@ impl Worktree {
|
||||||
|
|
||||||
let remote_id = worktree.id;
|
let remote_id = worktree.id;
|
||||||
let replica_id = join_response.replica_id as ReplicaId;
|
let replica_id = join_response.replica_id as ReplicaId;
|
||||||
let peers = join_response.peers;
|
|
||||||
let root_char_bag: CharBag = worktree
|
let root_char_bag: CharBag = worktree
|
||||||
.root_name
|
.root_name
|
||||||
.chars()
|
.chars()
|
||||||
|
@ -198,6 +229,20 @@ impl Worktree {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
let user_ids = join_response
|
||||||
|
.collaborators
|
||||||
|
.iter()
|
||||||
|
.map(|peer| peer.user_id)
|
||||||
|
.collect();
|
||||||
|
user_store
|
||||||
|
.update(cx, |user_store, cx| user_store.load_users(user_ids, cx))
|
||||||
|
.await?;
|
||||||
|
let mut collaborators = HashMap::with_capacity(join_response.collaborators.len());
|
||||||
|
for message in join_response.collaborators {
|
||||||
|
let collaborator = Collaborator::from_proto(message, &user_store, cx).await?;
|
||||||
|
collaborators.insert(collaborator.peer_id, collaborator);
|
||||||
|
}
|
||||||
|
|
||||||
let worktree = cx.update(|cx| {
|
let worktree = cx.update(|cx| {
|
||||||
cx.add_model(|cx: &mut ModelContext<Worktree>| {
|
cx.add_model(|cx: &mut ModelContext<Worktree>| {
|
||||||
let snapshot = Snapshot {
|
let snapshot = Snapshot {
|
||||||
|
@ -243,12 +288,12 @@ impl Worktree {
|
||||||
}
|
}
|
||||||
|
|
||||||
let _subscriptions = vec![
|
let _subscriptions = vec![
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Self::handle_add_peer),
|
client.subscribe_to_entity(remote_id, cx, Self::handle_add_collaborator),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Self::handle_remove_peer),
|
client.subscribe_to_entity(remote_id, cx, Self::handle_remove_collaborator),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Self::handle_update),
|
client.subscribe_to_entity(remote_id, cx, Self::handle_update),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Self::handle_update_buffer),
|
client.subscribe_to_entity(remote_id, cx, Self::handle_update_buffer),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved),
|
client.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Self::handle_unshare),
|
client.subscribe_to_entity(remote_id, cx, Self::handle_unshare),
|
||||||
];
|
];
|
||||||
|
|
||||||
Worktree::Remote(RemoteWorktree {
|
Worktree::Remote(RemoteWorktree {
|
||||||
|
@ -257,14 +302,12 @@ impl Worktree {
|
||||||
snapshot,
|
snapshot,
|
||||||
snapshot_rx,
|
snapshot_rx,
|
||||||
updates_tx,
|
updates_tx,
|
||||||
client: rpc.clone(),
|
client: client.clone(),
|
||||||
open_buffers: Default::default(),
|
open_buffers: Default::default(),
|
||||||
peers: peers
|
collaborators,
|
||||||
.into_iter()
|
|
||||||
.map(|p| (PeerId(p.peer_id), p.replica_id as ReplicaId))
|
|
||||||
.collect(),
|
|
||||||
queued_operations: Default::default(),
|
queued_operations: Default::default(),
|
||||||
languages,
|
languages,
|
||||||
|
user_store,
|
||||||
_subscriptions,
|
_subscriptions,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -318,27 +361,52 @@ impl Worktree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_add_peer(
|
pub fn user_store(&self) -> &ModelHandle<UserStore> {
|
||||||
&mut self,
|
|
||||||
envelope: TypedEnvelope<proto::AddPeer>,
|
|
||||||
_: Arc<Client>,
|
|
||||||
cx: &mut ModelContext<Self>,
|
|
||||||
) -> Result<()> {
|
|
||||||
match self {
|
match self {
|
||||||
Worktree::Local(worktree) => worktree.add_peer(envelope, cx),
|
Worktree::Local(worktree) => &worktree.user_store,
|
||||||
Worktree::Remote(worktree) => worktree.add_peer(envelope, cx),
|
Worktree::Remote(worktree) => &worktree.user_store,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_remove_peer(
|
pub fn handle_add_collaborator(
|
||||||
&mut self,
|
&mut self,
|
||||||
envelope: TypedEnvelope<proto::RemovePeer>,
|
mut envelope: TypedEnvelope<proto::AddCollaborator>,
|
||||||
|
_: Arc<Client>,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let user_store = self.user_store().clone();
|
||||||
|
let collaborator = envelope
|
||||||
|
.payload
|
||||||
|
.collaborator
|
||||||
|
.take()
|
||||||
|
.ok_or_else(|| anyhow!("empty collaborator"))?;
|
||||||
|
|
||||||
|
cx.spawn(|this, mut cx| {
|
||||||
|
async move {
|
||||||
|
let collaborator =
|
||||||
|
Collaborator::from_proto(collaborator, &user_store, &mut cx).await?;
|
||||||
|
this.update(&mut cx, |this, cx| match this {
|
||||||
|
Worktree::Local(worktree) => worktree.add_collaborator(collaborator, cx),
|
||||||
|
Worktree::Remote(worktree) => worktree.add_collaborator(collaborator, cx),
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
.log_err()
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_remove_collaborator(
|
||||||
|
&mut self,
|
||||||
|
envelope: TypedEnvelope<proto::RemoveCollaborator>,
|
||||||
_: Arc<Client>,
|
_: Arc<Client>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Worktree::Local(worktree) => worktree.remove_peer(envelope, cx),
|
Worktree::Local(worktree) => worktree.remove_collaborator(envelope, cx),
|
||||||
Worktree::Remote(worktree) => worktree.remove_peer(envelope, cx),
|
Worktree::Remote(worktree) => worktree.remove_collaborator(envelope, cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,10 +458,10 @@ impl Worktree {
|
||||||
.close_remote_buffer(envelope, cx)
|
.close_remote_buffer(envelope, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn peers(&self) -> &HashMap<PeerId, ReplicaId> {
|
pub fn collaborators(&self) -> &HashMap<PeerId, Collaborator> {
|
||||||
match self {
|
match self {
|
||||||
Worktree::Local(worktree) => &worktree.peers,
|
Worktree::Local(worktree) => &worktree.collaborators,
|
||||||
Worktree::Remote(worktree) => &worktree.peers,
|
Worktree::Remote(worktree) => &worktree.collaborators,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,7 +789,7 @@ impl Worktree {
|
||||||
Worktree::Local(worktree) => worktree
|
Worktree::Local(worktree) => worktree
|
||||||
.remote_id
|
.remote_id
|
||||||
.borrow()
|
.borrow()
|
||||||
.map(|id| (worktree.rpc.clone(), id)),
|
.map(|id| (worktree.client.clone(), id)),
|
||||||
Worktree::Remote(worktree) => Some((worktree.client.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 {
|
||||||
|
@ -772,10 +840,11 @@ pub struct LocalWorktree {
|
||||||
open_buffers: HashMap<usize, WeakModelHandle<Buffer>>,
|
open_buffers: HashMap<usize, WeakModelHandle<Buffer>>,
|
||||||
shared_buffers: HashMap<PeerId, HashMap<u64, ModelHandle<Buffer>>>,
|
shared_buffers: HashMap<PeerId, HashMap<u64, ModelHandle<Buffer>>>,
|
||||||
diagnostics: HashMap<PathBuf, Vec<lsp::Diagnostic>>,
|
diagnostics: HashMap<PathBuf, Vec<lsp::Diagnostic>>,
|
||||||
peers: HashMap<PeerId, ReplicaId>,
|
collaborators: HashMap<PeerId, Collaborator>,
|
||||||
queued_operations: Vec<(u64, Operation)>,
|
queued_operations: Vec<(u64, Operation)>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
rpc: Arc<Client>,
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
language_servers: HashMap<String, Arc<LanguageServer>>,
|
language_servers: HashMap<String, Arc<LanguageServer>>,
|
||||||
}
|
}
|
||||||
|
@ -787,7 +856,8 @@ struct WorktreeConfig {
|
||||||
|
|
||||||
impl LocalWorktree {
|
impl LocalWorktree {
|
||||||
async fn new(
|
async fn new(
|
||||||
rpc: Arc<Client>,
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
path: impl Into<Arc<Path>>,
|
path: impl Into<Arc<Path>>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
|
@ -841,20 +911,20 @@ impl LocalWorktree {
|
||||||
|
|
||||||
let (mut remote_id_tx, remote_id_rx) = watch::channel();
|
let (mut remote_id_tx, remote_id_rx) = watch::channel();
|
||||||
let _maintain_remote_id_task = cx.spawn_weak({
|
let _maintain_remote_id_task = cx.spawn_weak({
|
||||||
let rpc = rpc.clone();
|
let rpc = client.clone();
|
||||||
move |this, cx| {
|
move |this, cx| {
|
||||||
async move {
|
async move {
|
||||||
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 client::Status::Connected { .. } = status {
|
let remote_id = if let client::Status::Connected { .. } = status {
|
||||||
let collaborator_logins = this.read_with(&cx, |this, _| {
|
let authorized_logins = this.read_with(&cx, |this, _| {
|
||||||
this.as_local().unwrap().config.collaborators.clone()
|
this.as_local().unwrap().config.collaborators.clone()
|
||||||
});
|
});
|
||||||
let response = rpc
|
let response = rpc
|
||||||
.request(proto::OpenWorktree {
|
.request(proto::OpenWorktree {
|
||||||
root_name: root_name.clone(),
|
root_name: root_name.clone(),
|
||||||
collaborator_logins,
|
authorized_logins,
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -887,9 +957,10 @@ impl LocalWorktree {
|
||||||
shared_buffers: Default::default(),
|
shared_buffers: Default::default(),
|
||||||
diagnostics: Default::default(),
|
diagnostics: Default::default(),
|
||||||
queued_operations: Default::default(),
|
queued_operations: Default::default(),
|
||||||
peers: Default::default(),
|
collaborators: Default::default(),
|
||||||
languages,
|
languages,
|
||||||
rpc,
|
client,
|
||||||
|
user_store,
|
||||||
fs,
|
fs,
|
||||||
language_servers: Default::default(),
|
language_servers: Default::default(),
|
||||||
};
|
};
|
||||||
|
@ -1075,33 +1146,27 @@ impl LocalWorktree {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_peer(
|
pub fn add_collaborator(
|
||||||
&mut self,
|
&mut self,
|
||||||
envelope: TypedEnvelope<proto::AddPeer>,
|
collaborator: Collaborator,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Result<()> {
|
) {
|
||||||
let peer = envelope
|
self.collaborators
|
||||||
.payload
|
.insert(collaborator.peer_id, collaborator);
|
||||||
.peer
|
|
||||||
.as_ref()
|
|
||||||
.ok_or_else(|| anyhow!("empty peer"))?;
|
|
||||||
self.peers
|
|
||||||
.insert(PeerId(peer.peer_id), peer.replica_id as ReplicaId);
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_peer(
|
pub fn remove_collaborator(
|
||||||
&mut self,
|
&mut self,
|
||||||
envelope: TypedEnvelope<proto::RemovePeer>,
|
envelope: TypedEnvelope<proto::RemoveCollaborator>,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let peer_id = PeerId(envelope.payload.peer_id);
|
let peer_id = PeerId(envelope.payload.peer_id);
|
||||||
let replica_id = self
|
let replica_id = self
|
||||||
.peers
|
.collaborators
|
||||||
.remove(&peer_id)
|
.remove(&peer_id)
|
||||||
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?;
|
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?
|
||||||
|
.replica_id;
|
||||||
self.shared_buffers.remove(&peer_id);
|
self.shared_buffers.remove(&peer_id);
|
||||||
for (_, buffer) in &self.open_buffers {
|
for (_, buffer) in &self.open_buffers {
|
||||||
if let Some(buffer) = buffer.upgrade(cx) {
|
if let Some(buffer) = buffer.upgrade(cx) {
|
||||||
|
@ -1243,7 +1308,7 @@ impl LocalWorktree {
|
||||||
pub fn share(&mut self, cx: &mut ModelContext<Worktree>) -> Task<anyhow::Result<u64>> {
|
pub fn share(&mut self, cx: &mut ModelContext<Worktree>) -> Task<anyhow::Result<u64>> {
|
||||||
let snapshot = self.snapshot();
|
let snapshot = self.snapshot();
|
||||||
let share_request = self.share_request(cx);
|
let share_request = self.share_request(cx);
|
||||||
let rpc = self.rpc.clone();
|
let rpc = self.client.clone();
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let share_request = if let Some(request) = share_request.await {
|
let share_request = if let Some(request) = share_request.await {
|
||||||
request
|
request
|
||||||
|
@ -1276,8 +1341,8 @@ impl LocalWorktree {
|
||||||
|
|
||||||
this.update(&mut cx, |worktree, cx| {
|
this.update(&mut cx, |worktree, cx| {
|
||||||
let _subscriptions = vec![
|
let _subscriptions = vec![
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_add_peer),
|
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_add_collaborator),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_remove_peer),
|
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_remove_collaborator),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_open_buffer),
|
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_open_buffer),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_close_buffer),
|
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_close_buffer),
|
||||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_update_buffer),
|
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_update_buffer),
|
||||||
|
@ -1297,7 +1362,7 @@ impl LocalWorktree {
|
||||||
|
|
||||||
pub fn unshare(&mut self, cx: &mut ModelContext<Worktree>) {
|
pub fn unshare(&mut self, cx: &mut ModelContext<Worktree>) {
|
||||||
self.share.take();
|
self.share.take();
|
||||||
let rpc = self.rpc.clone();
|
let rpc = self.client.clone();
|
||||||
let remote_id = self.remote_id();
|
let remote_id = self.remote_id();
|
||||||
cx.foreground()
|
cx.foreground()
|
||||||
.spawn(
|
.spawn(
|
||||||
|
@ -1373,8 +1438,9 @@ pub struct RemoteWorktree {
|
||||||
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>,
|
collaborators: HashMap<PeerId, Collaborator>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
queued_operations: Vec<(u64, Operation)>,
|
queued_operations: Vec<(u64, Operation)>,
|
||||||
_subscriptions: Vec<client::Subscription>,
|
_subscriptions: Vec<client::Subscription>,
|
||||||
}
|
}
|
||||||
|
@ -1491,32 +1557,27 @@ impl RemoteWorktree {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_peer(
|
pub fn add_collaborator(
|
||||||
&mut self,
|
&mut self,
|
||||||
envelope: TypedEnvelope<proto::AddPeer>,
|
collaborator: Collaborator,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Result<()> {
|
) {
|
||||||
let peer = envelope
|
self.collaborators
|
||||||
.payload
|
.insert(collaborator.peer_id, collaborator);
|
||||||
.peer
|
|
||||||
.as_ref()
|
|
||||||
.ok_or_else(|| anyhow!("empty peer"))?;
|
|
||||||
self.peers
|
|
||||||
.insert(PeerId(peer.peer_id), peer.replica_id as ReplicaId);
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_peer(
|
pub fn remove_collaborator(
|
||||||
&mut self,
|
&mut self,
|
||||||
envelope: TypedEnvelope<proto::RemovePeer>,
|
envelope: TypedEnvelope<proto::RemoveCollaborator>,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let peer_id = PeerId(envelope.payload.peer_id);
|
let peer_id = PeerId(envelope.payload.peer_id);
|
||||||
let replica_id = self
|
let replica_id = self
|
||||||
.peers
|
.collaborators
|
||||||
.remove(&peer_id)
|
.remove(&peer_id)
|
||||||
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?;
|
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?
|
||||||
|
.replica_id;
|
||||||
for (_, buffer) in &self.open_buffers {
|
for (_, buffer) in &self.open_buffers {
|
||||||
if let Some(buffer) = buffer.upgrade(cx) {
|
if let Some(buffer) = buffer.upgrade(cx) {
|
||||||
buffer.update(cx, |buffer, cx| buffer.remove_peer(replica_id, cx));
|
buffer.update(cx, |buffer, cx| buffer.remove_peer(replica_id, cx));
|
||||||
|
@ -1977,7 +2038,7 @@ impl language::File for File {
|
||||||
) -> Task<Result<(clock::Global, SystemTime)>> {
|
) -> Task<Result<(clock::Global, SystemTime)>> {
|
||||||
self.worktree.update(cx, |worktree, cx| match worktree {
|
self.worktree.update(cx, |worktree, cx| match worktree {
|
||||||
Worktree::Local(worktree) => {
|
Worktree::Local(worktree) => {
|
||||||
let rpc = worktree.rpc.clone();
|
let rpc = worktree.client.clone();
|
||||||
let worktree_id = *worktree.remote_id.borrow();
|
let worktree_id = *worktree.remote_id.borrow();
|
||||||
let save = worktree.save(self.path.clone(), text, cx);
|
let save = worktree.save(self.path.clone(), text, cx);
|
||||||
cx.background().spawn(async move {
|
cx.background().spawn(async move {
|
||||||
|
@ -2944,7 +3005,7 @@ mod tests {
|
||||||
use crate::fs::FakeFs;
|
use crate::fs::FakeFs;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use buffer::Point;
|
use buffer::Point;
|
||||||
use client::test::FakeServer;
|
use client::test::{FakeHttpClient, FakeServer};
|
||||||
use fs::RealFs;
|
use fs::RealFs;
|
||||||
use language::{tree_sitter_rust, LanguageServerConfig};
|
use language::{tree_sitter_rust, LanguageServerConfig};
|
||||||
use language::{Diagnostic, LanguageConfig};
|
use language::{Diagnostic, LanguageConfig};
|
||||||
|
@ -2960,7 +3021,7 @@ mod tests {
|
||||||
use util::test::temp_tree;
|
use util::test::temp_tree;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_traversal(cx: gpui::TestAppContext) {
|
async fn test_traversal(mut cx: gpui::TestAppContext) {
|
||||||
let fs = FakeFs::new();
|
let fs = FakeFs::new();
|
||||||
fs.insert_tree(
|
fs.insert_tree(
|
||||||
"/root",
|
"/root",
|
||||||
|
@ -2974,8 +3035,13 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
Client::new(),
|
client,
|
||||||
|
user_store,
|
||||||
Arc::from(Path::new("/root")),
|
Arc::from(Path::new("/root")),
|
||||||
Arc::new(fs),
|
Arc::new(fs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3006,8 +3072,14 @@ mod tests {
|
||||||
let dir = temp_tree(json!({
|
let dir = temp_tree(json!({
|
||||||
"file1": "the old contents",
|
"file1": "the old contents",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
Client::new(),
|
client,
|
||||||
|
user_store,
|
||||||
dir.path(),
|
dir.path(),
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3036,8 +3108,13 @@ mod tests {
|
||||||
}));
|
}));
|
||||||
let file_path = dir.path().join("file1");
|
let file_path = dir.path().join("file1");
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
Client::new(),
|
client,
|
||||||
|
user_store,
|
||||||
file_path.clone(),
|
file_path.clone(),
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3082,8 +3159,10 @@ mod tests {
|
||||||
let user_id = 5;
|
let user_id = 5;
|
||||||
let mut client = 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 user_store = server.build_user_store(client.clone(), &mut cx).await;
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
|
user_store.clone(),
|
||||||
dir.path(),
|
dir.path(),
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3135,9 +3214,10 @@ mod tests {
|
||||||
proto::JoinWorktreeResponse {
|
proto::JoinWorktreeResponse {
|
||||||
worktree: share_request.await.unwrap().worktree,
|
worktree: share_request.await.unwrap().worktree,
|
||||||
replica_id: 1,
|
replica_id: 1,
|
||||||
peers: Vec::new(),
|
collaborators: Vec::new(),
|
||||||
},
|
},
|
||||||
Client::new(),
|
Client::new(),
|
||||||
|
user_store,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
&mut cx.to_async(),
|
&mut cx.to_async(),
|
||||||
)
|
)
|
||||||
|
@ -3230,7 +3310,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_rescan_with_gitignore(cx: gpui::TestAppContext) {
|
async fn test_rescan_with_gitignore(mut cx: gpui::TestAppContext) {
|
||||||
let dir = temp_tree(json!({
|
let dir = temp_tree(json!({
|
||||||
".git": {},
|
".git": {},
|
||||||
".gitignore": "ignored-dir\n",
|
".gitignore": "ignored-dir\n",
|
||||||
|
@ -3242,8 +3322,13 @@ mod tests {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
Client::new(),
|
client,
|
||||||
|
user_store,
|
||||||
dir.path(),
|
dir.path(),
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3281,6 +3366,7 @@ mod tests {
|
||||||
let user_id = 100;
|
let user_id = 100;
|
||||||
let mut client = 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 user_store = server.build_user_store(client.clone(), &mut cx).await;
|
||||||
|
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
fs.insert_tree(
|
fs.insert_tree(
|
||||||
|
@ -3298,6 +3384,7 @@ mod tests {
|
||||||
|
|
||||||
let worktree = Worktree::open_local(
|
let worktree = Worktree::open_local(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
|
user_store,
|
||||||
"/path/to/the-dir".as_ref(),
|
"/path/to/the-dir".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3306,17 +3393,12 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
|
||||||
let cx = cx.to_async();
|
|
||||||
client.authenticate_and_connect(&cx).await.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let open_worktree = server.receive::<proto::OpenWorktree>().await.unwrap();
|
let open_worktree = server.receive::<proto::OpenWorktree>().await.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
open_worktree.payload,
|
open_worktree.payload,
|
||||||
proto::OpenWorktree {
|
proto::OpenWorktree {
|
||||||
root_name: "the-dir".to_string(),
|
root_name: "the-dir".to_string(),
|
||||||
collaborator_logins: vec!["friend-1".to_string(), "friend-2".to_string()],
|
authorized_logins: vec!["friend-1".to_string(), "friend-2".to_string()],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3344,8 +3426,13 @@ mod tests {
|
||||||
"file2": "def",
|
"file2": "def",
|
||||||
"file3": "ghi",
|
"file3": "ghi",
|
||||||
}));
|
}));
|
||||||
|
let client = Client::new();
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
Client::new(),
|
client,
|
||||||
|
user_store,
|
||||||
dir.path(),
|
dir.path(),
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3477,8 +3564,13 @@ 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 client = Client::new();
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
Client::new(),
|
client,
|
||||||
|
user_store,
|
||||||
dir.path(),
|
dir.path(),
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -3587,8 +3679,13 @@ mod tests {
|
||||||
"b.rs": "const y: i32 = 1",
|
"b.rs": "const y: i32 = 1",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
Client::new(),
|
client,
|
||||||
|
user_store,
|
||||||
dir.path(),
|
dir.path(),
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
Arc::new(languages),
|
Arc::new(languages),
|
||||||
|
|
|
@ -621,6 +621,7 @@ mod tests {
|
||||||
Project::new(
|
Project::new(
|
||||||
params.languages.clone(),
|
params.languages.clone(),
|
||||||
params.client.clone(),
|
params.client.clone(),
|
||||||
|
params.user_store.clone(),
|
||||||
params.fs.clone(),
|
params.fs.clone(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,8 +21,8 @@ message Envelope {
|
||||||
UpdateBuffer update_buffer = 16;
|
UpdateBuffer update_buffer = 16;
|
||||||
SaveBuffer save_buffer = 17;
|
SaveBuffer save_buffer = 17;
|
||||||
BufferSaved buffer_saved = 18;
|
BufferSaved buffer_saved = 18;
|
||||||
AddPeer add_peer = 19;
|
AddCollaborator add_collaborator = 19;
|
||||||
RemovePeer remove_peer = 20;
|
RemoveCollaborator remove_collaborator = 20;
|
||||||
GetChannels get_channels = 21;
|
GetChannels get_channels = 21;
|
||||||
GetChannelsResponse get_channels_response = 22;
|
GetChannelsResponse get_channels_response = 22;
|
||||||
GetUsers get_users = 23;
|
GetUsers get_users = 23;
|
||||||
|
@ -38,7 +38,7 @@ message Envelope {
|
||||||
OpenWorktree open_worktree = 33;
|
OpenWorktree open_worktree = 33;
|
||||||
OpenWorktreeResponse open_worktree_response = 34;
|
OpenWorktreeResponse open_worktree_response = 34;
|
||||||
UnshareWorktree unshare_worktree = 35;
|
UnshareWorktree unshare_worktree = 35;
|
||||||
UpdateCollaborators update_collaborators = 36;
|
UpdateContacts update_contacts = 36;
|
||||||
LeaveWorktree leave_worktree = 37;
|
LeaveWorktree leave_worktree = 37;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ message Error {
|
||||||
|
|
||||||
message OpenWorktree {
|
message OpenWorktree {
|
||||||
string root_name = 1;
|
string root_name = 1;
|
||||||
repeated string collaborator_logins = 2;
|
repeated string authorized_logins = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message OpenWorktreeResponse {
|
message OpenWorktreeResponse {
|
||||||
|
@ -83,7 +83,7 @@ message LeaveWorktree {
|
||||||
message JoinWorktreeResponse {
|
message JoinWorktreeResponse {
|
||||||
Worktree worktree = 2;
|
Worktree worktree = 2;
|
||||||
uint32 replica_id = 3;
|
uint32 replica_id = 3;
|
||||||
repeated Peer peers = 4;
|
repeated Collaborator collaborators = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateWorktree {
|
message UpdateWorktree {
|
||||||
|
@ -96,12 +96,12 @@ message CloseWorktree {
|
||||||
uint64 worktree_id = 1;
|
uint64 worktree_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AddPeer {
|
message AddCollaborator {
|
||||||
uint64 worktree_id = 1;
|
uint64 worktree_id = 1;
|
||||||
Peer peer = 2;
|
Collaborator collaborator = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RemovePeer {
|
message RemoveCollaborator {
|
||||||
uint64 worktree_id = 1;
|
uint64 worktree_id = 1;
|
||||||
uint32 peer_id = 2;
|
uint32 peer_id = 2;
|
||||||
}
|
}
|
||||||
|
@ -190,15 +190,16 @@ message GetChannelMessagesResponse {
|
||||||
bool done = 2;
|
bool done = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateCollaborators {
|
message UpdateContacts {
|
||||||
repeated Collaborator collaborators = 1;
|
repeated Contact contacts = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entities
|
// Entities
|
||||||
|
|
||||||
message Peer {
|
message Collaborator {
|
||||||
uint32 peer_id = 1;
|
uint32 peer_id = 1;
|
||||||
uint32 replica_id = 2;
|
uint32 replica_id = 2;
|
||||||
|
uint64 user_id = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message User {
|
message User {
|
||||||
|
@ -357,7 +358,7 @@ message ChannelMessage {
|
||||||
Nonce nonce = 5;
|
Nonce nonce = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Collaborator {
|
message Contact {
|
||||||
uint64 user_id = 1;
|
uint64 user_id = 1;
|
||||||
repeated WorktreeMetadata worktrees = 2;
|
repeated WorktreeMetadata worktrees = 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ use postage::{
|
||||||
prelude::{Sink as _, Stream as _},
|
prelude::{Sink as _, Stream as _},
|
||||||
};
|
};
|
||||||
use smol_timeout::TimeoutExt as _;
|
use smol_timeout::TimeoutExt as _;
|
||||||
|
use std::sync::atomic::Ordering::SeqCst;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fmt,
|
fmt,
|
||||||
|
@ -81,12 +82,12 @@ impl<T: RequestMessage> TypedEnvelope<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Peer {
|
pub struct Peer {
|
||||||
connections: RwLock<HashMap<ConnectionId, ConnectionState>>,
|
pub connections: RwLock<HashMap<ConnectionId, ConnectionState>>,
|
||||||
next_connection_id: AtomicU32,
|
next_connection_id: AtomicU32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ConnectionState {
|
pub struct ConnectionState {
|
||||||
outgoing_tx: mpsc::Sender<proto::Envelope>,
|
outgoing_tx: mpsc::Sender<proto::Envelope>,
|
||||||
next_message_id: Arc<AtomicU32>,
|
next_message_id: Arc<AtomicU32>,
|
||||||
response_channels: Arc<Mutex<Option<HashMap<u32, mpsc::Sender<proto::Envelope>>>>>,
|
response_channels: Arc<Mutex<Option<HashMap<u32, mpsc::Sender<proto::Envelope>>>>>,
|
||||||
|
@ -110,10 +111,7 @@ impl Peer {
|
||||||
impl Future<Output = anyhow::Result<()>> + Send,
|
impl Future<Output = anyhow::Result<()>> + Send,
|
||||||
mpsc::Receiver<Box<dyn AnyTypedEnvelope>>,
|
mpsc::Receiver<Box<dyn AnyTypedEnvelope>>,
|
||||||
) {
|
) {
|
||||||
let connection_id = ConnectionId(
|
let connection_id = ConnectionId(self.next_connection_id.fetch_add(1, SeqCst));
|
||||||
self.next_connection_id
|
|
||||||
.fetch_add(1, atomic::Ordering::SeqCst),
|
|
||||||
);
|
|
||||||
let (mut incoming_tx, incoming_rx) = mpsc::channel(64);
|
let (mut incoming_tx, incoming_rx) = mpsc::channel(64);
|
||||||
let (outgoing_tx, mut outgoing_rx) = mpsc::channel(64);
|
let (outgoing_tx, mut outgoing_rx) = mpsc::channel(64);
|
||||||
let connection_state = ConnectionState {
|
let connection_state = ConnectionState {
|
||||||
|
@ -219,9 +217,7 @@ impl Peer {
|
||||||
let (tx, mut rx) = mpsc::channel(1);
|
let (tx, mut rx) = mpsc::channel(1);
|
||||||
async move {
|
async move {
|
||||||
let mut connection = this.connection_state(receiver_id).await?;
|
let mut connection = this.connection_state(receiver_id).await?;
|
||||||
let message_id = connection
|
let message_id = connection.next_message_id.fetch_add(1, SeqCst);
|
||||||
.next_message_id
|
|
||||||
.fetch_add(1, atomic::Ordering::SeqCst);
|
|
||||||
connection
|
connection
|
||||||
.response_channels
|
.response_channels
|
||||||
.lock()
|
.lock()
|
||||||
|
|
|
@ -121,7 +121,7 @@ macro_rules! entity_messages {
|
||||||
|
|
||||||
messages!(
|
messages!(
|
||||||
Ack,
|
Ack,
|
||||||
AddPeer,
|
AddCollaborator,
|
||||||
BufferSaved,
|
BufferSaved,
|
||||||
ChannelMessageSent,
|
ChannelMessageSent,
|
||||||
CloseBuffer,
|
CloseBuffer,
|
||||||
|
@ -131,7 +131,7 @@ messages!(
|
||||||
GetChannelMessagesResponse,
|
GetChannelMessagesResponse,
|
||||||
GetChannels,
|
GetChannels,
|
||||||
GetChannelsResponse,
|
GetChannelsResponse,
|
||||||
UpdateCollaborators,
|
UpdateContacts,
|
||||||
GetUsers,
|
GetUsers,
|
||||||
GetUsersResponse,
|
GetUsersResponse,
|
||||||
JoinChannel,
|
JoinChannel,
|
||||||
|
@ -145,7 +145,7 @@ messages!(
|
||||||
OpenWorktree,
|
OpenWorktree,
|
||||||
OpenWorktreeResponse,
|
OpenWorktreeResponse,
|
||||||
Ping,
|
Ping,
|
||||||
RemovePeer,
|
RemoveCollaborator,
|
||||||
SaveBuffer,
|
SaveBuffer,
|
||||||
SendChannelMessage,
|
SendChannelMessage,
|
||||||
SendChannelMessageResponse,
|
SendChannelMessageResponse,
|
||||||
|
@ -174,13 +174,13 @@ request_messages!(
|
||||||
|
|
||||||
entity_messages!(
|
entity_messages!(
|
||||||
worktree_id,
|
worktree_id,
|
||||||
AddPeer,
|
AddCollaborator,
|
||||||
BufferSaved,
|
BufferSaved,
|
||||||
CloseBuffer,
|
CloseBuffer,
|
||||||
CloseWorktree,
|
CloseWorktree,
|
||||||
OpenBuffer,
|
OpenBuffer,
|
||||||
JoinWorktree,
|
JoinWorktree,
|
||||||
RemovePeer,
|
RemoveCollaborator,
|
||||||
SaveBuffer,
|
SaveBuffer,
|
||||||
UnshareWorktree,
|
UnshareWorktree,
|
||||||
UpdateBuffer,
|
UpdateBuffer,
|
||||||
|
|
|
@ -112,14 +112,20 @@ impl Server {
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
addr: String,
|
addr: String,
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
|
mut send_connection_id: Option<postage::mpsc::Sender<ConnectionId>>,
|
||||||
) -> impl Future<Output = ()> {
|
) -> impl Future<Output = ()> {
|
||||||
let mut this = self.clone();
|
let mut this = self.clone();
|
||||||
async move {
|
async move {
|
||||||
let (connection_id, handle_io, mut incoming_rx) =
|
let (connection_id, handle_io, mut incoming_rx) =
|
||||||
this.peer.add_connection(connection).await;
|
this.peer.add_connection(connection).await;
|
||||||
|
|
||||||
|
if let Some(send_connection_id) = send_connection_id.as_mut() {
|
||||||
|
let _ = send_connection_id.send(connection_id).await;
|
||||||
|
}
|
||||||
|
|
||||||
this.state_mut().add_connection(connection_id, user_id);
|
this.state_mut().add_connection(connection_id, user_id);
|
||||||
if let Err(err) = this.update_collaborators_for_users(&[user_id]).await {
|
if let Err(err) = this.update_contacts_for_users(&[user_id]).await {
|
||||||
log::error!("error updating collaborators for {:?}: {}", user_id, err);
|
log::error!("error updating contacts for {:?}: {}", user_id, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
let handle_io = handle_io.fuse();
|
let handle_io = handle_io.fuse();
|
||||||
|
@ -173,7 +179,7 @@ impl Server {
|
||||||
if let Some(share) = worktree.share {
|
if let Some(share) = worktree.share {
|
||||||
broadcast(
|
broadcast(
|
||||||
connection_id,
|
connection_id,
|
||||||
share.guest_connection_ids.keys().copied().collect(),
|
share.guests.keys().copied().collect(),
|
||||||
|conn_id| {
|
|conn_id| {
|
||||||
self.peer
|
self.peer
|
||||||
.send(conn_id, proto::UnshareWorktree { worktree_id })
|
.send(conn_id, proto::UnshareWorktree { worktree_id })
|
||||||
|
@ -187,7 +193,7 @@ impl Server {
|
||||||
broadcast(connection_id, peer_ids, |conn_id| {
|
broadcast(connection_id, peer_ids, |conn_id| {
|
||||||
self.peer.send(
|
self.peer.send(
|
||||||
conn_id,
|
conn_id,
|
||||||
proto::RemovePeer {
|
proto::RemoveCollaborator {
|
||||||
worktree_id,
|
worktree_id,
|
||||||
peer_id: connection_id.0,
|
peer_id: connection_id.0,
|
||||||
},
|
},
|
||||||
|
@ -196,7 +202,7 @@ impl Server {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_collaborators_for_users(removed_connection.collaborator_ids.iter())
|
self.update_contacts_for_users(removed_connection.contact_ids.iter())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -214,12 +220,12 @@ impl Server {
|
||||||
let receipt = request.receipt();
|
let receipt = request.receipt();
|
||||||
let host_user_id = self.state().user_id_for_connection(request.sender_id)?;
|
let host_user_id = self.state().user_id_for_connection(request.sender_id)?;
|
||||||
|
|
||||||
let mut collaborator_user_ids = HashSet::new();
|
let mut contact_user_ids = HashSet::new();
|
||||||
collaborator_user_ids.insert(host_user_id);
|
contact_user_ids.insert(host_user_id);
|
||||||
for github_login in request.payload.collaborator_logins {
|
for github_login in request.payload.authorized_logins {
|
||||||
match self.app_state.db.create_user(&github_login, false).await {
|
match self.app_state.db.create_user(&github_login, false).await {
|
||||||
Ok(collaborator_user_id) => {
|
Ok(contact_user_id) => {
|
||||||
collaborator_user_ids.insert(collaborator_user_id);
|
contact_user_ids.insert(contact_user_id);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let message = err.to_string();
|
let message = err.to_string();
|
||||||
|
@ -231,10 +237,11 @@ impl Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let collaborator_user_ids = collaborator_user_ids.into_iter().collect::<Vec<_>>();
|
let contact_user_ids = contact_user_ids.into_iter().collect::<Vec<_>>();
|
||||||
let worktree_id = self.state_mut().add_worktree(Worktree {
|
let worktree_id = self.state_mut().add_worktree(Worktree {
|
||||||
host_connection_id: request.sender_id,
|
host_connection_id: request.sender_id,
|
||||||
collaborator_user_ids: collaborator_user_ids.clone(),
|
host_user_id,
|
||||||
|
authorized_user_ids: contact_user_ids.clone(),
|
||||||
root_name: request.payload.root_name,
|
root_name: request.payload.root_name,
|
||||||
share: None,
|
share: None,
|
||||||
});
|
});
|
||||||
|
@ -242,8 +249,7 @@ impl Server {
|
||||||
self.peer
|
self.peer
|
||||||
.respond(receipt, proto::OpenWorktreeResponse { worktree_id })
|
.respond(receipt, proto::OpenWorktreeResponse { worktree_id })
|
||||||
.await?;
|
.await?;
|
||||||
self.update_collaborators_for_users(&collaborator_user_ids)
|
self.update_contacts_for_users(&contact_user_ids).await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -260,7 +266,7 @@ impl Server {
|
||||||
if let Some(share) = worktree.share {
|
if let Some(share) = worktree.share {
|
||||||
broadcast(
|
broadcast(
|
||||||
request.sender_id,
|
request.sender_id,
|
||||||
share.guest_connection_ids.keys().copied().collect(),
|
share.guests.keys().copied().collect(),
|
||||||
|conn_id| {
|
|conn_id| {
|
||||||
self.peer
|
self.peer
|
||||||
.send(conn_id, proto::UnshareWorktree { worktree_id })
|
.send(conn_id, proto::UnshareWorktree { worktree_id })
|
||||||
|
@ -268,7 +274,7 @@ impl Server {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
self.update_collaborators_for_users(&worktree.collaborator_user_ids)
|
self.update_contacts_for_users(&worktree.authorized_user_ids)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -287,15 +293,14 @@ impl Server {
|
||||||
.map(|entry| (entry.id, entry))
|
.map(|entry| (entry.id, entry))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let collaborator_user_ids =
|
let contact_user_ids =
|
||||||
self.state_mut()
|
self.state_mut()
|
||||||
.share_worktree(worktree.id, request.sender_id, entries);
|
.share_worktree(worktree.id, request.sender_id, entries);
|
||||||
if let Some(collaborator_user_ids) = collaborator_user_ids {
|
if let Some(contact_user_ids) = contact_user_ids {
|
||||||
self.peer
|
self.peer
|
||||||
.respond(request.receipt(), proto::ShareWorktreeResponse {})
|
.respond(request.receipt(), proto::ShareWorktreeResponse {})
|
||||||
.await?;
|
.await?;
|
||||||
self.update_collaborators_for_users(&collaborator_user_ids)
|
self.update_contacts_for_users(&contact_user_ids).await?;
|
||||||
.await?;
|
|
||||||
} else {
|
} else {
|
||||||
self.peer
|
self.peer
|
||||||
.respond_with_error(
|
.respond_with_error(
|
||||||
|
@ -323,7 +328,7 @@ impl Server {
|
||||||
.send(conn_id, proto::UnshareWorktree { worktree_id })
|
.send(conn_id, proto::UnshareWorktree { worktree_id })
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
self.update_collaborators_for_users(&worktree.collaborator_ids)
|
self.update_contacts_for_users(&worktree.authorized_user_ids)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -341,17 +346,19 @@ impl Server {
|
||||||
.join_worktree(request.sender_id, user_id, worktree_id)
|
.join_worktree(request.sender_id, user_id, worktree_id)
|
||||||
.and_then(|joined| {
|
.and_then(|joined| {
|
||||||
let share = joined.worktree.share()?;
|
let share = joined.worktree.share()?;
|
||||||
let peer_count = share.guest_connection_ids.len();
|
let peer_count = share.guests.len();
|
||||||
let mut peers = Vec::with_capacity(peer_count);
|
let mut collaborators = Vec::with_capacity(peer_count);
|
||||||
peers.push(proto::Peer {
|
collaborators.push(proto::Collaborator {
|
||||||
peer_id: joined.worktree.host_connection_id.0,
|
peer_id: joined.worktree.host_connection_id.0,
|
||||||
replica_id: 0,
|
replica_id: 0,
|
||||||
|
user_id: joined.worktree.host_user_id.to_proto(),
|
||||||
});
|
});
|
||||||
for (peer_conn_id, peer_replica_id) in &share.guest_connection_ids {
|
for (peer_conn_id, (peer_replica_id, peer_user_id)) in &share.guests {
|
||||||
if *peer_conn_id != request.sender_id {
|
if *peer_conn_id != request.sender_id {
|
||||||
peers.push(proto::Peer {
|
collaborators.push(proto::Collaborator {
|
||||||
peer_id: peer_conn_id.0,
|
peer_id: peer_conn_id.0,
|
||||||
replica_id: *peer_replica_id as u32,
|
replica_id: *peer_replica_id as u32,
|
||||||
|
user_id: peer_user_id.to_proto(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,31 +369,31 @@ impl Server {
|
||||||
entries: share.entries.values().cloned().collect(),
|
entries: share.entries.values().cloned().collect(),
|
||||||
}),
|
}),
|
||||||
replica_id: joined.replica_id as u32,
|
replica_id: joined.replica_id as u32,
|
||||||
peers,
|
collaborators,
|
||||||
};
|
};
|
||||||
let connection_ids = joined.worktree.connection_ids();
|
let connection_ids = joined.worktree.connection_ids();
|
||||||
let collaborator_user_ids = joined.worktree.collaborator_user_ids.clone();
|
let contact_user_ids = joined.worktree.authorized_user_ids.clone();
|
||||||
Ok((response, connection_ids, collaborator_user_ids))
|
Ok((response, connection_ids, contact_user_ids))
|
||||||
});
|
});
|
||||||
|
|
||||||
match response_data {
|
match response_data {
|
||||||
Ok((response, connection_ids, collaborator_user_ids)) => {
|
Ok((response, connection_ids, contact_user_ids)) => {
|
||||||
broadcast(request.sender_id, connection_ids, |conn_id| {
|
broadcast(request.sender_id, connection_ids, |conn_id| {
|
||||||
self.peer.send(
|
self.peer.send(
|
||||||
conn_id,
|
conn_id,
|
||||||
proto::AddPeer {
|
proto::AddCollaborator {
|
||||||
worktree_id,
|
worktree_id,
|
||||||
peer: Some(proto::Peer {
|
collaborator: Some(proto::Collaborator {
|
||||||
peer_id: request.sender_id.0,
|
peer_id: request.sender_id.0,
|
||||||
replica_id: response.replica_id,
|
replica_id: response.replica_id,
|
||||||
|
user_id: user_id.to_proto(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
self.peer.respond(request.receipt(), response).await?;
|
self.peer.respond(request.receipt(), response).await?;
|
||||||
self.update_collaborators_for_users(&collaborator_user_ids)
|
self.update_contacts_for_users(&contact_user_ids).await?;
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
self.peer
|
self.peer
|
||||||
|
@ -414,14 +421,14 @@ impl Server {
|
||||||
broadcast(sender_id, worktree.connection_ids, |conn_id| {
|
broadcast(sender_id, worktree.connection_ids, |conn_id| {
|
||||||
self.peer.send(
|
self.peer.send(
|
||||||
conn_id,
|
conn_id,
|
||||||
proto::RemovePeer {
|
proto::RemoveCollaborator {
|
||||||
worktree_id,
|
worktree_id,
|
||||||
peer_id: sender_id.0,
|
peer_id: sender_id.0,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
self.update_collaborators_for_users(&worktree.collaborator_ids)
|
self.update_contacts_for_users(&worktree.authorized_user_ids)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -591,7 +598,7 @@ impl Server {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_collaborators_for_users<'a>(
|
async fn update_contacts_for_users<'a>(
|
||||||
self: &Arc<Server>,
|
self: &Arc<Server>,
|
||||||
user_ids: impl IntoIterator<Item = &'a UserId>,
|
user_ids: impl IntoIterator<Item = &'a UserId>,
|
||||||
) -> tide::Result<()> {
|
) -> tide::Result<()> {
|
||||||
|
@ -600,12 +607,12 @@ impl Server {
|
||||||
{
|
{
|
||||||
let state = self.state();
|
let state = self.state();
|
||||||
for user_id in user_ids {
|
for user_id in user_ids {
|
||||||
let collaborators = state.collaborators_for_user(*user_id);
|
let contacts = state.contacts_for_user(*user_id);
|
||||||
for connection_id in state.connection_ids_for_user(*user_id) {
|
for connection_id in state.connection_ids_for_user(*user_id) {
|
||||||
send_futures.push(self.peer.send(
|
send_futures.push(self.peer.send(
|
||||||
connection_id,
|
connection_id,
|
||||||
proto::UpdateCollaborators {
|
proto::UpdateContacts {
|
||||||
collaborators: collaborators.clone(),
|
contacts: contacts.clone(),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -886,6 +893,7 @@ pub fn add_routes(app: &mut tide::Server<Arc<AppState>>, rpc: &Arc<Peer>) {
|
||||||
),
|
),
|
||||||
addr,
|
addr,
|
||||||
user_id,
|
user_id,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
@ -924,9 +932,11 @@ mod tests {
|
||||||
use gpui::{ModelHandle, TestAppContext};
|
use gpui::{ModelHandle, TestAppContext};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use postage::{mpsc, watch};
|
use postage::{mpsc, watch};
|
||||||
|
use rpc::PeerId;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sqlx::types::time::OffsetDateTime;
|
use sqlx::types::time::OffsetDateTime;
|
||||||
use std::{
|
use std::{
|
||||||
|
ops::Deref,
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering::SeqCst},
|
atomic::{AtomicBool, Ordering::SeqCst},
|
||||||
|
@ -939,6 +949,7 @@ mod tests {
|
||||||
self, test::FakeHttpClient, Channel, ChannelDetails, ChannelList, Client, Credentials,
|
self, test::FakeHttpClient, Channel, ChannelDetails, ChannelList, Client, Credentials,
|
||||||
EstablishConnectionError, UserStore,
|
EstablishConnectionError, UserStore,
|
||||||
},
|
},
|
||||||
|
contacts_panel::JoinWorktree,
|
||||||
editor::{Editor, EditorSettings, Input},
|
editor::{Editor, EditorSettings, Input},
|
||||||
fs::{FakeFs, Fs as _},
|
fs::{FakeFs, Fs as _},
|
||||||
language::{
|
language::{
|
||||||
|
@ -946,7 +957,6 @@ mod tests {
|
||||||
LanguageServerConfig, Point,
|
LanguageServerConfig, Point,
|
||||||
},
|
},
|
||||||
lsp,
|
lsp,
|
||||||
people_panel::JoinWorktree,
|
|
||||||
project::{ProjectPath, Worktree},
|
project::{ProjectPath, Worktree},
|
||||||
test::test_app_state,
|
test::test_app_state,
|
||||||
workspace::Workspace,
|
workspace::Workspace,
|
||||||
|
@ -959,8 +969,8 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
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, _) = server.create_client(&mut cx_b, "user_b").await;
|
let client_b = server.create_client(&mut cx_b, "user_b").await;
|
||||||
|
|
||||||
cx_a.foreground().forbid_parking();
|
cx_a.foreground().forbid_parking();
|
||||||
|
|
||||||
|
@ -977,6 +987,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/a".as_ref(),
|
"/a".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -997,16 +1008,31 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let replica_id_b = worktree_b.read_with(&cx_b, |tree, _| tree.replica_id());
|
|
||||||
|
let replica_id_b = worktree_b.read_with(&cx_b, |tree, _| {
|
||||||
|
assert_eq!(
|
||||||
|
tree.collaborators()
|
||||||
|
.get(&client_a.peer_id)
|
||||||
|
.unwrap()
|
||||||
|
.user
|
||||||
|
.github_login,
|
||||||
|
"user_a"
|
||||||
|
);
|
||||||
|
tree.replica_id()
|
||||||
|
});
|
||||||
worktree_a
|
worktree_a
|
||||||
.condition(&cx_a, |tree, _| {
|
.condition(&cx_a, |tree, _| {
|
||||||
tree.peers()
|
tree.collaborators()
|
||||||
.values()
|
.get(&client_b.peer_id)
|
||||||
.any(|replica_id| *replica_id == replica_id_b)
|
.map_or(false, |collaborator| {
|
||||||
|
collaborator.replica_id == replica_id_b
|
||||||
|
&& collaborator.user.github_login == "user_b"
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -1050,27 +1076,27 @@ mod tests {
|
||||||
.condition(&cx_a, |tree, cx| !tree.has_open_buffer("b.txt", cx))
|
.condition(&cx_a, |tree, cx| !tree.has_open_buffer("b.txt", cx))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Dropping the worktree removes client B from client A's peers.
|
// Dropping the worktree removes client B from client A's collaborators.
|
||||||
cx_b.update(move |_| drop(worktree_b));
|
cx_b.update(move |_| drop(worktree_b));
|
||||||
worktree_a
|
worktree_a
|
||||||
.condition(&cx_a, |tree, _| tree.peers().is_empty())
|
.condition(&cx_a, |tree, _| tree.collaborators().is_empty())
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_unshare_worktree(mut cx_a: TestAppContext, mut cx_b: TestAppContext) {
|
async fn test_unshare_worktree(mut cx_a: TestAppContext, mut cx_b: TestAppContext) {
|
||||||
cx_b.update(zed::people_panel::init);
|
cx_b.update(zed::contacts_panel::init);
|
||||||
let mut app_state_a = cx_a.update(test_app_state);
|
let mut app_state_a = cx_a.update(test_app_state);
|
||||||
let mut app_state_b = cx_b.update(test_app_state);
|
let mut app_state_b = cx_b.update(test_app_state);
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
let (client_a, user_store_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 = server.create_client(&mut cx_b, "user_b").await;
|
||||||
Arc::get_mut(&mut app_state_a).unwrap().client = client_a;
|
Arc::get_mut(&mut app_state_a).unwrap().client = client_a.clone();
|
||||||
Arc::get_mut(&mut app_state_a).unwrap().user_store = user_store_a;
|
Arc::get_mut(&mut app_state_a).unwrap().user_store = client_a.user_store.clone();
|
||||||
Arc::get_mut(&mut app_state_b).unwrap().client = client_b;
|
Arc::get_mut(&mut app_state_b).unwrap().client = client_b.clone();
|
||||||
Arc::get_mut(&mut app_state_b).unwrap().user_store = user_store_b;
|
Arc::get_mut(&mut app_state_b).unwrap().user_store = client_b.user_store.clone();
|
||||||
|
|
||||||
cx_a.foreground().forbid_parking();
|
cx_a.foreground().forbid_parking();
|
||||||
|
|
||||||
|
@ -1087,6 +1113,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
app_state_a.client.clone(),
|
app_state_a.client.clone(),
|
||||||
|
app_state_a.user_store.clone(),
|
||||||
"/a".as_ref(),
|
"/a".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
app_state_a.languages.clone(),
|
app_state_a.languages.clone(),
|
||||||
|
@ -1161,9 +1188,9 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 3 clients.
|
// Connect to a server as 3 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
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, _) = server.create_client(&mut cx_b, "user_b").await;
|
let client_b = server.create_client(&mut cx_b, "user_b").await;
|
||||||
let (client_c, _) = server.create_client(&mut cx_c, "user_c").await;
|
let client_c = server.create_client(&mut cx_c, "user_c").await;
|
||||||
|
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
|
|
||||||
|
@ -1180,6 +1207,7 @@ mod tests {
|
||||||
|
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/a".as_ref(),
|
"/a".as_ref(),
|
||||||
fs.clone(),
|
fs.clone(),
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -1200,6 +1228,7 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -1208,6 +1237,7 @@ mod tests {
|
||||||
client_c.clone(),
|
client_c.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_c.user_store.clone(),
|
||||||
&mut cx_c.to_async(),
|
&mut cx_c.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -1300,8 +1330,8 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
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, _) = server.create_client(&mut cx_b, "user_b").await;
|
let client_b = server.create_client(&mut cx_b, "user_b").await;
|
||||||
|
|
||||||
// Share a local worktree as client A
|
// Share a local worktree as client A
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
|
@ -1316,6 +1346,7 @@ mod tests {
|
||||||
|
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/dir".as_ref(),
|
"/dir".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -1336,6 +1367,7 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -1385,8 +1417,8 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
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, _) = server.create_client(&mut cx_b, "user_b").await;
|
let client_b = server.create_client(&mut cx_b, "user_b").await;
|
||||||
|
|
||||||
// Share a local worktree as client A
|
// Share a local worktree as client A
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
|
@ -1400,6 +1432,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/dir".as_ref(),
|
"/dir".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -1420,6 +1453,7 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -1451,8 +1485,8 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
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, _) = server.create_client(&mut cx_b, "user_b").await;
|
let client_b = server.create_client(&mut cx_b, "user_b").await;
|
||||||
|
|
||||||
// Share a local worktree as client A
|
// Share a local worktree as client A
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
|
@ -1466,6 +1500,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/dir".as_ref(),
|
"/dir".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -1486,12 +1521,13 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
worktree_a
|
worktree_a
|
||||||
.condition(&cx_a, |tree, _| tree.peers().len() == 1)
|
.condition(&cx_a, |tree, _| tree.collaborators().len() == 1)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let buffer_b = cx_b
|
let buffer_b = cx_b
|
||||||
|
@ -1500,19 +1536,19 @@ mod tests {
|
||||||
cx_b.update(|_| drop(worktree_b));
|
cx_b.update(|_| drop(worktree_b));
|
||||||
drop(buffer_b);
|
drop(buffer_b);
|
||||||
worktree_a
|
worktree_a
|
||||||
.condition(&cx_a, |tree, _| tree.peers().len() == 0)
|
.condition(&cx_a, |tree, _| tree.collaborators().len() == 0)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_peer_disconnection(mut cx_a: TestAppContext, cx_b: TestAppContext) {
|
async fn test_peer_disconnection(mut cx_a: TestAppContext, mut cx_b: TestAppContext) {
|
||||||
cx_a.foreground().forbid_parking();
|
cx_a.foreground().forbid_parking();
|
||||||
let lang_registry = Arc::new(LanguageRegistry::new());
|
let lang_registry = Arc::new(LanguageRegistry::new());
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
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, _) = server.create_client(&mut cx_a, "user_b").await;
|
let client_b = server.create_client(&mut cx_b, "user_b").await;
|
||||||
|
|
||||||
// Share a local worktree as client A
|
// Share a local worktree as client A
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
|
@ -1527,6 +1563,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/a".as_ref(),
|
"/a".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -1547,18 +1584,19 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
worktree_a
|
worktree_a
|
||||||
.condition(&cx_a, |tree, _| tree.peers().len() == 1)
|
.condition(&cx_a, |tree, _| tree.collaborators().len() == 1)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Drop client B's connection and ensure client A observes client B leaving the worktree.
|
// Drop client B's connection and ensure client A observes client B leaving the worktree.
|
||||||
client_b.disconnect(&cx_b.to_async()).await.unwrap();
|
client_b.disconnect(&cx_b.to_async()).await.unwrap();
|
||||||
worktree_a
|
worktree_a
|
||||||
.condition(&cx_a, |tree, _| tree.peers().len() == 0)
|
.condition(&cx_a, |tree, _| tree.collaborators().len() == 0)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1585,8 +1623,8 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
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, _) = server.create_client(&mut cx_a, "user_b").await;
|
let client_b = server.create_client(&mut cx_b, "user_b").await;
|
||||||
|
|
||||||
// Share a local worktree as client A
|
// Share a local worktree as client A
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
|
@ -1601,6 +1639,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/a".as_ref(),
|
"/a".as_ref(),
|
||||||
fs,
|
fs,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -1655,6 +1694,7 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -1702,30 +1742,30 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
let (client_a, user_store_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 = server.create_client(&mut cx_b, "user_b").await;
|
||||||
|
|
||||||
// Create an org that includes these 2 users.
|
// Create an org that includes these 2 users.
|
||||||
let db = &server.app_state.db;
|
let db = &server.app_state.db;
|
||||||
let org_id = db.create_org("Test Org", "test-org").await.unwrap();
|
let org_id = db.create_org("Test Org", "test-org").await.unwrap();
|
||||||
db.add_org_member(org_id, current_user_id(&user_store_a, &cx_a), false)
|
db.add_org_member(org_id, client_a.current_user_id(&cx_a), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.add_org_member(org_id, current_user_id(&user_store_b, &cx_b), false)
|
db.add_org_member(org_id, client_b.current_user_id(&cx_b), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a channel that includes all the users.
|
// Create a channel that includes all the users.
|
||||||
let channel_id = db.create_org_channel(org_id, "test-channel").await.unwrap();
|
let channel_id = db.create_org_channel(org_id, "test-channel").await.unwrap();
|
||||||
db.add_channel_member(channel_id, current_user_id(&user_store_a, &cx_a), false)
|
db.add_channel_member(channel_id, client_a.current_user_id(&cx_a), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.add_channel_member(channel_id, current_user_id(&user_store_b, &cx_b), false)
|
db.add_channel_member(channel_id, client_b.current_user_id(&cx_b), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.create_channel_message(
|
db.create_channel_message(
|
||||||
channel_id,
|
channel_id,
|
||||||
current_user_id(&user_store_b, &cx_b),
|
client_b.current_user_id(&cx_b),
|
||||||
"hello A, it's B.",
|
"hello A, it's B.",
|
||||||
OffsetDateTime::now_utc(),
|
OffsetDateTime::now_utc(),
|
||||||
1,
|
1,
|
||||||
|
@ -1733,7 +1773,8 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let channels_a = cx_a.add_model(|cx| ChannelList::new(user_store_a, client_a, cx));
|
let channels_a = cx_a
|
||||||
|
.add_model(|cx| ChannelList::new(client_a.user_store.clone(), client_a.clone(), cx));
|
||||||
channels_a
|
channels_a
|
||||||
.condition(&mut cx_a, |list, _| list.available_channels().is_some())
|
.condition(&mut cx_a, |list, _| list.available_channels().is_some())
|
||||||
.await;
|
.await;
|
||||||
|
@ -1757,7 +1798,8 @@ mod tests {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let channels_b = cx_b.add_model(|cx| ChannelList::new(user_store_b, client_b, cx));
|
let channels_b = cx_b
|
||||||
|
.add_model(|cx| ChannelList::new(client_b.user_store.clone(), client_b.clone(), cx));
|
||||||
channels_b
|
channels_b
|
||||||
.condition(&mut cx_b, |list, _| list.available_channels().is_some())
|
.condition(&mut cx_b, |list, _| list.available_channels().is_some())
|
||||||
.await;
|
.await;
|
||||||
|
@ -1839,19 +1881,20 @@ mod tests {
|
||||||
cx_a.foreground().forbid_parking();
|
cx_a.foreground().forbid_parking();
|
||||||
|
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
let (client_a, user_store_a) = server.create_client(&mut cx_a, "user_a").await;
|
let client_a = server.create_client(&mut cx_a, "user_a").await;
|
||||||
|
|
||||||
let db = &server.app_state.db;
|
let db = &server.app_state.db;
|
||||||
let org_id = db.create_org("Test Org", "test-org").await.unwrap();
|
let org_id = db.create_org("Test Org", "test-org").await.unwrap();
|
||||||
let channel_id = db.create_org_channel(org_id, "test-channel").await.unwrap();
|
let channel_id = db.create_org_channel(org_id, "test-channel").await.unwrap();
|
||||||
db.add_org_member(org_id, current_user_id(&user_store_a, &cx_a), false)
|
db.add_org_member(org_id, client_a.current_user_id(&cx_a), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.add_channel_member(channel_id, current_user_id(&user_store_a, &cx_a), false)
|
db.add_channel_member(channel_id, client_a.current_user_id(&cx_a), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let channels_a = cx_a.add_model(|cx| ChannelList::new(user_store_a, client_a, cx));
|
let channels_a = cx_a
|
||||||
|
.add_model(|cx| ChannelList::new(client_a.user_store.clone(), client_a.clone(), cx));
|
||||||
channels_a
|
channels_a
|
||||||
.condition(&mut cx_a, |list, _| list.available_channels().is_some())
|
.condition(&mut cx_a, |list, _| list.available_channels().is_some())
|
||||||
.await;
|
.await;
|
||||||
|
@ -1899,31 +1942,31 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 2 clients.
|
// Connect to a server as 2 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
let (client_a, user_store_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 = server.create_client(&mut cx_b, "user_b").await;
|
||||||
let mut status_b = client_b.status();
|
let mut status_b = client_b.status();
|
||||||
|
|
||||||
// Create an org that includes these 2 users.
|
// Create an org that includes these 2 users.
|
||||||
let db = &server.app_state.db;
|
let db = &server.app_state.db;
|
||||||
let org_id = db.create_org("Test Org", "test-org").await.unwrap();
|
let org_id = db.create_org("Test Org", "test-org").await.unwrap();
|
||||||
db.add_org_member(org_id, current_user_id(&user_store_a, &cx_a), false)
|
db.add_org_member(org_id, client_a.current_user_id(&cx_a), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.add_org_member(org_id, current_user_id(&user_store_b, &cx_b), false)
|
db.add_org_member(org_id, client_b.current_user_id(&cx_b), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a channel that includes all the users.
|
// Create a channel that includes all the users.
|
||||||
let channel_id = db.create_org_channel(org_id, "test-channel").await.unwrap();
|
let channel_id = db.create_org_channel(org_id, "test-channel").await.unwrap();
|
||||||
db.add_channel_member(channel_id, current_user_id(&user_store_a, &cx_a), false)
|
db.add_channel_member(channel_id, client_a.current_user_id(&cx_a), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.add_channel_member(channel_id, current_user_id(&user_store_b, &cx_b), false)
|
db.add_channel_member(channel_id, client_b.current_user_id(&cx_b), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.create_channel_message(
|
db.create_channel_message(
|
||||||
channel_id,
|
channel_id,
|
||||||
current_user_id(&user_store_b, &cx_b),
|
client_b.current_user_id(&cx_b),
|
||||||
"hello A, it's B.",
|
"hello A, it's B.",
|
||||||
OffsetDateTime::now_utc(),
|
OffsetDateTime::now_utc(),
|
||||||
2,
|
2,
|
||||||
|
@ -1931,7 +1974,8 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let channels_a = cx_a.add_model(|cx| ChannelList::new(user_store_a, client_a, cx));
|
let channels_a = cx_a
|
||||||
|
.add_model(|cx| ChannelList::new(client_a.user_store.clone(), client_a.clone(), cx));
|
||||||
channels_a
|
channels_a
|
||||||
.condition(&mut cx_a, |list, _| list.available_channels().is_some())
|
.condition(&mut cx_a, |list, _| list.available_channels().is_some())
|
||||||
.await;
|
.await;
|
||||||
|
@ -1956,7 +2000,8 @@ mod tests {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let channels_b = cx_b.add_model(|cx| ChannelList::new(user_store_b.clone(), client_b, cx));
|
let channels_b = cx_b
|
||||||
|
.add_model(|cx| ChannelList::new(client_b.user_store.clone(), client_b.clone(), cx));
|
||||||
channels_b
|
channels_b
|
||||||
.condition(&mut cx_b, |list, _| list.available_channels().is_some())
|
.condition(&mut cx_b, |list, _| list.available_channels().is_some())
|
||||||
.await;
|
.await;
|
||||||
|
@ -1983,7 +2028,7 @@ mod tests {
|
||||||
|
|
||||||
// Disconnect client B, ensuring we can still access its cached channel data.
|
// Disconnect client B, ensuring we can still access its cached channel data.
|
||||||
server.forbid_connections();
|
server.forbid_connections();
|
||||||
server.disconnect_client(current_user_id(&user_store_b, &cx_b));
|
server.disconnect_client(client_b.current_user_id(&cx_b));
|
||||||
while !matches!(
|
while !matches!(
|
||||||
status_b.recv().await,
|
status_b.recv().await,
|
||||||
Some(client::Status::ReconnectionError { .. })
|
Some(client::Status::ReconnectionError { .. })
|
||||||
|
@ -2104,7 +2149,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_collaborators(
|
async fn test_contacts(
|
||||||
mut cx_a: TestAppContext,
|
mut cx_a: TestAppContext,
|
||||||
mut cx_b: TestAppContext,
|
mut cx_b: TestAppContext,
|
||||||
mut cx_c: TestAppContext,
|
mut cx_c: TestAppContext,
|
||||||
|
@ -2114,9 +2159,9 @@ mod tests {
|
||||||
|
|
||||||
// Connect to a server as 3 clients.
|
// Connect to a server as 3 clients.
|
||||||
let mut server = TestServer::start().await;
|
let mut server = TestServer::start().await;
|
||||||
let (client_a, user_store_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 = server.create_client(&mut cx_b, "user_b").await;
|
||||||
let (_client_c, user_store_c) = server.create_client(&mut cx_c, "user_c").await;
|
let client_c = server.create_client(&mut cx_c, "user_c").await;
|
||||||
|
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
|
|
||||||
|
@ -2131,6 +2176,7 @@ mod tests {
|
||||||
|
|
||||||
let worktree_a = Worktree::open_local(
|
let worktree_a = Worktree::open_local(
|
||||||
client_a.clone(),
|
client_a.clone(),
|
||||||
|
client_a.user_store.clone(),
|
||||||
"/a".as_ref(),
|
"/a".as_ref(),
|
||||||
fs.clone(),
|
fs.clone(),
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
@ -2139,19 +2185,22 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
user_store_a
|
client_a
|
||||||
|
.user_store
|
||||||
.condition(&cx_a, |user_store, _| {
|
.condition(&cx_a, |user_store, _| {
|
||||||
collaborators(user_store) == vec![("user_a", vec![("a", vec![])])]
|
contacts(user_store) == vec![("user_a", vec![("a", vec![])])]
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
user_store_b
|
client_b
|
||||||
|
.user_store
|
||||||
.condition(&cx_b, |user_store, _| {
|
.condition(&cx_b, |user_store, _| {
|
||||||
collaborators(user_store) == vec![("user_a", vec![("a", vec![])])]
|
contacts(user_store) == vec![("user_a", vec![("a", vec![])])]
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
user_store_c
|
client_c
|
||||||
|
.user_store
|
||||||
.condition(&cx_c, |user_store, _| {
|
.condition(&cx_c, |user_store, _| {
|
||||||
collaborators(user_store) == vec![("user_a", vec![("a", vec![])])]
|
contacts(user_store) == vec![("user_a", vec![("a", vec![])])]
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -2164,44 +2213,51 @@ mod tests {
|
||||||
client_b.clone(),
|
client_b.clone(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
lang_registry.clone(),
|
lang_registry.clone(),
|
||||||
|
client_b.user_store.clone(),
|
||||||
&mut cx_b.to_async(),
|
&mut cx_b.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
user_store_a
|
client_a
|
||||||
|
.user_store
|
||||||
.condition(&cx_a, |user_store, _| {
|
.condition(&cx_a, |user_store, _| {
|
||||||
collaborators(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
|
contacts(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
user_store_b
|
client_b
|
||||||
|
.user_store
|
||||||
.condition(&cx_b, |user_store, _| {
|
.condition(&cx_b, |user_store, _| {
|
||||||
collaborators(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
|
contacts(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
user_store_c
|
client_c
|
||||||
|
.user_store
|
||||||
.condition(&cx_c, |user_store, _| {
|
.condition(&cx_c, |user_store, _| {
|
||||||
collaborators(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
|
contacts(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
cx_a.update(move |_| drop(worktree_a));
|
cx_a.update(move |_| drop(worktree_a));
|
||||||
user_store_a
|
client_a
|
||||||
.condition(&cx_a, |user_store, _| collaborators(user_store) == vec![])
|
.user_store
|
||||||
|
.condition(&cx_a, |user_store, _| contacts(user_store) == vec![])
|
||||||
.await;
|
.await;
|
||||||
user_store_b
|
client_b
|
||||||
.condition(&cx_b, |user_store, _| collaborators(user_store) == vec![])
|
.user_store
|
||||||
|
.condition(&cx_b, |user_store, _| contacts(user_store) == vec![])
|
||||||
.await;
|
.await;
|
||||||
user_store_c
|
client_c
|
||||||
.condition(&cx_c, |user_store, _| collaborators(user_store) == vec![])
|
.user_store
|
||||||
|
.condition(&cx_c, |user_store, _| contacts(user_store) == vec![])
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
fn collaborators(user_store: &UserStore) -> Vec<(&str, Vec<(&str, Vec<&str>)>)> {
|
fn contacts(user_store: &UserStore) -> Vec<(&str, Vec<(&str, Vec<&str>)>)> {
|
||||||
user_store
|
user_store
|
||||||
.collaborators()
|
.contacts()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|collaborator| {
|
.map(|contact| {
|
||||||
let worktrees = collaborator
|
let worktrees = contact
|
||||||
.worktrees
|
.worktrees
|
||||||
.iter()
|
.iter()
|
||||||
.map(|w| {
|
.map(|w| {
|
||||||
|
@ -2211,7 +2267,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
(collaborator.user.github_login.as_str(), worktrees)
|
(contact.user.github_login.as_str(), worktrees)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -2245,17 +2301,15 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_client(
|
async fn create_client(&mut self, cx: &mut TestAppContext, name: &str) -> TestClient {
|
||||||
&mut self,
|
|
||||||
cx: &mut TestAppContext,
|
|
||||||
name: &str,
|
|
||||||
) -> (Arc<Client>, ModelHandle<UserStore>) {
|
|
||||||
let user_id = self.app_state.db.create_user(name, false).await.unwrap();
|
let user_id = self.app_state.db.create_user(name, false).await.unwrap();
|
||||||
let client_name = name.to_string();
|
let client_name = name.to_string();
|
||||||
let mut client = Client::new();
|
let mut client = Client::new();
|
||||||
let server = self.server.clone();
|
let server = self.server.clone();
|
||||||
let connection_killers = self.connection_killers.clone();
|
let connection_killers = self.connection_killers.clone();
|
||||||
let forbid_connections = self.forbid_connections.clone();
|
let forbid_connections = self.forbid_connections.clone();
|
||||||
|
let (connection_id_tx, mut connection_id_rx) = postage::mpsc::channel(16);
|
||||||
|
|
||||||
Arc::get_mut(&mut client)
|
Arc::get_mut(&mut client)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.override_authenticate(move |cx| {
|
.override_authenticate(move |cx| {
|
||||||
|
@ -2275,6 +2329,7 @@ mod tests {
|
||||||
let connection_killers = connection_killers.clone();
|
let connection_killers = connection_killers.clone();
|
||||||
let forbid_connections = forbid_connections.clone();
|
let forbid_connections = forbid_connections.clone();
|
||||||
let client_name = client_name.clone();
|
let client_name = client_name.clone();
|
||||||
|
let connection_id_tx = connection_id_tx.clone();
|
||||||
cx.spawn(move |cx| async move {
|
cx.spawn(move |cx| async move {
|
||||||
if forbid_connections.load(SeqCst) {
|
if forbid_connections.load(SeqCst) {
|
||||||
Err(EstablishConnectionError::other(anyhow!(
|
Err(EstablishConnectionError::other(anyhow!(
|
||||||
|
@ -2284,7 +2339,12 @@ mod tests {
|
||||||
let (client_conn, server_conn, kill_conn) = Connection::in_memory();
|
let (client_conn, server_conn, kill_conn) = Connection::in_memory();
|
||||||
connection_killers.lock().insert(user_id, kill_conn);
|
connection_killers.lock().insert(user_id, kill_conn);
|
||||||
cx.background()
|
cx.background()
|
||||||
.spawn(server.handle_connection(server_conn, client_name, user_id))
|
.spawn(server.handle_connection(
|
||||||
|
server_conn,
|
||||||
|
client_name,
|
||||||
|
user_id,
|
||||||
|
Some(connection_id_tx),
|
||||||
|
))
|
||||||
.detach();
|
.detach();
|
||||||
Ok(client_conn)
|
Ok(client_conn)
|
||||||
}
|
}
|
||||||
|
@ -2297,12 +2357,17 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let peer_id = PeerId(connection_id_rx.recv().await.unwrap().0);
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx));
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx));
|
||||||
let mut authed_user =
|
let mut authed_user =
|
||||||
user_store.read_with(cx, |user_store, _| user_store.watch_current_user());
|
user_store.read_with(cx, |user_store, _| user_store.watch_current_user());
|
||||||
while authed_user.recv().await.unwrap().is_none() {}
|
while authed_user.recv().await.unwrap().is_none() {}
|
||||||
|
|
||||||
(client, user_store)
|
TestClient {
|
||||||
|
client,
|
||||||
|
peer_id,
|
||||||
|
user_store,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disconnect_client(&self, user_id: UserId) {
|
fn disconnect_client(&self, user_id: UserId) {
|
||||||
|
@ -2358,10 +2423,27 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_user_id(user_store: &ModelHandle<UserStore>, cx: &TestAppContext) -> UserId {
|
struct TestClient {
|
||||||
UserId::from_proto(
|
client: Arc<Client>,
|
||||||
user_store.read_with(cx, |user_store, _| user_store.current_user().unwrap().id),
|
pub peer_id: PeerId,
|
||||||
)
|
pub user_store: ModelHandle<UserStore>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for TestClient {
|
||||||
|
type Target = Arc<Client>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.client
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestClient {
|
||||||
|
pub fn current_user_id(&self, cx: &TestAppContext) -> UserId {
|
||||||
|
UserId::from_proto(
|
||||||
|
self.user_store
|
||||||
|
.read_with(cx, |user_store, _| user_store.current_user().unwrap().id),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn channel_messages(channel: &Channel) -> Vec<(String, String, bool)> {
|
fn channel_messages(channel: &Channel) -> Vec<(String, String, bool)> {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::db::{ChannelId, UserId};
|
use crate::db::{ChannelId, UserId};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use std::collections::{hash_map, HashMap, HashSet};
|
|
||||||
use rpc::{proto, ConnectionId};
|
use rpc::{proto, ConnectionId};
|
||||||
|
use std::collections::{hash_map, HashMap, HashSet};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
|
@ -21,13 +21,14 @@ struct ConnectionState {
|
||||||
|
|
||||||
pub struct Worktree {
|
pub struct Worktree {
|
||||||
pub host_connection_id: ConnectionId,
|
pub host_connection_id: ConnectionId,
|
||||||
pub collaborator_user_ids: Vec<UserId>,
|
pub host_user_id: UserId,
|
||||||
|
pub authorized_user_ids: Vec<UserId>,
|
||||||
pub root_name: String,
|
pub root_name: String,
|
||||||
pub share: Option<WorktreeShare>,
|
pub share: Option<WorktreeShare>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WorktreeShare {
|
pub struct WorktreeShare {
|
||||||
pub guest_connection_ids: HashMap<ConnectionId, ReplicaId>,
|
pub guests: HashMap<ConnectionId, (ReplicaId, UserId)>,
|
||||||
pub active_replica_ids: HashSet<ReplicaId>,
|
pub active_replica_ids: HashSet<ReplicaId>,
|
||||||
pub entries: HashMap<u64, proto::Entry>,
|
pub entries: HashMap<u64, proto::Entry>,
|
||||||
}
|
}
|
||||||
|
@ -43,7 +44,7 @@ pub type ReplicaId = u16;
|
||||||
pub struct RemovedConnectionState {
|
pub struct RemovedConnectionState {
|
||||||
pub hosted_worktrees: HashMap<u64, Worktree>,
|
pub hosted_worktrees: HashMap<u64, Worktree>,
|
||||||
pub guest_worktree_ids: HashMap<u64, Vec<ConnectionId>>,
|
pub guest_worktree_ids: HashMap<u64, Vec<ConnectionId>>,
|
||||||
pub collaborator_ids: HashSet<UserId>,
|
pub contact_ids: HashSet<UserId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct JoinedWorktree<'a> {
|
pub struct JoinedWorktree<'a> {
|
||||||
|
@ -53,12 +54,12 @@ pub struct JoinedWorktree<'a> {
|
||||||
|
|
||||||
pub struct UnsharedWorktree {
|
pub struct UnsharedWorktree {
|
||||||
pub connection_ids: Vec<ConnectionId>,
|
pub connection_ids: Vec<ConnectionId>,
|
||||||
pub collaborator_ids: Vec<UserId>,
|
pub authorized_user_ids: Vec<UserId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LeftWorktree {
|
pub struct LeftWorktree {
|
||||||
pub connection_ids: Vec<ConnectionId>,
|
pub connection_ids: Vec<ConnectionId>,
|
||||||
pub collaborator_ids: Vec<UserId>,
|
pub authorized_user_ids: Vec<UserId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Store {
|
impl Store {
|
||||||
|
@ -106,14 +107,14 @@ impl Store {
|
||||||
for worktree_id in connection.worktrees.clone() {
|
for worktree_id in connection.worktrees.clone() {
|
||||||
if let Ok(worktree) = self.remove_worktree(worktree_id, connection_id) {
|
if let Ok(worktree) = self.remove_worktree(worktree_id, connection_id) {
|
||||||
result
|
result
|
||||||
.collaborator_ids
|
.contact_ids
|
||||||
.extend(worktree.collaborator_user_ids.iter().copied());
|
.extend(worktree.authorized_user_ids.iter().copied());
|
||||||
result.hosted_worktrees.insert(worktree_id, worktree);
|
result.hosted_worktrees.insert(worktree_id, worktree);
|
||||||
} else if let Some(worktree) = self.leave_worktree(connection_id, worktree_id) {
|
} else if let Some(worktree) = self.leave_worktree(connection_id, worktree_id) {
|
||||||
result
|
result
|
||||||
.guest_worktree_ids
|
.guest_worktree_ids
|
||||||
.insert(worktree_id, worktree.connection_ids);
|
.insert(worktree_id, worktree.connection_ids);
|
||||||
result.collaborator_ids.extend(worktree.collaborator_ids);
|
result.contact_ids.extend(worktree.authorized_user_ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,8 +171,8 @@ impl Store {
|
||||||
.copied()
|
.copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collaborators_for_user(&self, user_id: UserId) -> Vec<proto::Collaborator> {
|
pub fn contacts_for_user(&self, user_id: UserId) -> Vec<proto::Contact> {
|
||||||
let mut collaborators = HashMap::new();
|
let mut contacts = HashMap::new();
|
||||||
for worktree_id in self
|
for worktree_id in self
|
||||||
.visible_worktrees_by_user_id
|
.visible_worktrees_by_user_id
|
||||||
.get(&user_id)
|
.get(&user_id)
|
||||||
|
@ -181,7 +182,7 @@ impl Store {
|
||||||
|
|
||||||
let mut guests = HashSet::new();
|
let mut guests = HashSet::new();
|
||||||
if let Ok(share) = worktree.share() {
|
if let Ok(share) = worktree.share() {
|
||||||
for guest_connection_id in share.guest_connection_ids.keys() {
|
for guest_connection_id in share.guests.keys() {
|
||||||
if let Ok(user_id) = self.user_id_for_connection(*guest_connection_id) {
|
if let Ok(user_id) = self.user_id_for_connection(*guest_connection_id) {
|
||||||
guests.insert(user_id.to_proto());
|
guests.insert(user_id.to_proto());
|
||||||
}
|
}
|
||||||
|
@ -189,9 +190,9 @@ impl Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(host_user_id) = self.user_id_for_connection(worktree.host_connection_id) {
|
if let Ok(host_user_id) = self.user_id_for_connection(worktree.host_connection_id) {
|
||||||
collaborators
|
contacts
|
||||||
.entry(host_user_id)
|
.entry(host_user_id)
|
||||||
.or_insert_with(|| proto::Collaborator {
|
.or_insert_with(|| proto::Contact {
|
||||||
user_id: host_user_id.to_proto(),
|
user_id: host_user_id.to_proto(),
|
||||||
worktrees: Vec::new(),
|
worktrees: Vec::new(),
|
||||||
})
|
})
|
||||||
|
@ -205,14 +206,14 @@ impl Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collaborators.into_values().collect()
|
contacts.into_values().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_worktree(&mut self, worktree: Worktree) -> u64 {
|
pub fn add_worktree(&mut self, worktree: Worktree) -> u64 {
|
||||||
let worktree_id = self.next_worktree_id;
|
let worktree_id = self.next_worktree_id;
|
||||||
for collaborator_user_id in &worktree.collaborator_user_ids {
|
for authorized_user_id in &worktree.authorized_user_ids {
|
||||||
self.visible_worktrees_by_user_id
|
self.visible_worktrees_by_user_id
|
||||||
.entry(*collaborator_user_id)
|
.entry(*authorized_user_id)
|
||||||
.or_default()
|
.or_default()
|
||||||
.insert(worktree_id);
|
.insert(worktree_id);
|
||||||
}
|
}
|
||||||
|
@ -247,17 +248,17 @@ impl Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(share) = &worktree.share {
|
if let Some(share) = &worktree.share {
|
||||||
for connection_id in share.guest_connection_ids.keys() {
|
for connection_id in share.guests.keys() {
|
||||||
if let Some(connection) = self.connections.get_mut(connection_id) {
|
if let Some(connection) = self.connections.get_mut(connection_id) {
|
||||||
connection.worktrees.remove(&worktree_id);
|
connection.worktrees.remove(&worktree_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for collaborator_user_id in &worktree.collaborator_user_ids {
|
for authorized_user_id in &worktree.authorized_user_ids {
|
||||||
if let Some(visible_worktrees) = self
|
if let Some(visible_worktrees) = self
|
||||||
.visible_worktrees_by_user_id
|
.visible_worktrees_by_user_id
|
||||||
.get_mut(&collaborator_user_id)
|
.get_mut(&authorized_user_id)
|
||||||
{
|
{
|
||||||
visible_worktrees.remove(&worktree_id);
|
visible_worktrees.remove(&worktree_id);
|
||||||
}
|
}
|
||||||
|
@ -278,11 +279,11 @@ impl Store {
|
||||||
if let Some(worktree) = self.worktrees.get_mut(&worktree_id) {
|
if let Some(worktree) = self.worktrees.get_mut(&worktree_id) {
|
||||||
if worktree.host_connection_id == connection_id {
|
if worktree.host_connection_id == connection_id {
|
||||||
worktree.share = Some(WorktreeShare {
|
worktree.share = Some(WorktreeShare {
|
||||||
guest_connection_ids: Default::default(),
|
guests: Default::default(),
|
||||||
active_replica_ids: Default::default(),
|
active_replica_ids: Default::default(),
|
||||||
entries,
|
entries,
|
||||||
});
|
});
|
||||||
return Some(worktree.collaborator_user_ids.clone());
|
return Some(worktree.authorized_user_ids.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
@ -304,9 +305,9 @@ impl Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
let connection_ids = worktree.connection_ids();
|
let connection_ids = worktree.connection_ids();
|
||||||
let collaborator_ids = worktree.collaborator_user_ids.clone();
|
let authorized_user_ids = worktree.authorized_user_ids.clone();
|
||||||
if let Some(share) = worktree.share.take() {
|
if let Some(share) = worktree.share.take() {
|
||||||
for connection_id in share.guest_connection_ids.into_keys() {
|
for connection_id in share.guests.into_keys() {
|
||||||
if let Some(connection) = self.connections.get_mut(&connection_id) {
|
if let Some(connection) = self.connections.get_mut(&connection_id) {
|
||||||
connection.worktrees.remove(&worktree_id);
|
connection.worktrees.remove(&worktree_id);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +318,7 @@ impl Store {
|
||||||
|
|
||||||
Ok(UnsharedWorktree {
|
Ok(UnsharedWorktree {
|
||||||
connection_ids,
|
connection_ids,
|
||||||
collaborator_ids,
|
authorized_user_ids,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("worktree is not shared"))?
|
Err(anyhow!("worktree is not shared"))?
|
||||||
|
@ -338,7 +339,7 @@ impl Store {
|
||||||
.worktrees
|
.worktrees
|
||||||
.get_mut(&worktree_id)
|
.get_mut(&worktree_id)
|
||||||
.and_then(|worktree| {
|
.and_then(|worktree| {
|
||||||
if worktree.collaborator_user_ids.contains(&user_id) {
|
if worktree.authorized_user_ids.contains(&user_id) {
|
||||||
Some(worktree)
|
Some(worktree)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -354,7 +355,7 @@ impl Store {
|
||||||
replica_id += 1;
|
replica_id += 1;
|
||||||
}
|
}
|
||||||
share.active_replica_ids.insert(replica_id);
|
share.active_replica_ids.insert(replica_id);
|
||||||
share.guest_connection_ids.insert(connection_id, replica_id);
|
share.guests.insert(connection_id, (replica_id, user_id));
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
self.check_invariants();
|
self.check_invariants();
|
||||||
|
@ -372,7 +373,7 @@ impl Store {
|
||||||
) -> Option<LeftWorktree> {
|
) -> Option<LeftWorktree> {
|
||||||
let worktree = self.worktrees.get_mut(&worktree_id)?;
|
let worktree = self.worktrees.get_mut(&worktree_id)?;
|
||||||
let share = worktree.share.as_mut()?;
|
let share = worktree.share.as_mut()?;
|
||||||
let replica_id = share.guest_connection_ids.remove(&connection_id)?;
|
let (replica_id, _) = share.guests.remove(&connection_id)?;
|
||||||
share.active_replica_ids.remove(&replica_id);
|
share.active_replica_ids.remove(&replica_id);
|
||||||
|
|
||||||
if let Some(connection) = self.connections.get_mut(&connection_id) {
|
if let Some(connection) = self.connections.get_mut(&connection_id) {
|
||||||
|
@ -380,14 +381,14 @@ impl Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
let connection_ids = worktree.connection_ids();
|
let connection_ids = worktree.connection_ids();
|
||||||
let collaborator_ids = worktree.collaborator_user_ids.clone();
|
let authorized_user_ids = worktree.authorized_user_ids.clone();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
self.check_invariants();
|
self.check_invariants();
|
||||||
|
|
||||||
Some(LeftWorktree {
|
Some(LeftWorktree {
|
||||||
connection_ids,
|
connection_ids,
|
||||||
collaborator_ids,
|
authorized_user_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +428,7 @@ impl Store {
|
||||||
Ok(self
|
Ok(self
|
||||||
.read_worktree(worktree_id, connection_id)?
|
.read_worktree(worktree_id, connection_id)?
|
||||||
.share()?
|
.share()?
|
||||||
.guest_connection_ids
|
.guests
|
||||||
.keys()
|
.keys()
|
||||||
.copied()
|
.copied()
|
||||||
.collect())
|
.collect())
|
||||||
|
@ -458,10 +459,7 @@ impl Store {
|
||||||
.ok_or_else(|| anyhow!("worktree not found"))?;
|
.ok_or_else(|| anyhow!("worktree not found"))?;
|
||||||
|
|
||||||
if worktree.host_connection_id == connection_id
|
if worktree.host_connection_id == connection_id
|
||||||
|| worktree
|
|| worktree.share()?.guests.contains_key(&connection_id)
|
||||||
.share()?
|
|
||||||
.guest_connection_ids
|
|
||||||
.contains_key(&connection_id)
|
|
||||||
{
|
{
|
||||||
Ok(worktree)
|
Ok(worktree)
|
||||||
} else {
|
} else {
|
||||||
|
@ -484,9 +482,10 @@ impl Store {
|
||||||
.ok_or_else(|| anyhow!("worktree not found"))?;
|
.ok_or_else(|| anyhow!("worktree not found"))?;
|
||||||
|
|
||||||
if worktree.host_connection_id == connection_id
|
if worktree.host_connection_id == connection_id
|
||||||
|| worktree.share.as_ref().map_or(false, |share| {
|
|| worktree
|
||||||
share.guest_connection_ids.contains_key(&connection_id)
|
.share
|
||||||
})
|
.as_ref()
|
||||||
|
.map_or(false, |share| share.guests.contains_key(&connection_id))
|
||||||
{
|
{
|
||||||
Ok(worktree)
|
Ok(worktree)
|
||||||
} else {
|
} else {
|
||||||
|
@ -504,11 +503,7 @@ impl Store {
|
||||||
for worktree_id in &connection.worktrees {
|
for worktree_id in &connection.worktrees {
|
||||||
let worktree = &self.worktrees.get(&worktree_id).unwrap();
|
let worktree = &self.worktrees.get(&worktree_id).unwrap();
|
||||||
if worktree.host_connection_id != *connection_id {
|
if worktree.host_connection_id != *connection_id {
|
||||||
assert!(worktree
|
assert!(worktree.share().unwrap().guests.contains_key(connection_id));
|
||||||
.share()
|
|
||||||
.unwrap()
|
|
||||||
.guest_connection_ids
|
|
||||||
.contains_key(connection_id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for channel_id in &connection.channels {
|
for channel_id in &connection.channels {
|
||||||
|
@ -535,29 +530,26 @@ impl Store {
|
||||||
let host_connection = self.connections.get(&worktree.host_connection_id).unwrap();
|
let host_connection = self.connections.get(&worktree.host_connection_id).unwrap();
|
||||||
assert!(host_connection.worktrees.contains(worktree_id));
|
assert!(host_connection.worktrees.contains(worktree_id));
|
||||||
|
|
||||||
for collaborator_id in &worktree.collaborator_user_ids {
|
for authorized_user_ids in &worktree.authorized_user_ids {
|
||||||
let visible_worktree_ids = self
|
let visible_worktree_ids = self
|
||||||
.visible_worktrees_by_user_id
|
.visible_worktrees_by_user_id
|
||||||
.get(collaborator_id)
|
.get(authorized_user_ids)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(visible_worktree_ids.contains(worktree_id));
|
assert!(visible_worktree_ids.contains(worktree_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(share) = &worktree.share {
|
if let Some(share) = &worktree.share {
|
||||||
for guest_connection_id in share.guest_connection_ids.keys() {
|
for guest_connection_id in share.guests.keys() {
|
||||||
let guest_connection = self.connections.get(guest_connection_id).unwrap();
|
let guest_connection = self.connections.get(guest_connection_id).unwrap();
|
||||||
assert!(guest_connection.worktrees.contains(worktree_id));
|
assert!(guest_connection.worktrees.contains(worktree_id));
|
||||||
}
|
}
|
||||||
assert_eq!(
|
assert_eq!(share.active_replica_ids.len(), share.guests.len(),);
|
||||||
share.active_replica_ids.len(),
|
|
||||||
share.guest_connection_ids.len(),
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
share.active_replica_ids,
|
share.active_replica_ids,
|
||||||
share
|
share
|
||||||
.guest_connection_ids
|
.guests
|
||||||
.values()
|
.values()
|
||||||
.copied()
|
.map(|(replica_id, _)| *replica_id)
|
||||||
.collect::<HashSet<_>>(),
|
.collect::<HashSet<_>>(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -566,7 +558,7 @@ impl Store {
|
||||||
for (user_id, visible_worktree_ids) in &self.visible_worktrees_by_user_id {
|
for (user_id, visible_worktree_ids) in &self.visible_worktrees_by_user_id {
|
||||||
for worktree_id in visible_worktree_ids {
|
for worktree_id in visible_worktree_ids {
|
||||||
let worktree = self.worktrees.get(worktree_id).unwrap();
|
let worktree = self.worktrees.get(worktree_id).unwrap();
|
||||||
assert!(worktree.collaborator_user_ids.contains(user_id));
|
assert!(worktree.authorized_user_ids.contains(user_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,7 +575,7 @@ impl Worktree {
|
||||||
pub fn connection_ids(&self) -> Vec<ConnectionId> {
|
pub fn connection_ids(&self) -> Vec<ConnectionId> {
|
||||||
if let Some(share) = &self.share {
|
if let Some(share) = &self.share {
|
||||||
share
|
share
|
||||||
.guest_connection_ids
|
.guests
|
||||||
.keys()
|
.keys()
|
||||||
.copied()
|
.copied()
|
||||||
.chain(Some(self.host_connection_id))
|
.chain(Some(self.host_connection_id))
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct Theme {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub workspace: Workspace,
|
pub workspace: Workspace,
|
||||||
pub chat_panel: ChatPanel,
|
pub chat_panel: ChatPanel,
|
||||||
pub people_panel: PeoplePanel,
|
pub contacts_panel: ContactsPanel,
|
||||||
pub project_panel: ProjectPanel,
|
pub project_panel: ProjectPanel,
|
||||||
pub selector: Selector,
|
pub selector: Selector,
|
||||||
pub editor: EditorStyle,
|
pub editor: EditorStyle,
|
||||||
|
@ -42,8 +42,10 @@ pub struct Workspace {
|
||||||
pub struct Titlebar {
|
pub struct Titlebar {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub container: ContainerStyle,
|
pub container: ContainerStyle,
|
||||||
|
pub height: f32,
|
||||||
pub title: TextStyle,
|
pub title: TextStyle,
|
||||||
pub avatar_width: f32,
|
pub avatar_width: f32,
|
||||||
|
pub avatar_ribbon: AvatarRibbon,
|
||||||
pub offline_icon: OfflineIcon,
|
pub offline_icon: OfflineIcon,
|
||||||
pub icon_color: Color,
|
pub icon_color: Color,
|
||||||
pub avatar: ImageStyle,
|
pub avatar: ImageStyle,
|
||||||
|
@ -52,6 +54,14 @@ pub struct Titlebar {
|
||||||
pub outdated_warning: ContainedText,
|
pub outdated_warning: ContainedText,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, Default)]
|
||||||
|
pub struct AvatarRibbon {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub container: ContainerStyle,
|
||||||
|
pub width: f32,
|
||||||
|
pub height: f32,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
pub struct OfflineIcon {
|
pub struct OfflineIcon {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
@ -137,7 +147,7 @@ pub struct ProjectPanelEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default)]
|
#[derive(Deserialize, Default)]
|
||||||
pub struct PeoplePanel {
|
pub struct ContactsPanel {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub container: ContainerStyle,
|
pub container: ContainerStyle,
|
||||||
pub host_row_height: f32,
|
pub host_row_height: f32,
|
||||||
|
@ -275,6 +285,15 @@ impl EditorStyle {
|
||||||
pub fn placeholder_text(&self) -> &TextStyle {
|
pub fn placeholder_text(&self) -> &TextStyle {
|
||||||
self.placeholder_text.as_ref().unwrap_or(&self.text)
|
self.placeholder_text.as_ref().unwrap_or(&self.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
|
||||||
|
let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
|
||||||
|
if style_ix == 0 {
|
||||||
|
&self.selection
|
||||||
|
} else {
|
||||||
|
&self.guest_selections[style_ix - 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputEditorStyle {
|
impl InputEditorStyle {
|
||||||
|
|
|
@ -5,9 +5,15 @@ pub mod sidebar;
|
||||||
mod status_bar;
|
mod status_bar;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use client::{Authenticate, ChannelList, Client, UserStore};
|
use client::{Authenticate, ChannelList, Client, User, UserStore};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action, elements::*, json::to_string_pretty, keymap::Binding, platform::CursorStyle,
|
action,
|
||||||
|
color::Color,
|
||||||
|
elements::*,
|
||||||
|
geometry::{vector::vec2f, PathBuilder},
|
||||||
|
json::{self, to_string_pretty, ToJson},
|
||||||
|
keymap::Binding,
|
||||||
|
platform::CursorStyle,
|
||||||
AnyViewHandle, AppContext, ClipboardItem, Entity, ModelContext, ModelHandle, MutableAppContext,
|
AnyViewHandle, AppContext, ClipboardItem, Entity, ModelContext, ModelHandle, MutableAppContext,
|
||||||
PromptLevel, RenderContext, Task, View, ViewContext, ViewHandle, WeakModelHandle,
|
PromptLevel, RenderContext, Task, View, ViewContext, ViewHandle, WeakModelHandle,
|
||||||
};
|
};
|
||||||
|
@ -27,6 +33,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
use theme::Theme;
|
||||||
|
|
||||||
action!(OpenNew, WorkspaceParams);
|
action!(OpenNew, WorkspaceParams);
|
||||||
action!(Save);
|
action!(Save);
|
||||||
|
@ -348,6 +355,7 @@ impl Workspace {
|
||||||
Project::new(
|
Project::new(
|
||||||
params.languages.clone(),
|
params.languages.clone(),
|
||||||
params.client.clone(),
|
params.client.clone(),
|
||||||
|
params.user_store.clone(),
|
||||||
params.fs.clone(),
|
params.fs.clone(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -951,25 +959,100 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_avatar(&self, cx: &mut RenderContext<Self>) -> ElementBox {
|
fn render_titlebar(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||||
let theme = &self.settings.borrow().theme;
|
ConstrainedBox::new(
|
||||||
if let Some(avatar) = self
|
Container::new(
|
||||||
.user_store
|
Stack::new()
|
||||||
.read(cx)
|
.with_child(
|
||||||
.current_user()
|
Align::new(
|
||||||
.and_then(|user| user.avatar.clone())
|
Label::new("zed".into(), theme.workspace.titlebar.title.clone())
|
||||||
{
|
.boxed(),
|
||||||
ConstrainedBox::new(
|
)
|
||||||
Align::new(
|
.boxed(),
|
||||||
ConstrainedBox::new(
|
)
|
||||||
Image::new(avatar)
|
.with_child(
|
||||||
.with_style(theme.workspace.titlebar.avatar)
|
Align::new(
|
||||||
.boxed(),
|
Flex::row()
|
||||||
|
.with_children(self.render_collaborators(theme, cx))
|
||||||
|
.with_child(
|
||||||
|
self.render_avatar(
|
||||||
|
self.user_store.read(cx).current_user().as_ref(),
|
||||||
|
self.project
|
||||||
|
.read(cx)
|
||||||
|
.active_worktree()
|
||||||
|
.map(|worktree| worktree.read(cx).replica_id()),
|
||||||
|
theme,
|
||||||
|
cx,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.with_children(self.render_connection_status())
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.right()
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_style(theme.workspace.titlebar.container)
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_height(theme.workspace.titlebar.height)
|
||||||
|
.named("titlebar")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_collaborators(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> Vec<ElementBox> {
|
||||||
|
let mut elements = Vec::new();
|
||||||
|
if let Some(active_worktree) = self.project.read(cx).active_worktree() {
|
||||||
|
let collaborators = active_worktree
|
||||||
|
.read(cx)
|
||||||
|
.collaborators()
|
||||||
|
.values()
|
||||||
|
.cloned()
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
for collaborator in collaborators {
|
||||||
|
elements.push(self.render_avatar(
|
||||||
|
Some(&collaborator.user),
|
||||||
|
Some(collaborator.replica_id),
|
||||||
|
theme,
|
||||||
|
cx,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elements
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_avatar(
|
||||||
|
&self,
|
||||||
|
user: Option<&Arc<User>>,
|
||||||
|
replica_id: Option<u16>,
|
||||||
|
theme: &Theme,
|
||||||
|
cx: &mut RenderContext<Self>,
|
||||||
|
) -> ElementBox {
|
||||||
|
if let Some(avatar) = user.and_then(|user| user.avatar.clone()) {
|
||||||
|
ConstrainedBox::new(
|
||||||
|
Stack::new()
|
||||||
|
.with_child(
|
||||||
|
ConstrainedBox::new(
|
||||||
|
Image::new(avatar)
|
||||||
|
.with_style(theme.workspace.titlebar.avatar)
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_width(theme.workspace.titlebar.avatar_width)
|
||||||
|
.aligned()
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_child(
|
||||||
|
AvatarRibbon::new(replica_id.map_or(Default::default(), |id| {
|
||||||
|
theme.editor.replica_selection_style(id).cursor
|
||||||
|
}))
|
||||||
|
.constrained()
|
||||||
|
.with_width(theme.workspace.titlebar.avatar_ribbon.width)
|
||||||
|
.with_height(theme.workspace.titlebar.avatar_ribbon.height)
|
||||||
|
.aligned()
|
||||||
|
.bottom()
|
||||||
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_width(theme.workspace.titlebar.avatar_width)
|
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
)
|
)
|
||||||
.with_width(theme.workspace.right_sidebar.width)
|
.with_width(theme.workspace.right_sidebar.width)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
@ -1007,38 +1090,7 @@ impl View for Workspace {
|
||||||
let theme = &settings.theme;
|
let theme = &settings.theme;
|
||||||
Container::new(
|
Container::new(
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.with_child(
|
.with_child(self.render_titlebar(&theme, cx))
|
||||||
ConstrainedBox::new(
|
|
||||||
Container::new(
|
|
||||||
Stack::new()
|
|
||||||
.with_child(
|
|
||||||
Align::new(
|
|
||||||
Label::new(
|
|
||||||
"zed".into(),
|
|
||||||
theme.workspace.titlebar.title.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Align::new(
|
|
||||||
Flex::row()
|
|
||||||
.with_children(self.render_connection_status())
|
|
||||||
.with_child(self.render_avatar(cx))
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.right()
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_style(theme.workspace.titlebar.container)
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_height(32.)
|
|
||||||
.named("titlebar"),
|
|
||||||
)
|
|
||||||
.with_child(
|
.with_child(
|
||||||
Expanded::new(
|
Expanded::new(
|
||||||
1.0,
|
1.0,
|
||||||
|
@ -1106,3 +1158,71 @@ impl WorkspaceHandle for ViewHandle<Workspace> {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct AvatarRibbon {
|
||||||
|
color: Color,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AvatarRibbon {
|
||||||
|
pub fn new(color: Color) -> AvatarRibbon {
|
||||||
|
AvatarRibbon { color }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Element for AvatarRibbon {
|
||||||
|
type LayoutState = ();
|
||||||
|
|
||||||
|
type PaintState = ();
|
||||||
|
|
||||||
|
fn layout(
|
||||||
|
&mut self,
|
||||||
|
constraint: gpui::SizeConstraint,
|
||||||
|
_: &mut gpui::LayoutContext,
|
||||||
|
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
||||||
|
(constraint.max, ())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paint(
|
||||||
|
&mut self,
|
||||||
|
bounds: gpui::geometry::rect::RectF,
|
||||||
|
_: gpui::geometry::rect::RectF,
|
||||||
|
_: &mut Self::LayoutState,
|
||||||
|
cx: &mut gpui::PaintContext,
|
||||||
|
) -> Self::PaintState {
|
||||||
|
let mut path = PathBuilder::new();
|
||||||
|
path.reset(bounds.lower_left());
|
||||||
|
path.curve_to(
|
||||||
|
bounds.origin() + vec2f(bounds.height(), 0.),
|
||||||
|
bounds.origin(),
|
||||||
|
);
|
||||||
|
path.line_to(bounds.upper_right() - vec2f(bounds.height(), 0.));
|
||||||
|
path.curve_to(bounds.lower_right(), bounds.upper_right());
|
||||||
|
path.line_to(bounds.lower_left());
|
||||||
|
cx.scene.push_path(path.build(self.color, None));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dispatch_event(
|
||||||
|
&mut self,
|
||||||
|
_: &gpui::Event,
|
||||||
|
_: gpui::geometry::rect::RectF,
|
||||||
|
_: &mut Self::LayoutState,
|
||||||
|
_: &mut Self::PaintState,
|
||||||
|
_: &mut gpui::EventContext,
|
||||||
|
) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn debug(
|
||||||
|
&self,
|
||||||
|
bounds: gpui::geometry::rect::RectF,
|
||||||
|
_: &Self::LayoutState,
|
||||||
|
_: &Self::PaintState,
|
||||||
|
_: &gpui::DebugContext,
|
||||||
|
) -> gpui::json::Value {
|
||||||
|
json::json!({
|
||||||
|
"type": "AvatarRibbon",
|
||||||
|
"bounds": bounds.to_json(),
|
||||||
|
"color": self.color.to_json(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ go_to_line = { path = "../go_to_line" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
language = { path = "../language" }
|
language = { path = "../language" }
|
||||||
lsp = { path = "../lsp" }
|
lsp = { path = "../lsp" }
|
||||||
people_panel = { path = "../people_panel" }
|
contacts_panel = { path = "../contacts_panel" }
|
||||||
project = { path = "../project" }
|
project = { path = "../project" }
|
||||||
project_panel = { path = "../project_panel" }
|
project_panel = { path = "../project_panel" }
|
||||||
rpc = { path = "../rpc" }
|
rpc = { path = "../rpc" }
|
||||||
|
|
|
@ -6,11 +6,13 @@ background = "$surface.0"
|
||||||
pane_divider = { width = 1, color = "$border.0" }
|
pane_divider = { width = 1, color = "$border.0" }
|
||||||
|
|
||||||
[workspace.titlebar]
|
[workspace.titlebar]
|
||||||
|
height = 32
|
||||||
border = { width = 1, bottom = true, color = "$border.0" }
|
border = { width = 1, bottom = true, color = "$border.0" }
|
||||||
title = "$text.0"
|
title = "$text.0"
|
||||||
avatar_width = 20
|
avatar_width = 18
|
||||||
icon_color = "$text.2.color"
|
|
||||||
avatar = { corner_radius = 10, border = { width = 1, color = "#00000088" } }
|
avatar = { corner_radius = 10, border = { width = 1, color = "#00000088" } }
|
||||||
|
avatar_ribbon = { background = "#ff0000", height = 3, width = 12 }
|
||||||
|
icon_color = "$text.2.color"
|
||||||
outdated_warning = { extends = "$text.2", size = 13 }
|
outdated_warning = { extends = "$text.2", size = 13 }
|
||||||
|
|
||||||
[workspace.titlebar.sign_in_prompt]
|
[workspace.titlebar.sign_in_prompt]
|
||||||
|
@ -46,7 +48,7 @@ background = "$surface.1"
|
||||||
text = "$text.0"
|
text = "$text.0"
|
||||||
|
|
||||||
[workspace.sidebar]
|
[workspace.sidebar]
|
||||||
width = 32
|
width = 30
|
||||||
border = { right = true, width = 1, color = "$border.0" }
|
border = { right = true, width = 1, color = "$border.0" }
|
||||||
|
|
||||||
[workspace.sidebar.resize_handle]
|
[workspace.sidebar.resize_handle]
|
||||||
|
@ -146,38 +148,38 @@ underline = true
|
||||||
extends = "$chat_panel.sign_in_prompt"
|
extends = "$chat_panel.sign_in_prompt"
|
||||||
color = "$text.1.color"
|
color = "$text.1.color"
|
||||||
|
|
||||||
[people_panel]
|
[contacts_panel]
|
||||||
extends = "$panel"
|
extends = "$panel"
|
||||||
host_row_height = 28
|
host_row_height = 28
|
||||||
host_avatar = { corner_radius = 10, width = 20 }
|
host_avatar = { corner_radius = 10, width = 18 }
|
||||||
host_username = { extends = "$text.0", padding.left = 8 }
|
host_username = { extends = "$text.0", padding.left = 8 }
|
||||||
tree_branch_width = 1
|
tree_branch_width = 1
|
||||||
tree_branch_color = "$surface.2"
|
tree_branch_color = "$surface.2"
|
||||||
|
|
||||||
[people_panel.worktree]
|
[contacts_panel.worktree]
|
||||||
height = 24
|
height = 24
|
||||||
padding = { left = 8 }
|
padding = { left = 8 }
|
||||||
guest_avatar = { corner_radius = 8, width = 16 }
|
guest_avatar = { corner_radius = 8, width = 14 }
|
||||||
guest_avatar_spacing = 4
|
guest_avatar_spacing = 4
|
||||||
|
|
||||||
[people_panel.worktree.name]
|
[contacts_panel.worktree.name]
|
||||||
extends = "$text.1"
|
extends = "$text.1"
|
||||||
margin = { right = 6 }
|
margin = { right = 6 }
|
||||||
|
|
||||||
[people_panel.unshared_worktree]
|
[contacts_panel.unshared_worktree]
|
||||||
extends = "$people_panel.worktree"
|
extends = "$contacts_panel.worktree"
|
||||||
|
|
||||||
[people_panel.hovered_unshared_worktree]
|
[contacts_panel.hovered_unshared_worktree]
|
||||||
extends = "$people_panel.unshared_worktree"
|
extends = "$contacts_panel.unshared_worktree"
|
||||||
background = "$state.hover"
|
background = "$state.hover"
|
||||||
corner_radius = 6
|
corner_radius = 6
|
||||||
|
|
||||||
[people_panel.shared_worktree]
|
[contacts_panel.shared_worktree]
|
||||||
extends = "$people_panel.worktree"
|
extends = "$contacts_panel.worktree"
|
||||||
name.color = "$text.0.color"
|
name.color = "$text.0.color"
|
||||||
|
|
||||||
[people_panel.hovered_shared_worktree]
|
[contacts_panel.hovered_shared_worktree]
|
||||||
extends = "$people_panel.shared_worktree"
|
extends = "$contacts_panel.shared_worktree"
|
||||||
background = "$state.hover"
|
background = "$state.hover"
|
||||||
corner_radius = 6
|
corner_radius = 6
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ pub mod test;
|
||||||
use self::language::LanguageRegistry;
|
use self::language::LanguageRegistry;
|
||||||
use chat_panel::ChatPanel;
|
use chat_panel::ChatPanel;
|
||||||
pub use client;
|
pub use client;
|
||||||
|
pub use contacts_panel;
|
||||||
|
use contacts_panel::ContactsPanel;
|
||||||
pub use editor;
|
pub use editor;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action,
|
action,
|
||||||
|
@ -17,8 +19,6 @@ use gpui::{
|
||||||
};
|
};
|
||||||
pub use lsp;
|
pub use lsp;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
pub use people_panel;
|
|
||||||
use people_panel::PeoplePanel;
|
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
pub use project::{self, fs};
|
pub use project::{self, fs};
|
||||||
use project_panel::ProjectPanel;
|
use project_panel::ProjectPanel;
|
||||||
|
@ -144,8 +144,10 @@ fn build_workspace(params: &WorkspaceParams, cx: &mut ViewContext<Workspace>) ->
|
||||||
);
|
);
|
||||||
workspace.right_sidebar_mut().add_item(
|
workspace.right_sidebar_mut().add_item(
|
||||||
"icons/user-16.svg",
|
"icons/user-16.svg",
|
||||||
cx.add_view(|cx| PeoplePanel::new(params.user_store.clone(), params.settings.clone(), cx))
|
cx.add_view(|cx| {
|
||||||
.into(),
|
ContactsPanel::new(params.user_store.clone(), params.settings.clone(), cx)
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
);
|
);
|
||||||
workspace.right_sidebar_mut().add_item(
|
workspace.right_sidebar_mut().add_item(
|
||||||
"icons/comment-16.svg",
|
"icons/comment-16.svg",
|
||||||
|
|
|
@ -40,7 +40,7 @@ fn main() {
|
||||||
editor::init(cx, &mut entry_openers);
|
editor::init(cx, &mut entry_openers);
|
||||||
go_to_line::init(cx);
|
go_to_line::init(cx);
|
||||||
file_finder::init(cx);
|
file_finder::init(cx);
|
||||||
people_panel::init(cx);
|
contacts_panel::init(cx);
|
||||||
chat_panel::init(cx);
|
chat_panel::init(cx);
|
||||||
project_panel::init(cx);
|
project_panel::init(cx);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue