Fix zsh/bash completions for arguments in option groups with a custom completion #648
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.
Issue
Description
The issue
It was caused by a mismatch in the completion scripts and the custom completion parsing. This is following the example from the issue above.
The completion scripts contained the name of the argument
':arg-in-option-group:{_custom_completion $_completion_example_commandname ---completion -- argInOptionGroup $words}'
The parsing of the completion command failed to find the argument using
ArgumentSet.firstPositional(named:)
.This was caused by the function creating an
InputKey
with just aname
and comparing to keys in the set that have theirname
andpath
set.In other words
There's also another issue that would occur when a command and an option group each contain an argument with the same name. In that case the completion would always match the first one in the
ArgumentSet
even if the user is trying to get completions for the second argument.The fix
The completions scripts were updated to contain the full path of the argument instead of just the name. Then the completions parser can create an
InputKey
that will exactly match one in theArgumentSet
.To avoid having the logic spread out, an extension was added to
InputKey
to get thefullPathString
from a key and an init to create anInputKey
from afullPathString
.I also updated the bash completion script to use
ArgumentDefinition.customCompletionCall(_:)
that the zsh script was already using to deduplicate the logic.Checklist