Forward events from remote worktrees to their projects

This commit is contained in:
Max Brunsfeld 2022-01-04 15:49:29 -08:00
parent d8b888c9cb
commit 0bcd0a3f08
2 changed files with 48 additions and 34 deletions

View file

@ -229,35 +229,45 @@ impl Project {
collaborators.insert(collaborator.peer_id, collaborator); collaborators.insert(collaborator.peer_id, collaborator);
} }
Ok(cx.add_model(|cx| Self { Ok(cx.add_model(|cx| {
worktrees, let mut this = Self {
active_entry: None, worktrees: Vec::new(),
collaborators, active_entry: None,
languages, collaborators,
user_store, languages,
fs, user_store,
subscriptions: vec![ fs,
client.subscribe_to_entity(remote_id, cx, Self::handle_unshare_project), subscriptions: vec![
client.subscribe_to_entity(remote_id, cx, Self::handle_add_collaborator), client.subscribe_to_entity(remote_id, cx, Self::handle_unshare_project),
client.subscribe_to_entity(remote_id, cx, Self::handle_remove_collaborator), client.subscribe_to_entity(remote_id, cx, Self::handle_add_collaborator),
client.subscribe_to_entity(remote_id, cx, Self::handle_share_worktree), client.subscribe_to_entity(remote_id, cx, Self::handle_remove_collaborator),
client.subscribe_to_entity(remote_id, cx, Self::handle_unregister_worktree), client.subscribe_to_entity(remote_id, cx, Self::handle_share_worktree),
client.subscribe_to_entity(remote_id, cx, Self::handle_update_worktree), client.subscribe_to_entity(remote_id, cx, Self::handle_unregister_worktree),
client.subscribe_to_entity(remote_id, cx, Self::handle_update_diagnostic_summary), client.subscribe_to_entity(remote_id, cx, Self::handle_update_worktree),
client.subscribe_to_entity( client.subscribe_to_entity(
remote_id,
cx,
Self::handle_update_diagnostic_summary,
),
client.subscribe_to_entity(
remote_id,
cx,
Self::handle_disk_based_diagnostics_updated,
),
client.subscribe_to_entity(remote_id, cx, Self::handle_update_buffer),
client.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved),
],
client,
client_state: ProjectClientState::Remote {
sharing_has_stopped: false,
remote_id, remote_id,
cx, replica_id,
Self::handle_disk_based_diagnostics_updated, },
), };
client.subscribe_to_entity(remote_id, cx, Self::handle_update_buffer), for worktree in worktrees {
client.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved), this.add_worktree(worktree, cx);
], }
client, this
client_state: ProjectClientState::Remote {
sharing_has_stopped: false,
remote_id,
replica_id,
},
})) }))
} }

View file

@ -1060,7 +1060,7 @@ mod tests {
LanguageRegistry, LanguageServerConfig, Point, LanguageRegistry, LanguageServerConfig, Point,
}, },
lsp, lsp,
project::{DiagnosticSummary, Project}, project::{DiagnosticSummary, Project, ProjectPath},
}; };
#[gpui::test] #[gpui::test]
@ -1801,6 +1801,7 @@ mod tests {
let project_id = project_a let project_id = project_a
.update(&mut cx_a, |project, _| project.next_remote_id()) .update(&mut cx_a, |project, _| project.next_remote_id())
.await; .await;
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
project_a project_a
.update(&mut cx_a, |project, cx| project.share(cx)) .update(&mut cx_a, |project, cx| project.share(cx))
.await .await
@ -1826,7 +1827,6 @@ mod tests {
) )
.await .await
.unwrap(); .unwrap();
let worktree_b = project_b.update(&mut cx_b, |p, _| p.worktrees()[0].clone());
// Simulate a language server reporting errors for a file. // Simulate a language server reporting errors for a file.
fake_language_server fake_language_server
@ -1853,11 +1853,14 @@ mod tests {
}) })
.await; .await;
worktree_b project_b
.condition(&cx_b, |worktree, _| { .condition(&cx_b, |project, cx| {
worktree.diagnostic_summaries().collect::<Vec<_>>() project.diagnostic_summaries(cx).collect::<Vec<_>>()
== &[( == &[(
Arc::from(Path::new("a.rs")), ProjectPath {
worktree_id,
path: Arc::from(Path::new("a.rs")),
},
DiagnosticSummary { DiagnosticSummary {
error_count: 1, error_count: 1,
warning_count: 1, warning_count: 1,
@ -1868,6 +1871,7 @@ mod tests {
.await; .await;
// Open the file with the errors. // Open the file with the errors.
let worktree_b = project_b.update(&mut cx_b, |p, _| p.worktrees()[0].clone());
let buffer_b = cx_b let buffer_b = cx_b
.background() .background()
.spawn(worktree_b.update(&mut cx_b, |worktree, cx| worktree.open_buffer("a.rs", cx))) .spawn(worktree_b.update(&mut cx_b, |worktree, cx| worktree.open_buffer("a.rs", cx)))