diff options
| author | Jonas Maier <> | 2026-03-10 16:51:07 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-10 16:51:07 +0100 |
| commit | 27ee3f07c39f3f584fac4a8712dd4fe97e46e462 (patch) | |
| tree | 7ecf8c0420bf97ad76eb025d13d3cddc00e13dda /src | |
| parent | 8046a94bde376e018c01df4cdc3ade2c6aeaf32c (diff) | |
| download | pish-27ee3f07c39f3f584fac4a8712dd4fe97e46e462.tar.gz | |
command completion (only builtins and user-defined funs for now)
Diffstat (limited to 'src')
| -rw-r--r-- | src/completion.rs | 19 | ||||
| -rw-r--r-- | src/main.rs | 4 |
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) |
