Skip to content

Commit 2e13847

Browse files
committed
fix(complete): Missing options in multi-val arg
jj dynamic completions of option names work as expected: $ COMPLETE=fish jj -- jj abandon --ignore- --ignore-working-copy --ignore-immutable Unless there is a positional argument preceding the option $ COMPLETE=fish jj -- jj abandon @ --ignore- The positional arguments are defined in the "abandon" subcommand as: ```rust #[derive(clap::Args, Clone, Debug)] pub(crate) struct AbandonArgs { /// The revision(s) to abandon (default: @) #[arg(value_name = "REVSETS")] revisions_pos: Vec<RevisionArg>, } ``` Fix that in most cases. Fixes #5935
1 parent 74388d7 commit 2e13847

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clap_complete/src/engine/complete.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,18 @@ fn complete_arg(
159159
}
160160
completions.extend(complete_option(arg, cmd, current_dir));
161161
}
162-
ParseState::Pos(..) => {
162+
ParseState::Pos((_, num_arg)) => {
163163
if let Some(positional) = cmd
164164
.get_positionals()
165165
.find(|p| p.get_index() == Some(pos_index))
166166
{
167167
completions.extend(complete_arg_value(arg.to_value(), positional, current_dir));
168+
if positional
169+
.get_num_args()
170+
.is_some_and(|num_args| num_arg >= num_args.min_values())
171+
{
172+
completions.extend(complete_option(arg, cmd, current_dir));
173+
}
168174
}
169175
}
170176
ParseState::Opt((opt, count)) => {

clap_complete/tests/testsuite/engine.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,13 @@ pos_2
813813
"#]]
814814
);
815815

816-
assert_data_eq!(complete!(cmd, "pos_1 pos_2 --[TAB]"), snapbox::str![""]);
816+
assert_data_eq!(
817+
complete!(cmd, "pos_1 pos_2 --[TAB]"),
818+
snapbox::str![[r#"
819+
--format
820+
--help Print help
821+
"#]]
822+
);
817823
assert_data_eq!(
818824
complete!(cmd, "pos_1 pos_2 --format json [TAB]"),
819825
snapbox::str![[r#"

0 commit comments

Comments
 (0)