From d031260180cf87dd713438f6bb1a6e7879dbb613 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 19 Feb 2025 10:16:45 -0500 Subject: [PATCH] Avoid cloning configured env vars when starting a language server The clone of the hashmap can be avoided by passing a ref instead. This commit also changes the `server_environment` type to match the bounds expected by `Command::envs` - this will avoid future refactoring if the underlying type changes (for example switching to `hashbrown::HashMap`). --- helix-lsp/src/client.rs | 13 ++++++++----- helix-lsp/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 3a50f20a..d6308997 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -16,11 +16,14 @@ use helix_stdx::path; use parking_lot::Mutex; use serde::Deserialize; use serde_json::Value; -use std::sync::{ - atomic::{AtomicU64, Ordering}, - Arc, -}; use std::{collections::HashMap, path::PathBuf}; +use std::{ + ffi::OsStr, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, +}; use std::{future::Future, sync::OnceLock}; use std::{path::Path, process::Stdio}; use tokio::{ @@ -178,7 +181,7 @@ impl Client { cmd: &str, args: &[String], config: Option, - server_environment: HashMap, + server_environment: impl IntoIterator, impl AsRef)>, root_path: PathBuf, root_uri: Option, id: LanguageServerId, diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 5eeea81c..df57bbe8 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -871,7 +871,7 @@ fn start_client( &ls_config.command, &ls_config.args, ls_config.config.clone(), - ls_config.environment.clone(), + &ls_config.environment, root_path, root_uri, id,