From 6d724a8f331f4b2a8f1a001e990cf6129dc50b00 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 23 Jan 2024 09:29:07 -0500 Subject: Re-export `which` from `helix-stdx::env` We use `which::which` in many crates, so `which` was a separate dependency across all of them. We can centralize `which` into the stdx crate so it's easy for all crates to depend on it. I also moved the rest of `helix-view/src/env.rs` into helix-stdx's `env` module since it only contained a thin wrapper around `which` and `std::env`. --- helix-view/Cargo.toml | 1 - helix-view/src/clipboard.rs | 4 ++-- helix-view/src/document.rs | 7 ++++++- helix-view/src/editor.rs | 4 ++-- helix-view/src/env.rs | 8 -------- helix-view/src/lib.rs | 1 - 6 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 helix-view/src/env.rs (limited to 'helix-view') diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 0dc18b37..2e689341 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -46,7 +46,6 @@ serde_json = "1.0" toml = "0.7" log = "~0.4" -which = "5.0.0" parking_lot = "0.12.1" diff --git a/helix-view/src/clipboard.rs b/helix-view/src/clipboard.rs index 812c803e..9ff2fd78 100644 --- a/helix-view/src/clipboard.rs +++ b/helix-view/src/clipboard.rs @@ -73,7 +73,7 @@ pub fn get_clipboard_provider() -> Box { #[cfg(target_os = "macos")] pub fn get_clipboard_provider() -> Box { - use crate::env::{binary_exists, env_var_is_set}; + use helix_stdx::env::{binary_exists, env_var_is_set}; if env_var_is_set("TMUX") && binary_exists("tmux") { command_provider! { @@ -98,7 +98,7 @@ pub fn get_clipboard_provider() -> Box { #[cfg(not(any(windows, target_os = "wasm32", target_os = "macos")))] pub fn get_clipboard_provider() -> Box { - use crate::env::{binary_exists, env_var_is_set}; + use helix_stdx::env::{binary_exists, env_var_is_set}; use provider::command::is_exit_success; // TODO: support for user-defined provider, probably when we have plugin support by setting a // variable? diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 388810b1..88653948 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -726,7 +726,12 @@ impl Document { if let Some((fmt_cmd, fmt_args)) = self .language_config() .and_then(|c| c.formatter.as_ref()) - .and_then(|formatter| Some((which::which(&formatter.command).ok()?, &formatter.args))) + .and_then(|formatter| { + Some(( + helix_stdx::env::which(&formatter.command).ok()?, + &formatter.args, + )) + }) { use std::process::Stdio; let text = self.text().clone(); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index fbfcb356..f605cbb5 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -329,7 +329,7 @@ pub struct TerminalConfig { #[cfg(windows)] pub fn get_terminal_provider() -> Option { - use crate::env::binary_exists; + use helix_stdx::env::binary_exists; if binary_exists("wt") { return Some(TerminalConfig { @@ -352,7 +352,7 @@ pub fn get_terminal_provider() -> Option { #[cfg(not(any(windows, target_os = "wasm32")))] pub fn get_terminal_provider() -> Option { - use crate::env::{binary_exists, env_var_is_set}; + use helix_stdx::env::{binary_exists, env_var_is_set}; if env_var_is_set("TMUX") && binary_exists("tmux") { return Some(TerminalConfig { diff --git a/helix-view/src/env.rs b/helix-view/src/env.rs deleted file mode 100644 index c68cc609..00000000 --- a/helix-view/src/env.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub fn binary_exists(binary_name: &str) -> bool { - which::which(binary_name).is_ok() -} - -#[cfg(not(windows))] -pub fn env_var_is_set(env_var_name: &str) -> bool { - std::env::var_os(env_var_name).is_some() -} diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index 82827b5d..14b6e1ce 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -5,7 +5,6 @@ pub mod base64; pub mod clipboard; pub mod document; pub mod editor; -pub mod env; pub mod events; pub mod graphics; pub mod gutter; -- cgit v1.2.3-70-g09d2