From 0f96fea7d94742e920905ce809fe3025e28a39bc Mon Sep 17 00:00:00 2001 From: mattwparas Date: Tue, 11 Jul 2023 21:37:40 -0700 Subject: [PATCH] remove exported identifiers interface --- helix-term/src/commands.rs | 4 +-- helix-term/src/commands/engine.rs | 52 ++++++++++++++++++++++++++++--- helix-term/src/commands/typed.rs | 12 +++---- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d254608a0..e97960c1b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -542,13 +542,13 @@ impl std::str::FromStr for MappableCommand { args: args.clone(), }) .or_else(|| { - if let Some(doc) = self::engine::ExportedIdentifiers::engine_get_doc(name) { + if let Some(doc) = self::engine::ScriptingEngine::engine_get_doc(name) { Some(MappableCommand::Typable { name: name.to_owned(), args, doc, }) - } else if self::engine::ExportedIdentifiers::is_exported(name) { + } else if self::engine::ScriptingEngine::is_exported(name) { Some(MappableCommand::Typable { name: name.to_owned(), args, diff --git a/helix-term/src/commands/engine.rs b/helix-term/src/commands/engine.rs index d3aa241a4..371a81930 100644 --- a/helix-term/src/commands/engine.rs +++ b/helix-term/src/commands/engine.rs @@ -234,6 +234,45 @@ impl ScriptingEngine { None } + + pub(crate) fn fuzzy_match<'a>( + fuzzy_matcher: &'a fuzzy_matcher::skim::SkimMatcherV2, + input: &'a str, + ) -> Vec<(String, i64)> { + EXPORTED_IDENTIFIERS + .identifiers + .read() + .unwrap() + .iter() + .filter_map(|name| { + fuzzy_matcher + .fuzzy_match(name, input) + .map(|score| (name, score)) + }) + .map(|x| (x.0.to_string(), x.1)) + .collect::>() + } + + pub(crate) fn is_exported(ident: &str) -> bool { + EXPORTED_IDENTIFIERS + .identifiers + .read() + .unwrap() + .contains(ident) + } + + pub(crate) fn engine_get_doc(ident: &str) -> Option { + EXPORTED_IDENTIFIERS + .docs + .read() + .unwrap() + .get(ident) + .cloned() + } + + // fn get_doc(&self, ident: &str) -> Option { + // self.docs.read().unwrap().get(ident).cloned() + // } } // External modules that can load via rust dylib. These can then be consumed from @@ -1120,12 +1159,17 @@ impl ExportedIdentifiers { } pub(crate) fn engine_get_doc(ident: &str) -> Option { - EXPORTED_IDENTIFIERS.get_doc(ident) + EXPORTED_IDENTIFIERS + .docs + .read() + .unwrap() + .get(ident) + .cloned() } - fn get_doc(&self, ident: &str) -> Option { - self.docs.read().unwrap().get(ident).cloned() - } + // fn get_doc(&self, ident: &str) -> Option { + // self.docs.read().unwrap().get(ident).cloned() + // } } fn get_highlighted_text(cx: &mut Context) -> String { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index dfe70e5b6..9b819a927 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2924,13 +2924,11 @@ pub(super) fn command_mode(cx: &mut Context) { let words = shellwords.words(); if words.is_empty() || (words.len() == 1 && !shellwords.ends_with_whitespace()) { - let globals = crate::commands::engine::ExportedIdentifiers::fuzzy_match( - &FUZZY_MATCHER, - input, - ) - .into_iter() - .map(|x| (Cow::from(x.0), x.1)) - .collect::>(); + let globals = + crate::commands::engine::ScriptingEngine::fuzzy_match(&FUZZY_MATCHER, input) + .into_iter() + .map(|x| (Cow::from(x.0), x.1)) + .collect::>(); // If the command has not been finished yet, complete commands. let mut matches: Vec<_> = typed::TYPABLE_COMMAND_LIST