Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Number ACP tool call location lines from 1 (#66110)
Ben Brandt23973bd49f28
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rsindex bf7d2d25c8c..f4de697becd 100644--- a/crates/acp_thread/src/acp_thread.rs+++ b/crates/acp_thread/src/acp_thread.rs@@ -1850,7 +1850,8 @@ impl ToolCall {let buffer = buffer.await.log_err()?;let position = buffer.update(cx, |buffer, _| {let snapshot = buffer.snapshot();- if let Some(row) = location.line {+ if let Some(line) = location.line {+ let row = line.saturating_sub(1);let column = snapshot.indent_size_for_line(row).len;let point = snapshot.clip_point(Point::new(row, column), Bias::Left);snapshot.anchor_before(point)@@ -17932,7 +17933,7 @@ mod tests {let fs = FakeFs::new(cx.executor());fs.insert_tree(path!("/tmp/skills/test-skill"),- json!({ "SKILL.md": "skill body" }),+ json!({ "SKILL.md": "skill body\nsecond line" }),).await;let project = Project::test(fs, [], cx).await;@@ -17952,7 +17953,9 @@ mod tests {acp_v1::ToolCall::new("write_file", "Write SKILL.md").kind(acp_v1::ToolKind::Edit).status(acp_v1::ToolCallStatus::Completed)- .locations(vec![acp_v1::ToolCallLocation::new(skill_path.clone())]),+ .locations(vec![+ acp_v1::ToolCallLocation::new(skill_path.clone()).line(2),+ ]),),cx,)@@ -17971,7 +17974,15 @@ mod tests {.buffer.upgrade().expect("resolved location should keep an open buffer");- assert_eq!(buffer.read(cx).text(), "skill body");+ assert_eq!(buffer.read(cx).text(), "skill body\nsecond line");+ // ACP numbers lines from 1, so line 2 is the buffer's second row.+ assert_eq!(+ agent_location+ .position+ .to_point(&buffer.read(cx).snapshot())+ .row,+ 1+ );});}diff --git a/crates/agent/src/tools/edit_session.rs b/crates/agent/src/tools/edit_session.rsindex aaf2251b537..c21a9004d7c 100644--- a/crates/agent/src/tools/edit_session.rs+++ b/crates/agent/src/tools/edit_session.rs@@ -527,8 +527,11 @@ impl EditPipeline {let snapshot = buffer.read_with(cx, |buffer, _cx| buffer.snapshot());let line = snapshot.offset_to_point(range.start).row;+ // ACP numbers lines from 1.event_stream.update_fields(|update| {- update.locations(vec![acp::ToolCallLocation::new(abs_path).line(Some(line))])+ update.locations(vec![+ acp::ToolCallLocation::new(abs_path).line(Some(line + 1)),+ ])});let buffer_indent = snapshot.line_indent_for_row(line);diff --git a/crates/agent/src/tools/grep_tool.rs b/crates/agent/src/tools/grep_tool.rsindex eed142de9f7..2227e17de59 100644--- a/crates/agent/src/tools/grep_tool.rs+++ b/crates/agent/src/tools/grep_tool.rs@@ -355,7 +355,9 @@ impl AgentTool for GrepTool {)),));locations.push(- acp::ToolCallLocation::new(abs_path.clone()).line(Some(range.start.row)),+ // ACP numbers lines from 1.+ acp::ToolCallLocation::new(abs_path.clone())+ .line(Some(range.start.row + 1)),);}// Use a fence longer than any backtick run in the snippet so@@ -677,14 +679,14 @@ mod tests {);// Each match also reports a location so the panel can reveal the file at- // the matched (0-based) row.+ // the matched line, numbered from 1 as ACP numbers lines.let locations = update.locations.take().expect("expected locations");assert_eq!(locations.len(), 2);assert!(locations.iter().any(|location| {location.path.0.to_string_lossy().replace('\\', "/")== path!("/root/src/alpha.txt").replace('\\', "/")- && location.line == Some(0)+ && location.line == Some(1)}),"missing location for alpha.txt, got: {locations:?}");@@ -692,7 +694,7 @@ mod tests {locations.iter().any(|location| {location.path.0.to_string_lossy().replace('\\', "/")== path!("/root/beta.txt").replace('\\', "/")- && location.line == Some(0)+ && location.line == Some(1)}),"missing location for beta.txt, got: {locations:?}");diff --git a/crates/agent/src/tools/read_file_tool.rs b/crates/agent/src/tools/read_file_tool.rsindex 82f74df7cc0..875e1bb9eff 100644--- a/crates/agent/src/tools/read_file_tool.rs+++ b/crates/agent/src/tools/read_file_tool.rs@@ -112,7 +112,7 @@ async fn read_global_skill_file(event_stream.update_fields(|update| {update.locations(vec![acp::ToolCallLocation::new(canonical_path.to_path_buf())- .line(start_line.map(|line| line.saturating_sub(1))),+ .line(start_line.map(|line| line.max(1))),])});@@ -358,7 +358,7 @@ impl AgentTool for ReadFileTool {cx.update(|_cx| {event_stream.update_fields(|update| update.locations(vec![acp::ToolCallLocation::new(abs_path.clone())- .line(input.start_line.map(|line| line.saturating_sub(1))),+ .line(input.start_line.map(|line| line.max(1))),]));});diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rsindex b6d1286200f..aa4ff2280a3 100644--- a/crates/agent_ui/src/conversation_view/thread_view.rs+++ b/crates/agent_ui/src/conversation_view/thread_view.rs@@ -11480,7 +11480,10 @@ impl ThreadView {selections.select_anchor_ranges([anchor..anchor]);})} else {- let row = tool_call_location.line.unwrap_or_default();+ // ACP numbers lines from 1; editor rows start at 0.+ let row = tool_call_location+ .line+ .map_or(0, |line| line.saturating_sub(1));editor.change_selections(Default::default(), window, cx, |selections| {selections.select_ranges([Point::new(row, 0)..Point::new(row, 0)]);})