remove exported identifiers interface

pull/8675/merge^2
mattwparas 1 year ago
parent 3ee5829ed7
commit 0f96fea7d9

@ -542,13 +542,13 @@ impl std::str::FromStr for MappableCommand {
args: args.clone(), args: args.clone(),
}) })
.or_else(|| { .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 { Some(MappableCommand::Typable {
name: name.to_owned(), name: name.to_owned(),
args, args,
doc, doc,
}) })
} else if self::engine::ExportedIdentifiers::is_exported(name) { } else if self::engine::ScriptingEngine::is_exported(name) {
Some(MappableCommand::Typable { Some(MappableCommand::Typable {
name: name.to_owned(), name: name.to_owned(),
args, args,

@ -234,6 +234,45 @@ impl ScriptingEngine {
None 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::<Vec<_>>()
}
pub(crate) fn is_exported(ident: &str) -> bool {
EXPORTED_IDENTIFIERS
.identifiers
.read()
.unwrap()
.contains(ident)
}
pub(crate) fn engine_get_doc(ident: &str) -> Option<String> {
EXPORTED_IDENTIFIERS
.docs
.read()
.unwrap()
.get(ident)
.cloned()
}
// fn get_doc(&self, ident: &str) -> Option<String> {
// self.docs.read().unwrap().get(ident).cloned()
// }
} }
// External modules that can load via rust dylib. These can then be consumed from // 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<String> { pub(crate) fn engine_get_doc(ident: &str) -> Option<String> {
EXPORTED_IDENTIFIERS.get_doc(ident) EXPORTED_IDENTIFIERS
.docs
.read()
.unwrap()
.get(ident)
.cloned()
} }
fn get_doc(&self, ident: &str) -> Option<String> { // fn get_doc(&self, ident: &str) -> Option<String> {
self.docs.read().unwrap().get(ident).cloned() // self.docs.read().unwrap().get(ident).cloned()
} // }
} }
fn get_highlighted_text(cx: &mut Context) -> String { fn get_highlighted_text(cx: &mut Context) -> String {

@ -2924,10 +2924,8 @@ pub(super) fn command_mode(cx: &mut Context) {
let words = shellwords.words(); let words = shellwords.words();
if words.is_empty() || (words.len() == 1 && !shellwords.ends_with_whitespace()) { if words.is_empty() || (words.len() == 1 && !shellwords.ends_with_whitespace()) {
let globals = crate::commands::engine::ExportedIdentifiers::fuzzy_match( let globals =
&FUZZY_MATCHER, crate::commands::engine::ScriptingEngine::fuzzy_match(&FUZZY_MATCHER, input)
input,
)
.into_iter() .into_iter()
.map(|x| (Cow::from(x.0), x.1)) .map(|x| (Cow::from(x.0), x.1))
.collect::<Vec<_>>(); .collect::<Vec<_>>();

Loading…
Cancel
Save