Skip to content

rline: don't let a short completion rule break the others - #1765

Merged
peterbarker merged 1 commit into
ArduPilot:masterfrom
Abtektas:fix/rline-short-rule
Oct 1, 2026
Merged

peterbarker merged 1 commit into
ArduPilot:masterfrom
Abtektas:fix/rline-short-rule

Conversation

@Abtektas

Copy link
Copy Markdown
Contributor

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:

['<download|status|erase|resume|cancel|list>',
 'download all',
 'download latest']

typing download a<TAB> made the one-word rule raise IndexError. complete_rules() then returned nothing for the whole command, so all was never offered. The same happens one word later, inside the matching loop, e.g. rules ['<foo|bar>', 'foo baz qux'] and foo 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

  • Added tests/test_rline.py. Two of its three tests fail on master with IndexError and pass with this change. The third checks that existing completions behave as before: empty input, alternations, completion functions, non-matching rules.
  • Ran scripts/run_flake8.py MAVProxy.
  • macOS (arm64), Python 3.14.

#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 download rules from the issue are not part of this PR. This only fixes the rline bug 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

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>
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head ed515fb252.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/mavproxy/1765/1.html#prMAVProxy-1765

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.

@peterbarker
peterbarker merged commit 7e54bd9 into ArduPilot:master Oct 1, 2026
4 checks passed
@peterbarker

Copy link
Copy Markdown
Contributor

Merged, thanks!

@Ryanf55

Ryanf55 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Neat, good work. Glad to have some help improving the usability of MAVProxy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mavproxy_log: tab-complete on download

5 participants