aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse/mod.rs
diff options
context:
space:
mode:
authorJonas Maier <>2026-03-10 13:13:49 +0100
committerJonas Maier <>2026-03-10 13:13:49 +0100
commit7728b844958bb7882ddf384b40e5711d7a9316ad (patch)
treefd8ecf5981da5cb317a2328265fad88a24b80093 /src/parse/mod.rs
parent961314b443849840e15d079ebd5724383489fd05 (diff)
downloadpish-7728b844958bb7882ddf384b40e5711d7a9316ad.tar.gz
completion if there is variables in the to-be-completed string
Diffstat (limited to 'src/parse/mod.rs')
-rw-r--r--src/parse/mod.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index f08426e..47e2d87 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -704,27 +704,23 @@ impl CompletionContext {
}
}
-fn expstr_cc(s: &ExpString, kind: CompletionKind) -> CompletionContext {
- if s.parts.len() > 1 || !s.parts[0].is_boring() {
- CompletionContext::none()
- } else {
- CompletionContext {
- kind,
- partial: s.parts[0].clone().unwrap_boring().clone(),
- }
+fn expstr_cc<E: Expander>(s: &ExpString, kind: CompletionKind, e: &mut E) -> CompletionContext {
+ match s.clone().expand(e) {
+ Ok(buf) => CompletionContext { kind, partial: buf },
+ Err(_) => CompletionContext::none(),
}
}
-pub fn completion_context<'a>(x: &'a [u8]) -> CompletionContext {
+pub fn completion_context<'a, E: Expander>(x: &'a [u8], e: &mut E) -> CompletionContext {
let mut cursor = Cursor::new(x, ParseMode::Completion);
let ast = Ast::parse(&mut cursor);
match ast {
Ok(Ast::Pipes(pipes)) if cursor.spaced == false => {
if let Some(cmd) = pipes.cmds.last() {
if cmd.args.is_empty() {
- expstr_cc(&cmd.cmd, CompletionKind::Command)
+ expstr_cc(&cmd.cmd, CompletionKind::Command, e)
} else {
- expstr_cc(&cmd.args[cmd.args.len() - 1], CompletionKind::Argument)
+ expstr_cc(&cmd.args[cmd.args.len() - 1], CompletionKind::Argument, e)
}
} else {
CompletionContext::none()