From 0871c539ee981b31dd97a7488e9f362c2a94fe6d Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Wed, 29 Oct 2025 11:40:02 -0400 Subject: [PATCH] acp_tools: Add button to clear messages (#41206) Added a "Clear Messages" button to the ACP logs toolbar that removes all messages. ## Motivation When debugging ACP protocol implementations, the message list can become cluttered with old messages. This feature allows clearing all messages with a single click to start fresh, making it easier to focus on new interactions without closing and reopening the ACP logs view. Release Notes: - N/A --- crates/acp_tools/src/acp_tools.rs | 38 +++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/crates/acp_tools/src/acp_tools.rs b/crates/acp_tools/src/acp_tools.rs index 69722815306e412745a62832115d2f010b2b8607..a40bcbd93c878a85c85d7edd312e713988234966 100644 --- a/crates/acp_tools/src/acp_tools.rs +++ b/crates/acp_tools/src/acp_tools.rs @@ -259,6 +259,15 @@ impl AcpTools { serde_json::to_string_pretty(&messages).ok() } + fn clear_messages(&mut self, cx: &mut Context) { + if let Some(connection) = self.watched_connection.as_mut() { + connection.messages.clear(); + connection.list_state.reset(0); + self.expanded.clear(); + cx.notify(); + } + } + fn render_message( &mut self, index: usize, @@ -547,10 +556,16 @@ impl Render for AcpToolsToolbarItemView { }; let acp_tools = acp_tools.clone(); + let has_messages = acp_tools + .read(cx) + .watched_connection + .as_ref() + .is_some_and(|connection| !connection.messages.is_empty()); h_flex() .gap_2() - .child( + .child({ + let acp_tools = acp_tools.clone(); IconButton::new( "copy_all_messages", if self.just_copied { @@ -565,13 +580,7 @@ impl Render for AcpToolsToolbarItemView { } else { "Copy All Messages" })) - .disabled( - acp_tools - .read(cx) - .watched_connection - .as_ref() - .is_none_or(|connection| connection.messages.is_empty()), - ) + .disabled(!has_messages) .on_click(cx.listener(move |this, _, _window, cx| { if let Some(content) = acp_tools.read(cx).serialize_observed_messages() { cx.write_to_clipboard(ClipboardItem::new_string(content)); @@ -586,7 +595,18 @@ impl Render for AcpToolsToolbarItemView { }) .detach(); } - })), + })) + }) + .child( + IconButton::new("clear_messages", IconName::Trash) + .icon_size(IconSize::Small) + .tooltip(Tooltip::text("Clear Messages")) + .disabled(!has_messages) + .on_click(cx.listener(move |_this, _, _window, cx| { + acp_tools.update(cx, |acp_tools, cx| { + acp_tools.clear_messages(cx); + }); + })), ) .into_any() }