Make shell completion prioritize option values over new options#2041
Conversation
|
How does this affect options without values? |
Flag options are unaffected ( Count options do end up unintentionally taking over the completion for the next arg. That could be easily fixed by extending the previously mentioned Are there other kinds of options without values? Those are the only two cases I've seen in the documentation. |
|
Ah, I guess there's also options with optional values. This change also makes them claim the next arg for completion. If I understand correctly, the parser collects all of the possible prefixes from each option and then decides whether an arg is an optional value vs. another option based on those prefixes. Should the shell_completions do the same, using the collected prefixes from the parser? |
|
@davidism I pushed a rewrite of the fix to instead grab the opt_prefixes from the parser and store them into the context. Then the shell completion can use that information to more closely match what the parser will do.
The new implementation should treat them the same as the parser: if the incomplete string starts with a symbol used by any of the options, it will complete as a new option. Otherwise, it will complete as the value of the current option. See the added tests in test_shell_completion.py. |
|
Hi @davidism is there any interest in this PR or anything else I could help answer about it? |
9944ebf to
d93b74c
Compare
d93b74c to
4b03a6b
Compare
Allow option values that start with an option prefix to complete rather than treating them like new options. Don't treat count options as needing a value to complete.
4b03a6b to
f2e579a
Compare
Swap the order of checks in _resolve_incomplete so that we first check to see if we're completing an option value before detecting if we're completing a new option name. Allows option values that start with non-alphanumeric characters to complete rather than treating them like new options.
Checklist:
CHANGES.rstsummarizing the change and linking to the issue... versionchanged::entries in any relevant code docs.pre-commithooks and fix any issues.pytestandtox, no tests failed.