diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 97f97dfaf..45c696622 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -166,10 +166,12 @@ def self.retrieve_files_to_require_relative_from_current_dir def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding, doc_namespace: false) case input - when /^((["'`]).*\2)\.([^.]*)$/ + # this regexp only matches the closing character because of irb's Reline.completer_quote_characters setting + # details are described in: https://github.com/ruby/irb/pull/523 + when /^(.*["'`])\.([^.]*)$/ # String receiver = $1 - message = $3 + message = $2 if doc_namespace "String.#{message}" @@ -178,7 +180,9 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace select_message(receiver, message, candidates) end - when /^(\/[^\/]*\/)\.([^.]*)$/ + # this regexp only matches the closing character because of irb's Reline.completer_quote_characters setting + # details are described in: https://github.com/ruby/irb/pull/523 + when /^(.*\/)\.([^.]*)$/ # Regexp receiver = $1 message = $2 diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index b93b5e804..4ae1d63bf 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -14,11 +14,15 @@ def setup class TestMethodCompletion < TestCompletion def test_complete_string assert_include(IRB::InputCompletor.retrieve_completion_data("'foo'.up", bind: binding), "'foo'.upcase") + # completing 'foo bar'.up + assert_include(IRB::InputCompletor.retrieve_completion_data("bar'.up", bind: binding), "bar'.upcase") assert_equal("String.upcase", IRB::InputCompletor.retrieve_completion_data("'foo'.upcase", bind: binding, doc_namespace: true)) end def test_complete_regexp assert_include(IRB::InputCompletor.retrieve_completion_data("/foo/.ma", bind: binding), "/foo/.match") + # completing /foo bar/.ma + assert_include(IRB::InputCompletor.retrieve_completion_data("bar/.ma", bind: binding), "bar/.match") assert_equal("Regexp.match", IRB::InputCompletor.retrieve_completion_data("/foo/.match", bind: binding, doc_namespace: true)) end