Skip to content

aiorepl: Add tab completion support.#1081

Open
andrewleech wants to merge 1 commit intomicropython:masterfrom
andrewleech:aiorepl-tab-completion
Open

aiorepl: Add tab completion support.#1081
andrewleech wants to merge 1 commit intomicropython:masterfrom
andrewleech:aiorepl-tab-completion

Conversation

@andrewleech
Copy link
Contributor

Summary

Adds tab completion to aiorepl using the new micropython.repl_autocomplete() function exposed in micropython/micropython#17011. Behaviour matches the native REPL: single match inserts the completion, multiple matches prints candidates and redraws the prompt, tab after whitespace inserts 4 spaces for indentation. Falls back gracefully on ports without MICROPY_HELPER_REPL by checking for the function with getattr at startup.

Also uses micropython.stdio_mode_raw() when available (also from #17011) to switch terminal mode around code execution, matching how the native REPL toggles between raw mode for input and cooked mode during exec.

Version bumped to 0.3.0.

Testing

  • test_autocomplete.py + .py.exp added covering the autocomplete API contract, multi-match via __main__ globals injection, and the whitespace-before-cursor indentation logic.
  • Tested interactively on unix port with both single and multiple completions, cursor-in-middle-of-line completion, and tab-as-indentation.

Use micropython.repl_autocomplete() to provide tab completion matching
the native REPL behavior: single match inserts the completion, multiple
matches prints candidates and redraws the prompt, tab after whitespace
inserts 4 spaces for indentation. Falls back gracefully on ports without
MICROPY_HELPER_REPL.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants