aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/completion.rs19
-rw-r--r--src/main.rs4
2 files changed, 22 insertions, 1 deletions
diff --git a/src/completion.rs b/src/completion.rs
index 61dce76..2137b6f 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -79,3 +79,22 @@ pub fn variable_completion(session: Arc<Mutex<Session>>, prefix: BString) -> Vec
}
out
}
+
+pub fn command_completion(session: Arc<Mutex<Session>>, prefix: BString) -> Vec<Suggestion> {
+ let se = session.lock().unwrap();
+ let mut out = Vec::new();
+ for fun in se.funs.keys().chain(se.builtins.keys()) {
+ if fun.starts_with(&prefix) {
+ out.push(Suggestion {
+ display: fun.to_vec(),
+ delta: fun[prefix.len()..].to_vec(),
+ })
+ }
+ }
+
+ for s in out.iter_mut() {
+ s.delta.push(b' ');
+ }
+
+ out
+}
diff --git a/src/main.rs b/src/main.rs
index 6012a86..5e7d40a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -357,7 +357,9 @@ fn event_loop() {
);
let suggestions = match comp.kind {
- parse::CompletionKind::Command => todo!(),
+ parse::CompletionKind::Command => {
+ completion::command_completion(session.clone(), comp.partial)
+ }
parse::CompletionKind::Argument => completion::path_completion(comp.partial),
parse::CompletionKind::Variable => {
completion::variable_completion(session.clone(), comp.partial)