From a8a05f208bea3f760e702c084c70dad7ee33a5f8 Mon Sep 17 00:00:00 2001 From: Maksim Bondarenkov <119937608+ognevny@users.noreply.github.com> Date: Sat, 1 Mar 2025 19:17:55 +0300 Subject: [PATCH] cli: Add extra paths in `detect()` on Windows (#25765) I'm already integrating CLI into MSYS2 package, and this patche helped me to make it work like in Arch: https://github.com/msys2/MINGW-packages/pull/23537. used the same way as in [Linux implementation](https://github.com/zed-industries/zed/blob/6856e869fcb8fd2e164a2c43b42ac5046f1d7ea8/crates/cli/src/main.rs#L314) Closes #ISSUE Release Notes: - N/A --- crates/cli/src/main.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index b74a72b63c..bf87ec92d3 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -614,12 +614,19 @@ mod windows { let path = if let Some(path) = path { path.to_path_buf().canonicalize()? } else { - std::env::current_exe()? - .parent() - .context("no parent path for cli")? - .parent() - .context("no parent path for cli folder")? - .join("Zed.exe") + let cli = std::env::current_exe()?; + let dir = cli.parent().context("no parent path for cli")?; + + // ../Zed.exe is the standard, lib/zed is for MSYS2, ./zed.exe is for the target + // directory in development builds. + let possible_locations = ["../Zed.exe", "../lib/zed/zed-editor.exe", "./zed.exe"]; + possible_locations + .iter() + .find_map(|p| dir.join(p).canonicalize().ok().filter(|path| path != &cli)) + .context(format!( + "could not find any of: {}", + possible_locations.join(", ") + ))? }; Ok(App(path))