Skip to content

Commit 12acc1d

Browse files
VeykrilConradIrwin
authored andcommitted
acp_thread: Fix panic when following acp agents across buffers (#40798)
Fixes ZED-2D7 Release Notes: - N/A *or* Added/Fixed/Improved ...
1 parent 34a35b8 commit 12acc1d

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

crates/acp_thread/src/acp_thread.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,15 +1421,18 @@ impl AcpThread {
14211421

14221422
if let Some(Some(location)) = resolved_locations.last() {
14231423
project.update(cx, |project, cx| {
1424-
let should_ignore = if let Some(agent_location) = project.agent_location() {
1424+
let should_ignore = if let Some(agent_location) = project
1425+
.agent_location()
1426+
.filter(|agent_location| agent_location.buffer == location.buffer)
1427+
{
14251428
let snapshot = location.buffer.read(cx).snapshot();
14261429
let old_position = agent_location.position.to_point(&snapshot);
14271430
let new_position = location.position.to_point(&snapshot);
1428-
agent_location.buffer == location.buffer
1429-
// ignore this so that when we get updates from the edit tool
1430-
// the position doesn't reset to the startof line
1431-
&& (old_position.row == new_position.row
1432-
&& old_position.column > new_position.column)
1431+
1432+
// ignore this so that when we get updates from the edit tool
1433+
// the position doesn't reset to the startof line
1434+
old_position.row == new_position.row
1435+
&& old_position.column > new_position.column
14331436
} else {
14341437
false
14351438
};

crates/multi_buffer/src/multi_buffer.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6165,22 +6165,20 @@ impl MultiBufferSnapshot {
61656165
) -> SmallVec<[Locator; 1]> {
61666166
let mut sorted_ids = ids.into_iter().collect::<SmallVec<[_; 1]>>();
61676167
sorted_ids.sort_unstable();
6168+
sorted_ids.dedup();
61686169
let mut locators = SmallVec::new();
61696170

61706171
while sorted_ids.last() == Some(&ExcerptId::max()) {
61716172
sorted_ids.pop();
6172-
if let Some(mapping) = self.excerpt_ids.last() {
6173-
locators.push(mapping.locator.clone());
6174-
}
6173+
locators.push(Locator::max());
61756174
}
61766175

6177-
let mut sorted_ids = sorted_ids.into_iter().dedup().peekable();
6178-
if sorted_ids.peek() == Some(&ExcerptId::min()) {
6179-
sorted_ids.next();
6180-
if let Some(mapping) = self.excerpt_ids.first() {
6181-
locators.push(mapping.locator.clone());
6182-
}
6183-
}
6176+
let mut sorted_ids = sorted_ids.into_iter().peekable();
6177+
locators.extend(
6178+
sorted_ids
6179+
.peeking_take_while(|excerpt| *excerpt == ExcerptId::min())
6180+
.map(|_| Locator::min()),
6181+
);
61846182

61856183
let mut cursor = self.excerpt_ids.cursor::<ExcerptId>(());
61866184
for id in sorted_ids {

0 commit comments

Comments
 (0)