From b7b4e95ca97cc29933dd70f34c4274229a9b0d95 Mon Sep 17 00:00:00 2001 From: j4qfrost Date: Mon, 11 May 2020 00:18:13 -0700 Subject: [PATCH] Add search for nvim in PATH (#279) * add search for nvim * need suggestions for error message --- Cargo.lock | 39 +++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/bridge/mod.rs | 11 +++++++---- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98723e5..05254ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,28 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +[[package]] +name = "backtrace" +version = "0.3.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e" +dependencies = [ + "backtrace-sys", + "cfg-if", + "libc", + "rustc-demangle", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "base64" version = "0.11.0" @@ -652,6 +674,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "failure" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" +dependencies = [ + "backtrace", +] + [[package]] name = "filetime" version = "0.2.9" @@ -1309,6 +1340,7 @@ dependencies = [ "skulpin", "tokio", "unicode-segmentation", + "which", "winapi 0.3.8", "winres", ] @@ -1843,6 +1875,12 @@ dependencies = [ "walkdir", ] +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -2468,6 +2506,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" dependencies = [ + "failure", "libc", ] diff --git a/Cargo.toml b/Cargo.toml index 67092ba..ea8f367 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ flexi_logger = { version = "0.14.6", default-features = false } anyhow = "1.0.26" parking_lot="0.10.0" cfg-if = "0.1.10" +which = "3.1" [dev-dependencies] mockall = "0.7.0" diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 8dac6b9..90c598c 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -65,10 +65,13 @@ fn platform_build_nvim_cmd(bin: &str) -> Command { } fn build_nvim_cmd() -> Command { - let key = "NEOVIM_BIN"; - match std::env::var_os(key) { - Some(path) => platform_build_nvim_cmd(&path.to_string_lossy()), - None => platform_build_nvim_cmd("nvim"), + if let Some(path) = std::env::var_os("NEOVIM_BIN") { + platform_build_nvim_cmd(&path.to_string_lossy()) + } else if let Ok(path) = which::which("nvim") { + platform_build_nvim_cmd(path.to_str().unwrap()) + } else { + error!("nvim not found!"); + std::process::exit(1); } }