wip: add more atoms to completion list

This commit is contained in:
Euan Lacy
2022-05-11 21:37:03 +01:00
parent c2a87f898e
commit 27a15a2464
2 changed files with 12 additions and 6 deletions

View File

@@ -170,7 +170,7 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
#((#static_strs) => { Atom { index: #indices_iter } };)* #((#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 } },)* #(#static_strs => { Atom { index: #indices } },)*
}; };
} }

View File

@@ -5,7 +5,7 @@ use rustyline::validate::Validator;
use rustyline::highlight::{MatchingBracketHighlighter, Highlighter}; use rustyline::highlight::{MatchingBracketHighlighter, Highlighter};
use rustyline::{Helper as RlHelper, Result, Context}; 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 // TODO: Maybe add validation to the helper
pub struct Helper { pub struct Helper {
@@ -77,10 +77,16 @@ impl Completer for Helper {
let start_of_prefix = get_prefix(line, pos); let start_of_prefix = get_prefix(line, pos);
if let Some(idx) = start_of_prefix { if let Some(idx) = start_of_prefix {
let sub_str = line.get(idx..pos).unwrap(); let sub_str = line.get(idx..pos).unwrap();
let matching = unsafe { Ok((idx, unsafe {
(*self.atoms).iter().filter(|a| a.as_str().starts_with(sub_str)).map(|s| StrPtr(s.as_str())).collect() let mut matching = (*self.atoms).iter()
}; .chain(STATIC_ATOMS_MAP.values())
Ok((idx, matching)) .filter(|a| a.as_str().starts_with(sub_str))
.map(|s| StrPtr(s.as_str()))
.collect::<Vec<_>>();
matching.sort_unstable_by(|a, b| Ord::cmp(&(*a.0).len(), &(*b.0).len()));
matching
}))
} else { } else {
Ok((0, vec![])) Ok((0, vec![]))
} }