summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-10-06 20:10:09 +0900
committergit <svn-admin@ruby-lang.org>2024-10-06 11:10:12 +0000
commit98620f6c5246d27fed440b8d61cdb31cd915eafa (patch)
tree5710416c6e8402d7774c630dbfbdbd1449521ec9 /lib
parenta6383fbe1628bdaa9ec6a30b3baa60dd7430b461 (diff)
[ruby/irb] Change default completor from regexp to auto, try
TypeCompletor and fallback to RegexpCompletor. (https://github.com/ruby/irb/pull/1010) https://github.com/ruby/irb/commit/bb6a99d815
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/context.rb14
-rw-r--r--lib/irb/init.rb2
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index 668a823f5c..505bed80a1 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -176,11 +176,17 @@ module IRB
private def build_completor
completor_type = IRB.conf[:COMPLETOR]
+
+ # Gem repl_type_completor is added to bundled gems in Ruby 3.4.
+ # Use :type as default completor only in Ruby 3.4 or later.
+ verbose = !!completor_type
+ completor_type ||= RUBY_VERSION >= '3.4' ? :type : :regexp
+
case completor_type
when :regexp
return RegexpCompletor.new
when :type
- completor = build_type_completor
+ completor = build_type_completor(verbose: verbose)
return completor if completor
else
warn "Invalid value for IRB.conf[:COMPLETOR]: #{completor_type}"
@@ -189,17 +195,17 @@ module IRB
RegexpCompletor.new
end
- private def build_type_completor
+ private def build_type_completor(verbose:)
if RUBY_ENGINE == 'truffleruby'
# Avoid SyntaxError. truffleruby does not support endless method definition yet.
- warn 'TypeCompletor is not supported on TruffleRuby yet'
+ warn 'TypeCompletor is not supported on TruffleRuby yet' if verbose
return
end
begin
require 'repl_type_completor'
rescue LoadError => e
- warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}"
+ warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}" if verbose
return
end
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index 7dc08912ef..d474bd41d6 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -80,7 +80,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] = ENV.fetch("IRB_COMPLETOR", "regexp").to_sym
+ @CONF[:COMPLETOR] = ENV["IRB_COMPLETOR"]&.to_sym
@CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false
@CONF[:USE_LOADER] = false