Skip to content

Sort completion list#96

Merged
aycabta merged 1 commit into
ruby:masterfrom
shuujii:sort-completion-list
Jan 1, 2020
Merged

Sort completion list#96
aycabta merged 1 commit into
ruby:masterfrom
shuujii:sort-completion-list

Conversation

@shuujii

@shuujii shuujii commented Dec 27, 2019

Copy link
Copy Markdown
Contributor

Legacy mode:

$ irb --legacy
irb(main):001:0> l[TAB][TAB]
lambda           load             local_variables  loop

Before this patch:

$ irb
irb(main):001:0> l[TAB][TAB]
local_variables
loop
lambda
load

After this patch:

$ irb
irb(main):001:0> l[TAB][TAB]
lambda
load
local_variables
loop

#### Legacy mode:

  ```console
  $ irb --legacy
  irb(main):001:0> l[TAB][TAB]
  lambda           load             local_variables  loop
  ```

#### Before this patch:

  ```console
  $ irb
  irb(main):001:0> l[TAB][TAB]
  local_variables
  loop
  lambda
  load
  ```

#### After this patch:

  ```console
  $ irb
  irb(main):001:0> l[TAB][TAB]
  lambda
  load
  local_variables
  loop
  ```
@aycabta

aycabta commented Jan 1, 2020

Copy link
Copy Markdown
Member

Good!

@aycabta
aycabta merged commit 8122025 into ruby:master Jan 1, 2020
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.
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