From 9f26e50f0633238a275b25ca9e23b5f92476a37a Mon Sep 17 00:00:00 2001 From: Calvin Kosmatka Date: Sat, 26 Dec 2020 23:34:14 -0600 Subject: [PATCH] Fix --wsl option (#404) * use wsl nvim * use piped stderr for release build --- src/bridge/mod.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 7fab44b..3567201 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -29,16 +29,14 @@ fn set_windows_creation_flags(cmd: &mut Command) { #[cfg(windows)] fn platform_build_nvim_cmd(bin: &str) -> Option { - if !Path::new(&bin).exists() { - return None; - } - if env::args().any(|arg| arg == "--wsl") { let mut cmd = Command::new("wsl"); cmd.arg(bin); Some(cmd) - } else { + } else if Path::new(&bin).exists() { Some(Command::new(bin)) + } else { + None } } @@ -59,6 +57,23 @@ fn build_nvim_cmd() -> Command { warn!("NEOVIM_BIN is invalid falling back to first bin in PATH"); } } + #[cfg(windows)] + if env::args().any(|arg| arg == "--wsl") { + if let Ok(output) = std::process::Command::new("wsl").arg("which").arg("nvim").output() { + if output.status.success() { + let path = String::from_utf8(output.stdout).unwrap(); + let mut cmd = Command::new("wsl"); + cmd.arg(path.trim()); + return cmd; + } else { + error!("nvim not found in WSL path"); + std::process::exit(1); + } + } else { + error!("wsl which nvim failed"); + std::process::exit(1); + } + } if let Ok(path) = which::which("nvim") { if let Some(cmd) = platform_build_nvim_cmd(path.to_str().unwrap()) { cmd @@ -95,8 +110,13 @@ pub fn create_nvim_command() -> Command { let mut cmd = build_nvim_cmd(); cmd.arg("--embed") - .args(SETTINGS.neovim_arguments.iter().skip(1)) - .stderr(Stdio::inherit()); + .args(SETTINGS.neovim_arguments.iter().skip(1)); + + #[cfg(not(debug_assertions))] + cmd.stderr(Stdio::piped()); + + #[cfg(debug_assertions)] + cmd.stderr(Stdio::inherit()); #[cfg(windows)] set_windows_creation_flags(&mut cmd);