From 12acc1db10e9dc5246e436e27e46704efa2fa5fd Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 21 Oct 2025 16:37:16 +0200 Subject: [PATCH] acp_thread: Fix panic when following acp agents across buffers (#40798) Fixes ZED-2D7 Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/acp_thread/src/acp_thread.rs | 15 +++++++++------ crates/multi_buffer/src/multi_buffer.rs | 18 ++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs index ed2e01f0b37197d6878dee699fba43ed3410066f..4d8c57dd8f5a97aabc5cf3dc9e8d5aae9d6c8f2f 100644 --- a/crates/acp_thread/src/acp_thread.rs +++ b/crates/acp_thread/src/acp_thread.rs @@ -1421,15 +1421,18 @@ impl AcpThread { if let Some(Some(location)) = resolved_locations.last() { project.update(cx, |project, cx| { - let should_ignore = if let Some(agent_location) = project.agent_location() { + let should_ignore = if let Some(agent_location) = project + .agent_location() + .filter(|agent_location| agent_location.buffer == location.buffer) + { let snapshot = location.buffer.read(cx).snapshot(); let old_position = agent_location.position.to_point(&snapshot); let new_position = location.position.to_point(&snapshot); - agent_location.buffer == location.buffer - // ignore this so that when we get updates from the edit tool - // the position doesn't reset to the startof line - && (old_position.row == new_position.row - && old_position.column > new_position.column) + + // ignore this so that when we get updates from the edit tool + // the position doesn't reset to the startof line + old_position.row == new_position.row + && old_position.column > new_position.column } else { false }; diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index be01c4b6a1f9f67703f99bcd0b9b331574a6b360..3683487b691a183058f9f62818efad3a2b8cd3b6 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -6165,22 +6165,20 @@ impl MultiBufferSnapshot { ) -> SmallVec<[Locator; 1]> { let mut sorted_ids = ids.into_iter().collect::>(); sorted_ids.sort_unstable(); + sorted_ids.dedup(); let mut locators = SmallVec::new(); while sorted_ids.last() == Some(&ExcerptId::max()) { sorted_ids.pop(); - if let Some(mapping) = self.excerpt_ids.last() { - locators.push(mapping.locator.clone()); - } + locators.push(Locator::max()); } - let mut sorted_ids = sorted_ids.into_iter().dedup().peekable(); - if sorted_ids.peek() == Some(&ExcerptId::min()) { - sorted_ids.next(); - if let Some(mapping) = self.excerpt_ids.first() { - locators.push(mapping.locator.clone()); - } - } + let mut sorted_ids = sorted_ids.into_iter().peekable(); + locators.extend( + sorted_ids + .peeking_take_while(|excerpt| *excerpt == ExcerptId::min()) + .map(|_| Locator::min()), + ); let mut cursor = self.excerpt_ids.cursor::(()); for id in sorted_ids {