Repository navigation
rline: don't let a short completion rule break the others - #1765
Conversation
complete_rule() indexed the rule's components by the number of words
typed without checking the rule was that long. With rules like
['<download|status|list>', 'download all']
typing "download a<TAB>" made the one-word rule raise IndexError, and
complete_rules() then returned nothing for the whole command, so "all"
was never offered.
Return no candidates from a rule that is shorter than the command.
Windows already had this check for the last component only, so use one
check before the matching loop for every platform.
Fixes ArduPilot#1706
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated review note — AI-generated (Claude), validated against the live diff. Please sanity-check before acting. Reviewed at head Thanks, this looks good. Previously, a completion rule with fewer components than the typed command raised IndexError inside complete_rule(). That took out completion for every other rule of the same command; for example, 'camera roi ' and 'camera set ' fail on master. The new guard (https://github.com/ArduPilot/MAVProxy/pull/1765/files#diff-9be8e324d0e043c964d98d7d02335035e37bc2804e683c1703e33209c6781578R270) makes such a rule contribute nothing instead. A base-vs-head comparison over several hundred thousand generated rule/command cases, on both the Linux and the Windows code paths, found no other change in behaviour. It also replaces the Windows-only guard, which still left an IndexError in the match loop. The added tests pass on this branch and fail on master with the original IndexError. Not exercised here: interactive completion on a real readline terminal or on Windows prompt_toolkit, and the full GUI-dependent test suite. |
|
Merged, thanks! |
|
Neat, good work. Glad to have some help improving the usability of MAVProxy! |
Fixes #1706.
complete_rule()indexed the rule's components by the number of words typed without checking that the rule was that long. With rules like the ones in #1706:typing
download a<TAB>made the one-word rule raiseIndexError.complete_rules()then returned nothing for the whole command, soallwas never offered. The same happens one word later, inside the matching loop, e.g. rules['<foo|bar>', 'foo baz qux']andfoo baz q<TAB>.Windows already had a length check, but only for the last component and after the matching loop. This PR does one check before the loop for every platform: a rule shorter than the command offers no candidates.
Testing
tests/test_rline.py. Two of its three tests fail on master withIndexErrorand pass with this change. The third checks that existing completions behave as before: empty input, alternations, completion functions, non-matching rules.scripts/run_flake8.py MAVProxy.#1569 also touches the Windows check in
complete_rule()(it drops the Python 2 condition), so whichever PR merges second needs a small rebase there.The log module's
downloadrules from the issue are not part of this PR. This only fixes therlinebug that stopped them from completing.This contribution was AI-assisted (Claude Code): it wrote the change and the test. I reviewed the change and the results.
🤖 Generated with Claude Code