From 089ce8f6aa1e6534d71fd1eeab800f069d81c755 Mon Sep 17 00:00:00 2001 From: Max Frai Date: Fri, 11 Jul 2025 02:43:52 +0200 Subject: [PATCH] agent: Allow clicking on the read file tool header to jump to the exact file location (#33161) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Release Notes: - Allow clicking on the header of the read file tool to jump to the exact file location When researching code or when the Agent analyzes context by reading various project files, the read file tool is used. It usually includes line numbers relevant to the current prompt or task. However, it’s often frustrating that the read file header isn’t clickable to view the corresponding code directly. This PR makes the header clickable, allowing users to jump to the referenced file. If start and end lines are specified, it will navigate directly to that exact location. https://github.com/user-attachments/assets/b0125d0b-7166-43dd-924e-dc5585813b0b Co-authored-by: Danilo Leal --- crates/assistant_tools/src/read_file_tool.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/assistant_tools/src/read_file_tool.rs b/crates/assistant_tools/src/read_file_tool.rs index 5b95469817..6bbc2fc089 100644 --- a/crates/assistant_tools/src/read_file_tool.rs +++ b/crates/assistant_tools/src/read_file_tool.rs @@ -18,7 +18,6 @@ use serde::{Deserialize, Serialize}; use settings::Settings; use std::sync::Arc; use ui::IconName; -use util::markdown::MarkdownInlineCode; /// If the model requests to read a file whose size exceeds this, then #[derive(Debug, Serialize, Deserialize, JsonSchema)] @@ -78,11 +77,21 @@ impl Tool for ReadFileTool { fn ui_text(&self, input: &serde_json::Value) -> String { match serde_json::from_value::(input.clone()) { Ok(input) => { - let path = MarkdownInlineCode(&input.path); + let path = &input.path; match (input.start_line, input.end_line) { - (Some(start), None) => format!("Read file {path} (from line {start})"), - (Some(start), Some(end)) => format!("Read file {path} (lines {start}-{end})"), - _ => format!("Read file {path}"), + (Some(start), Some(end)) => { + format!( + "[Read file `{}` (lines {}-{})](@selection:{}:({}-{}))", + path, start, end, path, start, end + ) + } + (Some(start), None) => { + format!( + "[Read file `{}` (from line {})](@selection:{}:({}-{}))", + path, start, path, start, start + ) + } + _ => format!("[Read file `{}`](@file:{})", path, path), } } Err(_) => "Read file".to_string(),