feat(complete): Add ValueCompleter::complete_at for indexed multi-value completion#6353
Merged
epage merged 2 commits intoclap-rs:masterfrom Apr 27, 2026
Merged
Conversation
epage
reviewed
Apr 25, 2026
epage
reviewed
Apr 25, 2026
6ca55b8 to
7b23bd2
Compare
Snapshot existing behavior for a custom `ValueCompleter` on a multi-value option. Without an index-aware API, the completer cannot differentiate by argument position, so both the first and second values surface the same merged candidate set. This pins down the baseline so a follow-up commit can show the behavior change in the test diff.
Add `ValueCompleter::complete_at(arg_index, current)` and a matching `ArgValueCompleter::complete_at` shim. The default trait impl delegates to `complete`, so existing implementors are unaffected. The dynamic engine now threads each value's position within an argument's `num_args` range into the completer, so a multi-value argument can return different candidates per slot (for example, a remote name first and a branch name second for `--set-upstream <REMOTE> <BRANCH>`). `arg_index` counts shell arguments and is unaffected by `value_delimiter`. Closes clap-rs#6284
7b23bd2 to
ac0d148
Compare
Contributor
Author
epage
approved these changes
Apr 25, 2026
Member
epage
left a comment
There was a problem hiding this comment.
I'll merge when I have a chance to release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6284.
Adds
ValueCompleter::complete_at(arg_index, current)so a custom completercan return different candidates for each value of a multi-value argument.
The motivating case from the issue:
--set-upstream <REMOTE> <BRANCH>shouldcomplete remotes at index 0 and branches at index 1.
The new method has a default implementation that delegates to
complete, soexisting implementations of
ValueCompleter(including all closure-basedcompleters) keep working unchanged.
arg_indexis the zero-based positionwithin the argument's
num_argsrange and is unaffected byvalue_delimiter.Engine plumbing computes the index from the existing
ParseState:ParseState::Opt((opt, count)):arg_index = count - 1ParseState::Pos((_, num_arg)):arg_index = num_arg - 10(single-value paths).The new test
suggest_custom_arg_completer_at_indexcovers both indices fora
num_args(2)flag, including prefix-filtered completions, and confirmsthe default
complete_atstill defers tocompletefor the unindexed case.