Skip to content

Commit 032f6da

Browse files
authored
Enable Setting Completer Type through IRB_COMPLETOR (#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.
1 parent 07e4d54 commit 032f6da

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ irb(main):002> a.first. # Completes Integer methods
314314

315315
- `NO_COLOR`: Assigning a value to it disables IRB's colorization.
316316
- `IRB_USE_AUTOCOMPLETE`: Setting it to `false` disables IRB's autocompletion.
317+
- `IRB_COMPLETOR`: Configures IRB's auto-completion behavior, allowing settings for either `regexp` or `type`.
317318
- `VISUAL`: Its value would be used to open files by the `edit` command.
318319
- `EDITOR`: Its value would be used to open files by the `edit` command if `VISUAL` is unset.
319320
- `IRBRC`: The file specified would be evaluated as IRB's rc-file.

lib/irb/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def IRB.init_config(ap_path)
7676
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
7777
@CONF[:USE_COLORIZE] = (nc = ENV['NO_COLOR']).nil? || nc.empty?
7878
@CONF[:USE_AUTOCOMPLETE] = ENV.fetch("IRB_USE_AUTOCOMPLETE", "true") != "false"
79-
@CONF[:COMPLETOR] = :regexp
79+
@CONF[:COMPLETOR] = ENV.fetch("IRB_COMPLETOR", "regexp").to_sym
8080
@CONF[:INSPECT_MODE] = true
8181
@CONF[:USE_TRACER] = false
8282
@CONF[:USE_LOADER] = false

test/irb/test_init.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,34 @@ def test_use_autocomplete_environment_variable
120120
IRB.conf[:USE_AUTOCOMPLETE] = orig_use_autocomplete_conf
121121
end
122122

123+
def test_completor_environment_variable
124+
orig_use_autocomplete_env = ENV['IRB_COMPLETOR']
125+
orig_use_autocomplete_conf = IRB.conf[:COMPLETOR]
126+
127+
ENV['IRB_COMPLETOR'] = nil
128+
IRB.setup(__FILE__)
129+
assert_equal(:regexp, IRB.conf[:COMPLETOR])
130+
131+
ENV['IRB_COMPLETOR'] = 'regexp'
132+
IRB.setup(__FILE__)
133+
assert_equal(:regexp, IRB.conf[:COMPLETOR])
134+
135+
ENV['IRB_COMPLETOR'] = 'type'
136+
IRB.setup(__FILE__)
137+
assert_equal(:type, IRB.conf[:COMPLETOR])
138+
139+
ENV['IRB_COMPLETOR'] = 'regexp'
140+
IRB.setup(__FILE__, argv: ['--type-completor'])
141+
assert_equal :type, IRB.conf[:COMPLETOR]
142+
143+
ENV['IRB_COMPLETOR'] = 'type'
144+
IRB.setup(__FILE__, argv: ['--regexp-completor'])
145+
assert_equal :regexp, IRB.conf[:COMPLETOR]
146+
ensure
147+
ENV['IRB_COMPLETOR'] = orig_use_autocomplete_env
148+
IRB.conf[:COMPLETOR] = orig_use_autocomplete_conf
149+
end
150+
123151
def test_completor_setup_with_argv
124152
orig_completor_conf = IRB.conf[:COMPLETOR]
125153

0 commit comments

Comments
 (0)