Make new_thread nicer with RC receiver

Ben Brandt created

Change summary

crates/acp_thread/src/connection.rs    |  8 +++-----
crates/agent_servers/src/claude.rs     | 14 ++++++++++----
crates/agent_servers/src/e2e_tests.rs  |  7 +------
crates/agent_ui/src/acp/thread_view.rs |  5 +----
4 files changed, 15 insertions(+), 19 deletions(-)

Detailed changes

crates/acp_thread/src/connection.rs 🔗

@@ -11,10 +11,9 @@ use crate::AcpThread;
 
 pub trait AgentConnection {
     fn new_thread(
-        &self,
+        self: Rc<Self>,
         project: Entity<Project>,
         cwd: &Path,
-        connection: Rc<dyn AgentConnection>,
         cx: &mut AsyncApp,
     ) -> Task<Result<Entity<AcpThread>>>;
 
@@ -42,10 +41,9 @@ pub struct OldAcpAgentConnection {
 
 impl AgentConnection for OldAcpAgentConnection {
     fn new_thread(
-        &self,
+        self: Rc<Self>,
         project: Entity<Project>,
         _cwd: &Path,
-        connection: Rc<dyn AgentConnection>,
         cx: &mut AsyncApp,
     ) -> Task<Result<Entity<AcpThread>>> {
         let task = self.connection.request_any(
@@ -65,7 +63,7 @@ impl AgentConnection for OldAcpAgentConnection {
             cx.update(|cx| {
                 let thread = cx.new(|cx| {
                     let session_id = acp::SessionId("acp-old-no-id".into());
-                    AcpThread::new(connection, "Gemini".into(), project, session_id, cx)
+                    AcpThread::new(self.clone(), "Gemini".into(), project, session_id, cx)
                 });
                 thread
             })

crates/agent_servers/src/claude.rs 🔗

@@ -198,15 +198,21 @@ fn send_interrupt(_pid: i32) -> anyhow::Result<()> {
 
 impl AgentConnection for ClaudeAgentConnection {
     fn new_thread(
-        &self,
+        self: Rc<Self>,
         project: Entity<Project>,
         _cwd: &Path,
-        connection: Rc<dyn AgentConnection>,
         cx: &mut AsyncApp,
     ) -> Task<Result<Entity<AcpThread>>> {
         let session_id = self.session_id.clone();
-        let thread_result = cx
-            .new(|cx| AcpThread::new(connection, "Claude".into(), project, session_id.clone(), cx));
+        let thread_result = cx.new(|cx| {
+            AcpThread::new(
+                self.clone(),
+                "Claude".into(),
+                project,
+                session_id.clone(),
+                cx,
+            )
+        });
 
         if let Ok(thread) = &thread_result {
             self.threads_map

crates/agent_servers/src/e2e_tests.rs 🔗

@@ -376,12 +376,7 @@ pub async fn new_test_thread(
         .unwrap();
 
     let thread = connection
-        .new_thread(
-            project.clone(),
-            current_dir.as_ref(),
-            connection.clone(),
-            &mut cx.to_async(),
-        )
+        .new_thread(project.clone(), current_dir.as_ref(), &mut cx.to_async())
         .await
         .unwrap();
 

crates/agent_ui/src/acp/thread_view.rs 🔗

@@ -213,10 +213,7 @@ impl AcpThreadView {
                 }
             };
 
-            let result = match connection
-                .new_thread(project.clone(), &root_dir, connection.clone(), cx)
-                .await
-            {
+            let result = match connection.new_thread(project.clone(), &root_dir, cx).await {
                 Err(e) => {
                     let mut cx = cx.clone();
                     if e.downcast_ref::<oneshot::Canceled>().is_some() {