agent: Make read_file and edit_file tool call titles more specific (#37639)

For read_file and edit_file, show the worktree-relative path if there's
only one visible worktree, and the "full path" otherwise. Also restores
the display of line numbers for read_file calls.

Release Notes:

- N/A
This commit is contained in:
Cole Miller
2025-09-08 12:57:22 -04:00
committed by GitHub
parent a66cd820b3
commit 5f01f6d75f
22 changed files with 393 additions and 173 deletions
+17
View File
@@ -4497,6 +4497,23 @@ impl Project {
None
}
/// If there's only one visible worktree, returns the given worktree-relative path with no prefix.
///
/// Otherwise, returns the full path for the project path (obtained by prefixing the worktree-relative path with the name of the worktree).
pub fn short_full_path_for_project_path(
&self,
project_path: &ProjectPath,
cx: &App,
) -> Option<PathBuf> {
if self.visible_worktrees(cx).take(2).count() < 2 {
return Some(project_path.path.to_path_buf());
}
self.worktree_for_id(project_path.worktree_id, cx)
.and_then(|worktree| {
Some(Path::new(worktree.read(cx).abs_path().file_name()?).join(&project_path.path))
})
}
pub fn project_path_for_absolute_path(&self, abs_path: &Path, cx: &App) -> Option<ProjectPath> {
self.find_worktree(abs_path, cx)
.map(|(worktree, relative_path)| ProjectPath {