fix: Open editor on windows (#476)

This commit is contained in:
Solomon
2025-08-14 18:44:27 +01:00
committed by GitHub
parent 9b4ca9dc45
commit 605ac4a9ba
3 changed files with 25 additions and 1 deletions

View File

@@ -334,7 +334,23 @@ impl EditorConfig {
} }
pub fn open_file(&self, path: &str) -> Result<(), std::io::Error> { 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]); let mut cmd = std::process::Command::new(&command[0]);
for arg in &command[1..] { for arg in &command[1..] {
cmd.arg(arg); cmd.arg(arg);

View File

@@ -28,3 +28,4 @@ tokio = { workspace = true }
futures = "0.3.31" futures = "0.3.31"
tokio-stream = { version = "0.1.17", features = ["sync"] } tokio-stream = { version = "0.1.17", features = ["sync"] }
shellexpand = "3.1.1" shellexpand = "3.1.1"
which = "8.0.0"

View File

@@ -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<String> {
which::which(executable)
.ok()
.map(|p| p.to_string_lossy().to_string())
}