Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r--helix-term/src/ui/mod.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 107e48dd..a68f423a 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -441,6 +441,50 @@ pub mod completers {
})
}
+ pub fn help(_editor: &Editor, input: &str) -> Vec<Completion> {
+ let static_cmds_path = helix_loader::runtime_dir().join("help/static-commands");
+ let typable_cmds_path = helix_loader::runtime_dir().join("help/typable-commands");
+ let mut items: Vec<String> = std::fs::read_dir(static_cmds_path)
+ .map(|entries| {
+ entries
+ .filter_map(|entry| {
+ let entry = entry.ok()?;
+ let path = entry.path();
+ (path.extension()? == "txt")
+ .then(|| path.file_stem().unwrap().to_string_lossy().into_owned())
+ })
+ .chain(
+ std::fs::read_dir(typable_cmds_path)
+ .map(|entries| {
+ entries.filter_map(|entry| {
+ let entry = entry.ok()?;
+ let path = entry.path();
+ (path.extension()? == "txt").then(|| {
+ format!(":{}", path.file_stem().unwrap().to_string_lossy())
+ })
+ })
+ })
+ .into_iter()
+ .flatten(),
+ )
+ .collect()
+ })
+ .unwrap_or_default();
+ items.push("topics".to_owned());
+
+ let matcher = Matcher::default();
+
+ let mut matches: Vec<_> = items
+ .into_iter()
+ .map(Cow::from)
+ .filter_map(|name| matcher.fuzzy_match(&name, input).map(|score| (name, score)))
+ .collect();
+
+ matches.sort_unstable_by_key(|(_file, score)| Reverse(*score));
+
+ matches.into_iter().map(|(name, _)| ((0..), name)).collect()
+ }
+
#[derive(Copy, Clone, PartialEq, Eq)]
enum FileMatch {
/// Entry should be ignored