use std::path::PathBuf;
use std::sync::Mutex;
use std::sync::OnceLock;
use super::manager::ConfigManager;
static EXPLICIT_CONFIG_PATH: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
fn cell() -> &'static Mutex<Option<PathBuf>> {
EXPLICIT_CONFIG_PATH.get_or_init(|| Mutex::new(None))
}
pub fn set_explicit_config_path(path: Option<PathBuf>) {
{
let mut guard = cell().lock().unwrap_or_else(|poisoned| poisoned.into_inner());
*guard = path;
}
ConfigManager::invalidate_all_workspace_cache();
}
pub fn explicit_config_path() -> Option<PathBuf> {
let guard = cell().lock().unwrap_or_else(|poisoned| poisoned.into_inner());
guard.clone()
}
#[cfg(test)]
pub(crate) struct ExplicitConfigPathGuard {
previous: Option<PathBuf>,
}
#[cfg(test)]
impl ExplicitConfigPathGuard {
pub(crate) fn set(path: Option<PathBuf>) -> Self {
let previous = explicit_config_path();
set_explicit_config_path(path);
Self { previous }
}
}
#[cfg(test)]
impl Drop for ExplicitConfigPathGuard {
fn drop(&mut self) {
set_explicit_config_path(self.previous.take());
}
}