From f19d0f0b982c08bfb5610805b555469071c3d2a9 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 28 Aug 2024 14:42:00 -0600 Subject: [PATCH] Fix OpenPathPrompt locally with tilde (#17027) Release Notes: - Fixed a panic opening a file in ~/ with `use_system_prompts: false` --- crates/file_finder/src/open_path_prompt.rs | 7 ++++++- crates/project/src/project.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/file_finder/src/open_path_prompt.rs b/crates/file_finder/src/open_path_prompt.rs index 3a6522f308..2628fe81ce 100644 --- a/crates/file_finder/src/open_path_prompt.rs +++ b/crates/file_finder/src/open_path_prompt.rs @@ -236,7 +236,12 @@ impl PickerDelegate for OpenPathDelegate { let Some(candidate) = directory_state.match_candidates.get(*m) else { return; }; - let result = Path::new(&directory_state.path).join(&candidate.string); + let result = Path::new( + self.lister + .resolve_tilde(&directory_state.path, cx) + .as_ref(), + ) + .join(&candidate.string); if let Some(tx) = self.tx.take() { tx.send(Some(vec![result])).ok(); } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 7ef29926fd..981ee5da14 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -664,6 +664,14 @@ impl DirectoryLister { } } + pub fn resolve_tilde<'a>(&self, path: &'a String, cx: &AppContext) -> Cow<'a, str> { + if self.is_local(cx) { + shellexpand::tilde(path) + } else { + Cow::from(path) + } + } + pub fn default_query(&self, cx: &mut AppContext) -> String { if let DirectoryLister::Project(project) = self { if let Some(worktree) = project.read(cx).visible_worktrees(cx).next() {