use super::Expression;
use std::cell::RefCell;
use std::collections::HashMap;
thread_local! {
static ALIAS_MAP: RefCell<HashMap<String, Expression>> = RefCell::new(HashMap::new());
}
pub fn set_alias(name: String, expression: Expression) {
ALIAS_MAP.with(|map| {
map.borrow_mut().insert(name, expression);
});
}
pub fn get_alias(name: &str) -> Option<Expression> {
ALIAS_MAP.with(|map| map.borrow().get(name).cloned())
}
pub fn get_alias_completion(prefix: &str) -> Vec<String> {
ALIAS_MAP.with(|map| {
map.borrow()
.keys()
.filter(|m| m.starts_with(prefix))
.map(|k| k.to_string())
.collect::<Vec<_>>()
})
}