Fix picker new_path_prompt throwing "file exists" when saving (#21080)

Peter Tripp and Conrad Irwin created

Fix for getting File exists "os error 17" with `"use_system_path_prompts": false,`

This was reproducible when the first worktree is a non-folder worktree
(e.g. setting.json) so we were trying to create the new file with a path
under ~/.config/zed/settings.json/newfile.ext

Co-authored-by: Conrad Irwin <conrad@zed.dev>

Change summary

crates/file_finder/src/new_path_prompt.rs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

Detailed changes

crates/file_finder/src/new_path_prompt.rs 🔗

@@ -71,8 +71,16 @@ impl Match {
     fn project_path(&self, project: &Project, cx: &WindowContext) -> Option<ProjectPath> {
         let worktree_id = if let Some(path_match) = &self.path_match {
             WorktreeId::from_usize(path_match.worktree_id)
+        } else if let Some(worktree) = project.visible_worktrees(cx).find(|worktree| {
+            worktree
+                .read(cx)
+                .root_entry()
+                .is_some_and(|entry| entry.is_dir())
+        }) {
+            worktree.read(cx).id()
         } else {
-            project.worktrees(cx).next()?.read(cx).id()
+            // todo(): we should find_or_create a workspace.
+            return None;
         };
 
         let path = PathBuf::from(self.relative_path());