agent: Allow clicking on the read file tool header to jump to the exact file location (#33161)
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 <daniloleal09@gmail.com>
This commit is contained in:
parent
842ac984d5
commit
089ce8f6aa
1 changed files with 14 additions and 5 deletions
|
@ -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::<ReadFileToolInput>(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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue