diff options
| author | Jonas Maier <> | 2026-03-17 15:23:43 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-17 15:23:43 +0100 |
| commit | 965196972fa27237b6cb97209c915381a95a5bef (patch) | |
| tree | 225e1258bbd3ce961fc40390799666ffe51bbb9d /src | |
| parent | 7b5a112d000bb21fd81569617353daa0c911d084 (diff) | |
| download | pish-965196972fa27237b6cb97209c915381a95a5bef.tar.gz | |
builtin to determine what completion would do
Diffstat (limited to 'src')
| -rw-r--r-- | src/parse/mod.rs | 1 | ||||
| -rw-r--r-- | src/run/builtin.rs | 27 | ||||
| -rw-r--r-- | src/run/mod.rs | 1 |
3 files changed, 29 insertions, 0 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index eda89f1..e085f34 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -797,6 +797,7 @@ pub fn do_parse(x: &[u8]) -> Res<Ast<PreExpansion>, (ParseError, &[u8])> { } } +#[derive(Debug)] pub enum CompletionKind { Command, Argument, diff --git a/src/run/builtin.rs b/src/run/builtin.rs index 141357f..f0cb999 100644 --- a/src/run/builtin.rs +++ b/src/run/builtin.rs @@ -375,6 +375,33 @@ impl Builtin for parse { } } +pub struct completion; +impl Builtin for completion { + fn name(&self) -> &str { + "completion" + } + + fn io( + &self, + session: Arc<Mutex<Session>>, + args: &[BString], + _stdin: &mut dyn Read, + stdout: &mut dyn Write, + ) -> Result { + for arg in args { + let c = crate::completion(session.clone(), &arg); + write!(stdout, "{:?} ", c.kind)?; + stdout.write_all(&c.shared_prefix)?; + for s in c.suggestions { + stdout.write_all(b" ")?; + stdout.write_all(&s.display)?; + } + stdout.write_all(b"\n")?; + } + Ok(()) + } +} + pub struct null; impl Builtin for null { fn name(&self) -> &str { diff --git a/src/run/mod.rs b/src/run/mod.rs index 1133ddb..2224eac 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -491,6 +491,7 @@ const BUILTINS: &[&'static dyn Builtin] = &[ &builtin::parse, &builtin::null, &builtin::var, + &builtin::completion, ]; pub fn builtin_map() -> HashMap<BString, &'static dyn Builtin> { |
