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

Improve method completion for string and regexp that includes word break characters #523

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 /^(.*["'`])\.([^.]*)$/
tompng marked this conversation as resolved.
Show resolved Hide resolved
# String
receiver = $1
message = $3
message = $2

if doc_namespace
"String.#{message}"
Expand All @@ -178,7 +178,7 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace
select_message(receiver, message, candidates)
end

when /^(\/[^\/]*\/)\.([^.]*)$/
when /^(.*\/)\.([^.]*)$/
tompng marked this conversation as resolved.
Show resolved Hide resolved
# Regexp
receiver = $1
message = $2
Expand Down
8 changes: 8 additions & 0 deletions test/irb/test_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
st0012 marked this conversation as resolved.
Show resolved Hide resolved
# 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

Expand Down