fix: extend cursor_start fix to magic get_completions (issue #432 follow-up)#437
Merged
blink1073 merged 1 commit intoCalysto:mainfrom Apr 28, 2026
Merged
Conversation
…#432 follow-up) When a magic's get_completions returns matches and the cursor sits after a non-identifier character such as '--', cursor_start was still left at 0, causing the client to erase and replace the entire input line. Apply the same fix used for path completions (PR Calysto#433): when info["obj"] is empty and there are matches at the end of do_complete, set cursor_start to cursor_end so completions are appended at the cursor rather than replacing from position 0. Add test_magic_complete_trailing_dash to cover this case with a custom magic that offers completions for a '--' prefix.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
References
closes #432 (follow-up to #433)
Description
The v1.0.3 fix in #433 corrected
cursor_startfor path completions when the cursor sits after a non-identifier character (e.g./,-). However, when a magic'sget_completionsreturns matches in the same situation (e.g. cursor after--),cursor_startwas still left at 0, causing the Jupyter client to erase and replace the entire input line.Changes
metakernel/_metakernel.py: At the end ofdo_complete, after all matches are collected, apply the same fix: wheninfo["obj"]is empty and there are matches, setcursor_start = cursor_endso completions are appended at the cursor rather than replacing from position 0.tests/test_metakernel.py: Addtest_magic_complete_trailing_dash— registers a custom magic withget_completionsreturning options, and asserts that for%option_magic --,cursor_start == cursor_end.Backwards-incompatible changes
None
Testing
just test tests/test_metakernel.py— all 93 tests pass including the new regression testjust typing— no issuesjust pre-commit— all hooks passAI usage