Skip to content

Fixed sorting of variables and matched suggestions in completion#379

Merged
hsbt merged 1 commit into
ruby:masterfrom
makketagg:fix/completion-sort-variables
Oct 5, 2022
Merged

Fixed sorting of variables and matched suggestions in completion#379
hsbt merged 1 commit into
ruby:masterfrom
makketagg:fix/completion-sort-variables

Conversation

@makketagg

Copy link
Copy Markdown
Contributor

Fixed sorting of suggestions. Fixed #378

@hsbt
hsbt merged commit 5842888 into ruby:master Oct 5, 2022
@hsbt

hsbt commented Oct 5, 2022

Copy link
Copy Markdown
Member

👍

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.
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.
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.

Unexpected sorting of variables and other matched suggestions

2 participants