[ruby/irb] Enable Setting Completer Type through IRB_COMPLETOR

(https://github.com/ruby/irb/pull/771)

I propose introducing the capability to set the IRB completion kinds via an environment variable, specifically `IRB_COMPLETOR=type`.
This feature aims to enhance the Rails console experience by allowing Rails users to specify their preferred completion more conveniently.

Currently, when using the Rails console, there's no straightforward way to globally set the type completion across a Rails application repository.
It's possible to configure this setting by placing a `.irbrc` file at the project root. However, using a .irbrc file is not ideal as it allows for broad configurations and can potentially affect the production environment.
My suggestion focuses on allowing users to set the completion to 'type' in a minimal.

This enhancement would be particularly beneficial for teams writing RBS in their Rails applications.
This type completer, integrated with RBS, would enhance completion accuracy, improving the Rails console experience.

https://github.com/ruby/irb/commit/032f6da25f
This commit is contained in:
ima1zumi 2023-11-21 09:04:36 +09:00 committed by git
parent a182b2c5e1
commit 7164715666
2 changed files with 29 additions and 1 deletions

View File

@ -76,7 +76,7 @@ module IRB # :nodoc:
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
@CONF[:USE_COLORIZE] = (nc = ENV['NO_COLOR']).nil? || nc.empty?
@CONF[:USE_AUTOCOMPLETE] = ENV.fetch("IRB_USE_AUTOCOMPLETE", "true") != "false"
@CONF[:COMPLETOR] = :regexp
@CONF[:COMPLETOR] = ENV.fetch("IRB_COMPLETOR", "regexp").to_sym
@CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false
@CONF[:USE_LOADER] = false

View File

@ -120,6 +120,34 @@ module TestIRB
IRB.conf[:USE_AUTOCOMPLETE] = orig_use_autocomplete_conf
end
def test_completor_environment_variable
orig_use_autocomplete_env = ENV['IRB_COMPLETOR']
orig_use_autocomplete_conf = IRB.conf[:COMPLETOR]
ENV['IRB_COMPLETOR'] = nil
IRB.setup(__FILE__)
assert_equal(:regexp, IRB.conf[:COMPLETOR])
ENV['IRB_COMPLETOR'] = 'regexp'
IRB.setup(__FILE__)
assert_equal(:regexp, IRB.conf[:COMPLETOR])
ENV['IRB_COMPLETOR'] = 'type'
IRB.setup(__FILE__)
assert_equal(:type, IRB.conf[:COMPLETOR])
ENV['IRB_COMPLETOR'] = 'regexp'
IRB.setup(__FILE__, argv: ['--type-completor'])
assert_equal :type, IRB.conf[:COMPLETOR]
ENV['IRB_COMPLETOR'] = 'type'
IRB.setup(__FILE__, argv: ['--regexp-completor'])
assert_equal :regexp, IRB.conf[:COMPLETOR]
ensure
ENV['IRB_COMPLETOR'] = orig_use_autocomplete_env
IRB.conf[:COMPLETOR] = orig_use_autocomplete_conf
end
def test_completor_setup_with_argv
orig_completor_conf = IRB.conf[:COMPLETOR]