From 5b2912b63ef3846eaed401a50d96acc9eae684de Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 20 Sep 2024 10:05:49 -0500 Subject: [PATCH] fix(complete): Improve completion debugging --- clap_complete/src/engine/complete.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/clap_complete/src/engine/complete.rs b/clap_complete/src/engine/complete.rs index 75dad1b2..e2fcfda7 100644 --- a/clap_complete/src/engine/complete.rs +++ b/clap_complete/src/engine/complete.rs @@ -15,6 +15,7 @@ pub fn complete( arg_index: usize, current_dir: Option<&std::path::Path>, ) -> Result, std::io::Error> { + debug!("complete: args={args:?}, arg_index={arg_index:?}, current_dir={current_dir:?}"); cmd.build(); let raw_args = clap_lex::RawArgs::new(args); @@ -26,6 +27,7 @@ pub fn complete( ); // As we loop, `cursor` will always be pointing to the next item raw_args.next_os(&mut target_cursor); + debug!("complete: target_cursor={target_cursor:?}"); // TODO: Multicall support if !cmd.is_no_binary_name_set() { @@ -39,12 +41,14 @@ pub fn complete( while let Some(arg) = raw_args.next(&mut cursor) { let current_state = next_state; next_state = ParseState::ValueDone; + debug!( + "complete::next: arg={:?}, current_state={current_state:?}, cursor={cursor:?}", + arg.to_value_os(), + ); if cursor == target_cursor { return complete_arg(&arg, current_cmd, current_dir, pos_index, current_state); } - debug!("complete::next: Begin parsing '{:?}'", arg.to_value_os(),); - if let Ok(value) = arg.to_value() { if let Some(next_cmd) = current_cmd.find_subcommand(value) { current_cmd = next_cmd;