aboutsummaryrefslogtreecommitdiff
path: root/src/lisp/eval.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp/eval.rs')
-rw-r--r--src/lisp/eval.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lisp/eval.rs b/src/lisp/eval.rs
index b39730b..784cba0 100644
--- a/src/lisp/eval.rs
+++ b/src/lisp/eval.rs
@@ -20,6 +20,15 @@ pub struct Evaluator<'ctx, 'global> {
20 pub context: Context, 20 pub context: Context,
21} 21}
22 22
23impl<'ctx, 'global> Evaluator<'ctx, 'global> {
24 pub fn new(app: &'global mut AppState<'ctx>) -> Self {
25 Self {
26 app,
27 context: Vec::new(),
28 }
29 }
30}
31
23impl<'ctx, 'global> Evaluator<'ctx, 'global> 32impl<'ctx, 'global> Evaluator<'ctx, 'global>
24where 33where
25 'ctx: 'global, 34 'ctx: 'global,
@@ -337,6 +346,25 @@ pub fn lookup(env_list: &[Environment], key: &str) -> Result<LispExpr, LispError
337 } 346 }
338} 347}
339 348
349pub fn completions<'a>(env_list: &'a [Environment], prefix: &str) -> Vec<&'a str> {
350 fn helper<'h>(env_list: &'h [Environment], prefix: &str, completions: &mut Vec<Vec<&'h str>>) {
351 if !env_list.is_empty() {
352 let nearest_env = env_list.last().unwrap();
353 completions.push(
354 nearest_env
355 .keys()
356 .filter(|k| k.starts_with(prefix))
357 .map(|s| &s[prefix.len()..])
358 .collect::<Vec<_>>(),
359 );
360 helper(&env_list[..env_list.len() - 1], prefix, completions);
361 }
362 }
363 let mut completions = Vec::new();
364 helper(env_list, prefix, &mut completions);
365 completions.into_iter().flatten().collect()
366}
367
340#[cfg(test)] 368#[cfg(test)]
341mod tests { 369mod tests {
342 use super::*; 370 use super::*;