From 7728b844958bb7882ddf384b40e5711d7a9316ad Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Tue, 10 Mar 2026 13:13:49 +0100 Subject: completion if there is variables in the to-be-completed string --- src/parse/mod.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/parse') 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(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() -- cgit v1.2.3