From dc63138089dd3d2b6d5995c585206c63a6cf2b4b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 7 Jun 2025 02:04:49 +0300 Subject: [PATCH] Use proper paths when determining file finder icons for external files (#32274) Before: before After: after Release Notes: - N/A --- crates/file_finder/src/file_finder.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 1329f9073f..bfdb8fc4f4 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -459,7 +459,7 @@ enum Match { } impl Match { - fn path(&self) -> Option<&Arc> { + fn relative_path(&self) -> Option<&Arc> { match self { Match::History { path, .. } => Some(&path.project.path), Match::Search(panel_match) => Some(&panel_match.0.path), @@ -467,6 +467,26 @@ impl Match { } } + fn abs_path(&self, project: &Entity, cx: &App) -> Option { + match self { + Match::History { path, .. } => path.absolute.clone().or_else(|| { + project + .read(cx) + .worktree_for_id(path.project.worktree_id, cx)? + .read(cx) + .absolutize(&path.project.path) + .ok() + }), + Match::Search(ProjectPanelOrdMatch(path_match)) => project + .read(cx) + .worktree_for_id(WorktreeId::from_usize(path_match.worktree_id), cx)? + .read(cx) + .absolutize(&path_match.path) + .ok(), + Match::CreateNew(_) => None, + } + } + fn panel_match(&self) -> Option<&ProjectPanelOrdMatch> { match self { Match::History { panel_match, .. } => panel_match.as_ref(), @@ -501,7 +521,7 @@ impl Matches { // reason for the matches set to change. self.matches .iter() - .position(|m| match m.path() { + .position(|m| match m.relative_path() { Some(p) => path.project.path == *p, None => false, }) @@ -1570,7 +1590,8 @@ impl PickerDelegate for FileFinderDelegate { if !settings.file_icons { return None; } - let file_name = path_match.path()?.file_name()?; + let abs_path = path_match.abs_path(&self.project, cx)?; + let file_name = abs_path.file_name()?; let icon = FileIcons::get_icon(file_name.as_ref(), cx)?; Some(Icon::from_path(icon).color(Color::Muted)) });