From d09b7d7880e0c9eb0aba9ed099ea15d08bf7bc7c Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Fri, 24 Apr 2026 18:01:38 -0400 Subject: [PATCH 1/2] perf(code_analysis:config): avoid allocs --- .../emmylua_code_analysis/src/config/pre_process.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/emmylua_code_analysis/src/config/pre_process.rs b/crates/emmylua_code_analysis/src/config/pre_process.rs index 681d4c4e0..e38db17ff 100644 --- a/crates/emmylua_code_analysis/src/config/pre_process.rs +++ b/crates/emmylua_code_analysis/src/config/pre_process.rs @@ -1,5 +1,5 @@ use regex::Regex; -use std::{collections::HashSet, path::PathBuf, process::Command}; +use std::{borrow::Cow, collections::HashSet, path::PathBuf, process::Command}; use crate::config::configs::{EmmyrcWorkspacePathConfig, EmmyrcWorkspacePathItem}; @@ -60,10 +60,9 @@ impl PreProcessContext { } fn pre_process_path(&self, path: &str) -> String { - let mut path = path.to_string(); - path = self.replace_env_var(&path); + let path = self.replace_env_var(path); // ${workspaceFolder} == {workspaceFolder} - path = path.replace("$", ""); + let mut path = path.replace("$", ""); // ideally, this should be `Cow` let workspace_str = match self.workspace.to_str() { Some(path) => path, None => { @@ -129,10 +128,10 @@ impl PreProcessContext { } // compact luals - fn replace_env_var(&self, path: &str) -> String { + fn replace_env_var<'a>(&self, path: &'a str) -> Cow<'a, str> { let re = match &self.env_var_regex { Some(re) => re, - None => return path.to_string(), + None => return Cow::Borrowed(path), }; re.replace_all(path, |caps: ®ex::Captures| { let key = &caps[1]; @@ -141,7 +140,6 @@ impl PreProcessContext { String::new() }) }) - .to_string() } fn replace_placeholders(&self, input: &str, workspace_folder: &str) -> String { From ca8cc08c0e4d05cf0dafe571095fa462e8f2aff5 Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Wed, 14 Jan 2026 14:19:11 -0400 Subject: [PATCH 2/2] fix(code_analysis:config): strict tilde match --- .../src/config/pre_process.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/emmylua_code_analysis/src/config/pre_process.rs b/crates/emmylua_code_analysis/src/config/pre_process.rs index e38db17ff..3114bdd65 100644 --- a/crates/emmylua_code_analysis/src/config/pre_process.rs +++ b/crates/emmylua_code_analysis/src/config/pre_process.rs @@ -73,24 +73,18 @@ impl PreProcessContext { path = self.replace_placeholders(&path, workspace_str); - if path.starts_with('~') { + if let Some(suffix) = path.strip_prefix("~/") { let home_dir = match dirs::home_dir() { - Some(path) => path, + Some(h) => h, None => { log::error!("Warning: Home directory not found"); return path; } }; - path = home_dir.join(&path[2..]).to_string_lossy().to_string(); - } else if path.starts_with("./") { - path = self - .workspace - .join(&path[2..]) - .to_string_lossy() - .to_string(); - } else if PathBuf::from(&path).is_absolute() { - path = path.to_string(); - } else { + path = home_dir.join(suffix).to_string_lossy().to_string(); + } else if let Some(suffix) = path.strip_prefix("./") { + path = self.workspace.join(suffix).to_string_lossy().to_string(); + } else if !PathBuf::from(&path).is_absolute() { path = self.workspace.join(&path).to_string_lossy().to_string(); }