Skip to content

Commit

Permalink
Merge pull request #281 from aycabta/retrieve-completed-receiver-that…
Browse files Browse the repository at this point in the history
…-is-a-module

Retrieve completed receiver that is a module or class correctly
  • Loading branch information
aycabta authored Sep 4, 2021
2 parents bba115e + a1ddf64 commit 7199b95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace
candidates.uniq!
end
if doc_namespace
"#{rec.class.name}#{sep}#{candidates.find{ |i| i == message }}"
rec_class = rec.is_a?(Module) ? rec : rec.class
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
else
select_message(receiver, message, candidates, sep)
end
Expand Down
7 changes: 7 additions & 0 deletions test/irb/test_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ def test_complete_require_relative

def test_complete_variable
str_example = ''
str_example.clear # suppress "assigned but unused variable" warning
assert_include(IRB::InputCompletor.retrieve_completion_data("str_examp", bind: binding), "str_example")
assert_equal(IRB::InputCompletor.retrieve_completion_data("str_example", bind: binding, doc_namespace: true), "String")
assert_equal(IRB::InputCompletor.retrieve_completion_data("str_example.to_s", bind: binding, doc_namespace: true), "String.to_s")
end

def test_complete_class_method
assert_include(IRB::InputCompletor.retrieve_completion_data("String.new", bind: binding), "String.new")
assert_equal(IRB::InputCompletor.retrieve_completion_data("String.new", bind: binding, doc_namespace: true), "String.new")
end
end
end

0 comments on commit 7199b95

Please sign in to comment.