]> Repositorios git - scryer-prolog.git/commitdiff
wip: add more atoms to completion list
authorEuan Lacy <[email protected]>
Wed, 11 May 2022 20:37:03 +0000 (21:37 +0100)
committerEuan Lacy <[email protected]>
Wed, 11 May 2022 20:37:03 +0000 (21:37 +0100)
build/static_string_indexing.rs
src/repl_helper.rs

index 390c5405f92db1a85b5f2dc9c386e54b73dd4ea8..6f57b37ffb62399f1bc00d0bd8cb488d0952f7af 100644 (file)
@@ -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 } },)*
         };
     }
index 913470201c368d540808c3935a8507037f4d840d..21dc9800785d306f665814270d623ce2fff2f1ee 100644 (file)
@@ -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::<Vec<_>>();
+
+                matching.sort_unstable_by(|a, b| Ord::cmp(&(*a.0).len(), &(*b.0).len()));
+                matching
+            }))
         } else {
             Ok((0, vec![]))
         }