Fixed sorting of variables and matched suggestions in completion#379
Merged
Conversation
Member
|
👍 |
This was referenced Oct 6, 2022
kryzhovnik
added a commit
to kryzhovnik/repl_type_completor
that referenced
this pull request
Jul 15, 2026
Method completion candidates ([:call], [:call_or_const], [:lvar_or_method]) were returned in reflection order, which is an artifact of the method table and not even definition order. This looked random in the completion dialog: e.g. for an ActiveRecord model, `user.email_address` was listed after all its generated variants like `email_address_before_last_save`. Constants, ivars and symbols were already sorted, and the readline-style menu was sorted in ruby/reline#96, as was part of the regexp completor in ruby/irb#379 (fixing ruby/irb#349). This extends the same policy to all candidate kinds by sorting once at the exit point of completion_candidates, which also makes the per-branch sorts redundant, so they are removed. Plain alphabetical order would rank internal methods (__id__, __send__, Rails' _run_commit_callbacks etc.) first when completing an empty method name, because underscore precedes letters in ASCII. Candidates starting with an underscore are therefore sorted after the rest. The rule is applied to the full name before the typed prefix is stripped, so it only affects completions where the leading underscore is actually typed-visible.
This was referenced Jul 15, 2026
tompng
pushed a commit
that referenced
this pull request
Jul 16, 2026
#379 sorted local variables and string method candidates, but receiver.method completion (the most common case), symbols, global variables and absolute constants were still returned in method table order, which looks random in the completion dialog. Sort them too. Candidates starting with an underscore go last, so that completing `u.` does not begin with __id__, __send__ and other internals.
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.
Fixed sorting of suggestions. Fixed #378