Skip to content

Sort remaining completion candidates in RegexpCompletor#1230

Merged
tompng merged 1 commit into
ruby:masterfrom
kryzhovnik:sort-completion-candidates
Jul 16, 2026
Merged

Sort remaining completion candidates in RegexpCompletor#1230
tompng merged 1 commit into
ruby:masterfrom
kryzhovnik:sort-completion-candidates

Conversation

@kryzhovnik

Copy link
Copy Markdown
Contributor

#379 sorted local variables and string method candidates (fixing #349), but receiver.method completion — the most common case — still returns candidates in method table order, which looks random. Same for symbols, global variables and :: constants. With an ActiveRecord model, u.email_address is listed below all its generated variants:

u.email_address_before_last_save
u.email_address_change_to_be_saved
u.email_address=
...
u.email_address

This sorts candidates in select_message (making the two pre-sorted call sites redundant) and in the symbol/gvar/absolute constant branches.

One detail: candidates starting with _ are sorted last, otherwise completing u. would begin with __id__, __send__, _run_commit_callbacks and similar internals instead of regular methods. Same change for TypeCompletor is proposed in ruby/repl_type_completor#78.

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

@tompng tompng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you 👍

@tompng
tompng merged commit 1b20991 into ruby:master Jul 16, 2026
33 of 40 checks passed
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