From 2ef3a24bca6ceeaf1877eee6749694982affb721 Mon Sep 17 00:00:00 2001 From: tompng Date: Sat, 25 Feb 2023 16:13:20 +0900 Subject: [PATCH 1/4] Improve method completion for string and regexp that includes word break characters --- lib/irb/completion.rb | 6 +++--- test/irb/test_completion.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 97f97dfaf..4d84b9474 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -166,10 +166,10 @@ 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)\.([^.]*)$/ + when /^(.*["'`])\.([^.]*)$/ # String receiver = $1 - message = $3 + message = $2 if doc_namespace "String.#{message}" @@ -178,7 +178,7 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace select_message(receiver, message, candidates) end - when /^(\/[^\/]*\/)\.([^.]*)$/ + when /^(.*\/)\.([^.]*)$/ # Regexp receiver = $1 message = $2 diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index b93b5e804..0ac95c4d0 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -14,11 +14,19 @@ def setup class TestMethodCompletion < TestCompletion def test_complete_string assert_include(IRB::InputCompletor.retrieve_completion_data("'foo'.up", bind: binding), "'foo'.upcase") + assert_not_include(IRB::InputCompletor.retrieve_completion_data("'foo'.up", bind: binding), "'foo'.update") + # completing 'foo bar'.up + assert_include(IRB::InputCompletor.retrieve_completion_data("bar'.up", bind: binding), "bar'.upcase") + assert_not_include(IRB::InputCompletor.retrieve_completion_data("bar'.up", bind: binding), "bar'.update") 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") + assert_not_include(IRB::InputCompletor.retrieve_completion_data("/foo/.ma", bind: binding), "/foo/.map") + # completing /foo bar/.ma + assert_include(IRB::InputCompletor.retrieve_completion_data("bar/.ma", bind: binding), "bar/.match") + assert_not_include(IRB::InputCompletor.retrieve_completion_data("bar/.ma", bind: binding), "bar/.map") assert_equal("Regexp.match", IRB::InputCompletor.retrieve_completion_data("/foo/.match", bind: binding, doc_namespace: true)) end From 08af557b82e1466a4b0fe535342d912cfcbd4f6d Mon Sep 17 00:00:00 2001 From: tompng Date: Mon, 6 Mar 2023 01:10:05 +0900 Subject: [PATCH 2/4] Remove completion-test's assert_not_include because candidates no longer include every possible methods --- test/irb/test_completion.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index 0ac95c4d0..4ae1d63bf 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -14,19 +14,15 @@ def setup class TestMethodCompletion < TestCompletion def test_complete_string assert_include(IRB::InputCompletor.retrieve_completion_data("'foo'.up", bind: binding), "'foo'.upcase") - assert_not_include(IRB::InputCompletor.retrieve_completion_data("'foo'.up", bind: binding), "'foo'.update") # completing 'foo bar'.up assert_include(IRB::InputCompletor.retrieve_completion_data("bar'.up", bind: binding), "bar'.upcase") - assert_not_include(IRB::InputCompletor.retrieve_completion_data("bar'.up", bind: binding), "bar'.update") 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") - assert_not_include(IRB::InputCompletor.retrieve_completion_data("/foo/.ma", bind: binding), "/foo/.map") # completing /foo bar/.ma assert_include(IRB::InputCompletor.retrieve_completion_data("bar/.ma", bind: binding), "bar/.match") - assert_not_include(IRB::InputCompletor.retrieve_completion_data("bar/.ma", bind: binding), "bar/.map") assert_equal("Regexp.match", IRB::InputCompletor.retrieve_completion_data("/foo/.match", bind: binding, doc_namespace: true)) end From d0825f0060a4a1dfc9497b3fefb0e824b8387f65 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Mon, 6 Mar 2023 02:20:52 +0900 Subject: [PATCH 3/4] Add comment about string's method completion regexp Co-authored-by: Stan Lo --- lib/irb/completion.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 4d84b9474..ca2fb5481 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -166,6 +166,8 @@ 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 + # 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 From bb96a543d49f3573a86d64b2e119993265da415b Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Mon, 6 Mar 2023 02:21:10 +0900 Subject: [PATCH 4/4] Add comment about regexp's method completion regexp Co-authored-by: Stan Lo --- lib/irb/completion.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index ca2fb5481..45c696622 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -180,6 +180,8 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace select_message(receiver, message, candidates) end + # 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