-
Notifications
You must be signed in to change notification settings - Fork 1.1k
aiorepl: Add tab completion support. #1081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+80
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
micropython/aiorepl/manifest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
micropython/aiorepl/test_autocomplete.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Test tab completion logic used by aiorepl. | ||
| import sys | ||
| import micropython | ||
|
|
||
| try: | ||
| micropython.repl_autocomplete | ||
| except AttributeError: | ||
| print("SKIP") | ||
| raise SystemExit | ||
|
|
||
| # Test the autocomplete API contract that aiorepl depends on. | ||
|
|
||
| # Single completion: keyword "import" | ||
| result = micropython.repl_autocomplete("impo") | ||
| print(repr(result)) | ||
|
|
||
| # No match: returns empty string | ||
| result = micropython.repl_autocomplete("xyz_no_match_zzz") | ||
| print(repr(result)) | ||
|
|
||
| # Multiple matches: returns None (candidates printed to stdout by C code). | ||
| # Create two globals sharing a prefix so autocomplete finds multiple matches. | ||
| import __main__ | ||
|
|
||
| __main__.tvar_alpha = 1 | ||
| __main__.tvar_beta = 2 | ||
| result = micropython.repl_autocomplete("tvar_") | ||
| del __main__.tvar_alpha | ||
| del __main__.tvar_beta | ||
| print("multiple:", repr(result)) | ||
|
|
||
| # Test the whitespace-before-cursor logic used for tab-as-indentation. | ||
| # This validates the condition: cursor_pos > 0 and cmd[cursor_pos - 1] <= " " | ||
| test_cases = [ | ||
| ("x ", True), # space before cursor | ||
| ("x", False), # non-whitespace before cursor | ||
| ("\n", True), # newline counts as whitespace | ||
| ("", False), # empty line (cursor_pos == 0) | ||
| ] | ||
| for cmd, expected in test_cases: | ||
| cursor_pos = len(cmd) | ||
| is_whitespace = cursor_pos > 0 and cmd[cursor_pos - 1] <= " " | ||
| print(cmd.encode(), is_whitespace == expected) | ||
9 changes: 9 additions & 0 deletions
micropython/aiorepl/test_autocomplete.py.exp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 'rt ' | ||
| '' | ||
|
|
||
| tvar_alpha tvar_beta | ||
| multiple: None | ||
| b'x ' True | ||
| b'x' True | ||
| b'\n' True | ||
| b'' True |
Oops, something went wrong.
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.