Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default completor from regexp to type-completor if RUBY_VERSION>=3.4 #1010

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

tompng
Copy link
Member

@tompng tompng commented Sep 30, 2024

In Ruby >= 3.4, ReplTypeCompletor is a bundled gem, installed by default.
This pull request changes the default completor to type-completor if RUBY_VERSION >= 3.4.
If ReplTypeCompletor is not available (not installed or not added to Gemfile), fallbacks to regexp-baased completion.
The default isstill :regexp if RUBY_VERSION < 3.4

Run with bundler

With bundler and when repl_type_completor is not added to Gemfile, IRB will use regexp-based completion.
IRB shows warning message only If --type-completor or IRB.conf[:COMPLETOR] = :type is explicitly specified.

$ ruby -v
ruby 3.4.0dev

$ irb
irb(main):001> irb_info
(TypeCompletor)

$ echo "gem 'irb', path: 'path/to/irb'" > Gemfile

$ bundle exec irb
(no waarning)
irb(main):001> irb_info
(RegexpCompletor)

$ bundle exec irb --type-completor
TypeCompletor requires `gem repl_type_completor`: cannot load such file -- repl_type_completor
irb(main):001> irb_info
(RegexpCompletor)

Restriction with rdbg

ReplTypeCompletor uses background thread to load RBS type information which could take time.
Debug gem stops all other threads, so if IRB enters debug mode before loading RBS completes, type completor can't use type information.
Even without type information, type completor can still complete as good or better than regexp-based completion.

@st0012
Copy link
Member

st0012 commented Oct 1, 2024

Since repl_type_completor only has ~64k downloads atm, this means almost all IRB sessions after this change will trigger a LoadError unnecessarily. And at the same time, this change isn't actually making more people use repl_type_completor. It simply saves the existing users the need to configure it.

IMO the right solution here is to propose making repl_type_completor a bundled gem. And only until that happens, we make it a default for IRB with a Ruby version check as older Ruby versions still won't have it installed by default.

@tompng tompng changed the title Change default completor from regexp to type-completor Change default completor from regexp to type-completor if RUBY_VERSION>=3.4 Oct 5, 2024
@tompng
Copy link
Member Author

tompng commented Oct 5, 2024

ReplTypeCompletor is added to bundled gem now 🎉 I updated the pull request description.

with a Ruby version check

Looks nice, added

@st0012 st0012 added the enhancement New feature or request label Oct 5, 2024
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Let's give it a try 🎉

Copy link
Member

@ima1zumi ima1zumi left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@tompng tompng merged commit bb6a99d into ruby:master Oct 6, 2024
30 checks passed
@tompng tompng deleted the type_completor_as_default branch October 6, 2024 11:10
matzbot pushed a commit to ruby/ruby that referenced this pull request Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants