Fix clippy warnings

Ben Brandt created

Change summary

crates/acp_thread/src/acp_thread.rs            | 17 +++--------
crates/acp_thread/src/connection.rs            |  6 ++--
crates/agent_servers/src/agent_servers.rs      |  3 +
crates/agent_servers/src/claude.rs             |  7 ++--
crates/agent_servers/src/codex.rs              |  5 +--
crates/agent_servers/src/mcp_server.rs         | 27 +++++++++++++------
crates/agent_servers/src/stdio_agent_server.rs |  6 ++--
7 files changed, 36 insertions(+), 35 deletions(-)

Detailed changes

crates/acp_thread/src/acp_thread.rs 🔗

@@ -111,14 +111,7 @@ pub enum AssistantMessageChunk {
 impl AssistantMessageChunk {
     pub fn from_str(chunk: &str, language_registry: &Arc<LanguageRegistry>, cx: &mut App) -> Self {
         Self::Message {
-            block: ContentBlock::new(
-                acp::ContentBlock::Text(acp::TextContent {
-                    text: chunk.to_owned().into(),
-                    annotations: None,
-                }),
-                language_registry,
-                cx,
-            ),
+            block: ContentBlock::new(chunk.into(), language_registry, cx),
         }
     }
 
@@ -562,7 +555,7 @@ pub struct AcpThread {
     action_log: Entity<ActionLog>,
     shared_buffers: HashMap<Entity<Buffer>, BufferSnapshot>,
     send_task: Option<Task<()>>,
-    connection: Arc<dyn AgentConnection>,
+    connection: Rc<dyn AgentConnection>,
     child_status: Option<Task<Result<()>>>,
     session_id: acp::SessionId,
 }
@@ -606,7 +599,7 @@ impl Error for LoadError {}
 
 impl AcpThread {
     pub fn new(
-        connection: Arc<dyn AgentConnection>,
+        connection: Rc<dyn AgentConnection>,
         // todo! remove me
         title: SharedString,
         // todo! remove this?
@@ -1294,7 +1287,7 @@ impl acp_old::Client for OldAcpClientDelegate {
             .await;
 
         let outcome = match response {
-            Ok(option_id) => outcomes[option_id.0.parse::<usize>().unwrap_or(0)].clone(),
+            Ok(option_id) => outcomes[option_id.0.parse::<usize>().unwrap_or(0)],
             Err(oneshot::Canceled) => acp_old::ToolCallConfirmationOutcome::Cancel,
         };
 
@@ -1831,7 +1824,7 @@ mod tests {
             };
 
             AcpThread::new(
-                Arc::new(connection),
+                Rc::new(connection),
                 "Test".into(),
                 None,
                 project,

crates/acp_thread/src/connection.rs 🔗

@@ -1,4 +1,4 @@
-use std::{cell::RefCell, error::Error, fmt, path::Path, rc::Rc, sync::Arc};
+use std::{cell::RefCell, error::Error, fmt, path::Path, rc::Rc};
 
 use agent_client_protocol as acp;
 use agentic_coding_protocol::{self as acp_old, AgentRequest};
@@ -14,7 +14,7 @@ pub trait AgentConnection {
         &self,
         project: Entity<Project>,
         cwd: &Path,
-        connection: Arc<dyn AgentConnection>,
+        connection: Rc<dyn AgentConnection>,
         cx: &mut AsyncApp,
     ) -> Task<Result<Entity<AcpThread>>>;
 
@@ -46,7 +46,7 @@ impl AgentConnection for OldAcpAgentConnection {
         &self,
         project: Entity<Project>,
         _cwd: &Path,
-        connection: Arc<dyn AgentConnection>,
+        connection: Rc<dyn AgentConnection>,
         cx: &mut AsyncApp,
     ) -> Task<Result<Entity<AcpThread>>> {
         let task = self.connection.request_any(

crates/agent_servers/src/agent_servers.rs 🔗

@@ -23,6 +23,7 @@ use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 use std::{
     path::{Path, PathBuf},
+    rc::Rc,
     sync::Arc,
 };
 use util::ResultExt as _;
@@ -42,7 +43,7 @@ pub trait AgentServer: Send {
         root_dir: &Path,
         project: &Entity<Project>,
         cx: &mut App,
-    ) -> Task<Result<Arc<dyn AgentConnection>>>;
+    ) -> Task<Result<Rc<dyn AgentConnection>>>;
 }
 
 impl std::fmt::Debug for AgentServerCommand {

crates/agent_servers/src/claude.rs 🔗

@@ -9,7 +9,6 @@ use std::fmt::Display;
 use std::path::Path;
 use std::pin::pin;
 use std::rc::Rc;
-use std::sync::Arc;
 use uuid::Uuid;
 
 use agent_client_protocol as acp;
@@ -56,7 +55,7 @@ impl AgentServer for ClaudeCode {
         root_dir: &Path,
         project: &Entity<Project>,
         cx: &mut App,
-    ) -> Task<Result<Arc<dyn AgentConnection>>> {
+    ) -> Task<Result<Rc<dyn AgentConnection>>> {
         let project = project.clone();
         let root_dir = root_dir.to_path_buf();
         cx.spawn(async move |cx| {
@@ -179,7 +178,7 @@ impl AgentServer for ClaudeCode {
                 _mcp_server: Some(permission_mcp_server),
             };
 
-            Ok(Arc::new(connection) as _)
+            Ok(Rc::new(connection) as _)
         })
     }
 }
@@ -202,7 +201,7 @@ impl AgentConnection for ClaudeAgentConnection {
         &self,
         project: Entity<Project>,
         _cwd: &Path,
-        connection: Arc<dyn AgentConnection>,
+        connection: Rc<dyn AgentConnection>,
         cx: &mut AsyncApp,
     ) -> Task<Result<Entity<AcpThread>>> {
         let session_id = self.session_id.clone();

crates/agent_servers/src/codex.rs 🔗

@@ -1,6 +1,5 @@
 use project::Project;
-use std::path::Path;
-use std::sync::Arc;
+use std::{path::Path, rc::Rc};
 
 use anyhow::Result;
 use gpui::{App, Entity, Task};
@@ -33,7 +32,7 @@ impl AgentServer for Codex {
         _root_dir: &Path,
         _project: &Entity<Project>,
         _cx: &mut App,
-    ) -> Task<Result<Arc<dyn AgentConnection>>> {
+    ) -> Task<Result<Rc<dyn AgentConnection>>> {
         // re-implement using ACP
         todo!()
     }

crates/agent_servers/src/mcp_server.rs 🔗

@@ -197,9 +197,12 @@ impl ZedMcpServer {
     ) -> Task<Result<Vec<ToolResponseContent>>> {
         cx.spawn(async move |cx| {
             // todo! get session id somehow
-            let threads_map = threads_map.borrow();
-            let Some((_, thread)) = threads_map.iter().next() else {
-                anyhow::bail!("Server not available");
+            let thread = {
+                let threads_map = threads_map.borrow();
+                let Some((_, thread)) = threads_map.iter().next() else {
+                    anyhow::bail!("Server not available");
+                };
+                thread.clone()
             };
 
             let content = thread
@@ -219,9 +222,12 @@ impl ZedMcpServer {
     ) -> Task<Result<()>> {
         cx.spawn(async move |cx| {
             // todo! get session id somehow
-            let threads_map = threads_map.borrow();
-            let Some((_, thread)) = threads_map.iter().next() else {
-                anyhow::bail!("Server not available");
+            let thread = {
+                let threads_map = threads_map.borrow();
+                let Some((_, thread)) = threads_map.iter().next() else {
+                    anyhow::bail!("Server not available");
+                };
+                thread.clone()
             };
 
             let content = thread
@@ -252,9 +258,12 @@ impl ZedMcpServer {
     ) -> Task<Result<PermissionToolResponse>> {
         cx.spawn(async move |cx| {
             // todo! get session id somehow
-            let threads_map = threads_map.borrow();
-            let Some((_, thread)) = threads_map.iter().next() else {
-                anyhow::bail!("Server not available");
+            let thread = {
+                let threads_map = threads_map.borrow();
+                let Some((_, thread)) = threads_map.iter().next() else {
+                    anyhow::bail!("Server not available");
+                };
+                thread.clone()
             };
 
             let claude_tool = ClaudeTool::infer(&params.tool_name, params.input.clone());

crates/agent_servers/src/stdio_agent_server.rs 🔗

@@ -4,7 +4,7 @@ use agentic_coding_protocol as acp_old;
 use anyhow::{Result, anyhow};
 use gpui::{App, AsyncApp, Entity, Task, WeakEntity, prelude::*};
 use project::Project;
-use std::{cell::RefCell, path::Path, rc::Rc, sync::Arc};
+use std::{cell::RefCell, path::Path, rc::Rc};
 use util::ResultExt;
 
 pub trait StdioAgentServer: Send + Clone {
@@ -47,7 +47,7 @@ impl<T: StdioAgentServer + 'static> AgentServer for T {
         root_dir: &Path,
         project: &Entity<Project>,
         cx: &mut App,
-    ) -> Task<Result<Arc<dyn AgentConnection>>> {
+    ) -> Task<Result<Rc<dyn AgentConnection>>> {
         let root_dir = root_dir.to_path_buf();
         let project = project.clone();
         let this = self.clone();
@@ -107,7 +107,7 @@ impl<T: StdioAgentServer + 'static> AgentServer for T {
                 result
             });
 
-            let connection: Arc<dyn AgentConnection> = Arc::new(OldAcpAgentConnection {
+            let connection: Rc<dyn AgentConnection> = Rc::new(OldAcpAgentConnection {
                 connection,
                 child_status,
                 thread: thread_rc,