diff --git a/Cargo.lock b/Cargo.lock index 55d51bd..435d4be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -324,6 +324,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "flate2" version = "1.0.30" @@ -460,6 +470,15 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "ignore" version = "0.4.22" @@ -493,6 +512,7 @@ dependencies = [ "syntect", "test-case", "unicode-width", + "which", ] [[package]] @@ -565,6 +585,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "lock_api" version = "0.4.12" @@ -841,6 +867,19 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustversion" version = "1.0.17" @@ -1157,6 +1196,18 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "which" +version = "6.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ee928febd44d98f2f459a4a79bd4d928591333a494a10a868418ac1b39cf1f" +dependencies = [ + "either", + "home", + "rustix", + "winsafe", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1327,6 +1378,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/Cargo.toml b/Cargo.toml index 0581a99..41a4d24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ itertools = "0.13.0" anyhow = "1.0.83" strum = { version = "0.26.2", features = ["derive"] } syntect = "5.2.0" +which = "6.0.3" [dev-dependencies] lazy_static = "1.4.0" diff --git a/src/editor.rs b/src/editor.rs index bb7a1f2..731eb7d 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -4,7 +4,6 @@ use clap::ValueEnum; use itertools::Itertools; use std::{ fmt::{self, Debug, Display, Formatter}, - io, process::{Child, Command}, }; use strum::Display; @@ -87,10 +86,11 @@ impl EditorCommand { )) } - pub fn spawn(&self, file_name: &str, line_number: u64) -> io::Result { - let mut command = Command::new(self.program()); + pub fn spawn(&self, file_name: &str, line_number: u64) -> Result { + let path = which::which(self.program())?; + let mut command = Command::new(path); command.args(self.args(file_name, line_number)); - command.spawn() + command.spawn().map_err(anyhow::Error::from) } fn program(&self) -> &str { diff --git a/src/ig.rs b/src/ig.rs index 51ea531..7a7e998 100644 --- a/src/ig.rs +++ b/src/ig.rs @@ -4,7 +4,6 @@ mod search_config; mod searcher; mod sink; -use std::io; use std::process::ExitStatus; use std::sync::mpsc; @@ -43,9 +42,9 @@ impl Ig { } } - fn try_spawn_editor(&self, file_name: &str, line_number: u64) -> io::Result { + fn try_spawn_editor(&self, file_name: &str, line_number: u64) -> anyhow::Result { let mut editor_process = self.editor_command.spawn(file_name, line_number)?; - editor_process.wait() + editor_process.wait().map_err(anyhow::Error::from) } pub fn open_file_if_requested(&mut self, selected_entry: Option<(String, u64)>) {