Insert project id in connection's project during project registration

Antonio Scandurra created

...in contrast to doing so during worktree registration. This fixes a
randomized test failure which would panic because store invariants would be
violated. This would happen when a peer disconnected before it had a chance
to register a worktree because, when removing all the state associated with
that peer upon disconnection, we would notice the registered project without
however finding it in the peer's connection state.

Change summary

crates/server/src/rpc/store.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

Detailed changes

crates/server/src/rpc/store.rs 🔗

@@ -244,6 +244,9 @@ impl Store {
                 language_servers: Default::default(),
             },
         );
+        if let Some(connection) = self.connections.get_mut(&host_connection_id) {
+            connection.projects.insert(project_id);
+        }
         self.next_project_id += 1;
         project_id
     }
@@ -266,9 +269,7 @@ impl Store {
                     .or_default()
                     .insert(project_id);
             }
-            if let Some(connection) = self.connections.get_mut(&project.host_connection_id) {
-                connection.projects.insert(project_id);
-            }
+
             project.worktrees.insert(worktree_id, worktree);
             if let Ok(share) = project.share_mut() {
                 share.worktrees.insert(worktree_id, Default::default());