Skip to content

Commit e34a745

Browse files
committed
resolve path from env
1 parent 92044b5 commit e34a745

File tree

1 file changed

+18
-1
lines changed
  • crates/code_analysis/src/config

1 file changed

+18
-1
lines changed

crates/code_analysis/src/config/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use configs::{
1414
EmmyrcStrict, EmmyrcWorkspace,
1515
};
1616
use emmylua_parser::{LuaLanguageLevel, ParserConfig};
17+
use regex::Regex;
1718
use rowan::NodeCache;
1819
use schemars::JsonSchema;
1920
use serde::{Deserialize, Serialize};
@@ -118,6 +119,22 @@ fn pre_process_path(path: &str, workspace: &PathBuf) -> String {
118119
.to_string();
119120
}
120121

121-
path = path.replace("${workspaceFolder}", &workspace.to_string_lossy());
122+
path = path.replace("$", "");
123+
path = replace_placeholders(&path, workspace.to_str().unwrap());
122124
path
123125
}
126+
127+
fn replace_placeholders(input: &str, workspace_folder: &str) -> String {
128+
let re = Regex::new(r"\{([^}]+)\}").unwrap();
129+
re.replace_all(input, |caps: &regex::Captures| {
130+
let key = &caps[1];
131+
if key == "workspaceFolder" {
132+
workspace_folder.to_string()
133+
} else if let Some(env_name) = key.strip_prefix("env:") {
134+
std::env::var(env_name).unwrap_or_default()
135+
} else {
136+
caps[0].to_string()
137+
}
138+
})
139+
.to_string()
140+
}

0 commit comments

Comments
 (0)