From 605ac4a9baaabc8aa785cb10180a396191d7a76e Mon Sep 17 00:00:00 2001 From: Solomon Date: Thu, 14 Aug 2025 18:44:27 +0100 Subject: [PATCH] fix: Open editor on windows (#476) --- .../src/services/config/versions/v2.rs | 18 +++++++++++++++++- crates/utils/Cargo.toml | 1 + crates/utils/src/shell.rs | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/services/src/services/config/versions/v2.rs b/crates/services/src/services/config/versions/v2.rs index 209724c3..fa6a8288 100644 --- a/crates/services/src/services/config/versions/v2.rs +++ b/crates/services/src/services/config/versions/v2.rs @@ -334,7 +334,23 @@ impl EditorConfig { } pub fn open_file(&self, path: &str) -> Result<(), std::io::Error> { - let command = self.get_command(); + let mut command = self.get_command(); + + if command.is_empty() { + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "No editor command configured", + )); + } + + if cfg!(windows) { + command[0] = + utils::shell::resolve_executable_path(&command[0]).ok_or(std::io::Error::new( + std::io::ErrorKind::NotFound, + format!("Editor command '{}' not found", command[0]), + ))?; + } + let mut cmd = std::process::Command::new(&command[0]); for arg in &command[1..] { cmd.arg(arg); diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index b6f0fff0..f367b840 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -28,3 +28,4 @@ tokio = { workspace = true } futures = "0.3.31" tokio-stream = { version = "0.1.17", features = ["sync"] } shellexpand = "3.1.1" +which = "8.0.0" diff --git a/crates/utils/src/shell.rs b/crates/utils/src/shell.rs index e14273e6..9e36719f 100644 --- a/crates/utils/src/shell.rs +++ b/crates/utils/src/shell.rs @@ -17,3 +17,10 @@ pub fn get_shell_command() -> (&'static str, &'static str) { } } } + +/// Resolves the full path of an executable using the system's PATH environment variable. +pub fn resolve_executable_path(executable: &str) -> Option { + which::which(executable) + .ok() + .map(|p| p.to_string_lossy().to_string()) +}