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

Enable completion setting through IRB_COMPLETOR #771

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ irb(main):002> a.first. # Completes Integer methods

- `NO_COLOR`: Assigning a value to it disables IRB's colorization.
- `IRB_USE_AUTOCOMPLETE`: Setting it to `false` disables IRB's autocompletion.
- `IRB_COMPLETOR`: Configures IRB's auto-completion behavior, allowing settings for either `regexp` or `type`.
- `VISUAL`: Its value would be used to open files by the `edit` command.
- `EDITOR`: Its value would be used to open files by the `edit` command if `VISUAL` is unset.
- `IRBRC`: The file specified would be evaluated as IRB's rc-file.
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def IRB.init_config(ap_path)
@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
Expand Down
28 changes: 28 additions & 0 deletions test/irb/test_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,34 @@ def test_use_autocomplete_environment_variable
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])
st0012 marked this conversation as resolved.
Show resolved Hide resolved

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]

Expand Down