From 27a15a2464835a5ae015b04c0a9ce1c3a42ee576 Mon Sep 17 00:00:00 2001 From: Euan Lacy Date: Wed, 11 May 2022 21:37:03 +0100 Subject: [PATCH] wip: add more atoms to completion list --- build/static_string_indexing.rs | 2 +- src/repl_helper.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/build/static_string_indexing.rs b/build/static_string_indexing.rs index 390c5405..6f57b37f 100644 --- a/build/static_string_indexing.rs +++ b/build/static_string_indexing.rs @@ -170,7 +170,7 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea #((#static_strs) => { Atom { index: #indices_iter } };)* } - static STATIC_ATOMS_MAP: phf::Map<&'static str, Atom> = phf::phf_map! { + pub static STATIC_ATOMS_MAP: phf::Map<&'static str, Atom> = phf::phf_map! { #(#static_strs => { Atom { index: #indices } },)* }; } diff --git a/src/repl_helper.rs b/src/repl_helper.rs index 91347020..21dc9800 100644 --- a/src/repl_helper.rs +++ b/src/repl_helper.rs @@ -5,7 +5,7 @@ use rustyline::validate::Validator; use rustyline::highlight::{MatchingBracketHighlighter, Highlighter}; use rustyline::{Helper as RlHelper, Result, Context}; -use crate::machine::mock_wam::Atom; +use crate::atom_table::{Atom, STATIC_ATOMS_MAP}; // TODO: Maybe add validation to the helper pub struct Helper { @@ -77,10 +77,16 @@ impl Completer for Helper { let start_of_prefix = get_prefix(line, pos); if let Some(idx) = start_of_prefix { let sub_str = line.get(idx..pos).unwrap(); - let matching = unsafe { - (*self.atoms).iter().filter(|a| a.as_str().starts_with(sub_str)).map(|s| StrPtr(s.as_str())).collect() - }; - Ok((idx, matching)) + Ok((idx, unsafe { + let mut matching = (*self.atoms).iter() + .chain(STATIC_ATOMS_MAP.values()) + .filter(|a| a.as_str().starts_with(sub_str)) + .map(|s| StrPtr(s.as_str())) + .collect::>(); + + matching.sort_unstable_by(|a, b| Ord::cmp(&(*a.0).len(), &(*b.0).len())); + matching + })) } else { Ok((0, vec![])) } -- 2.54.0