Skip to content

Commit

Permalink
Detect the variable class to show doc
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Sep 2, 2021
1 parent a9db71e commit 33b9bec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/irb/completion.rb
Expand Up @@ -315,12 +315,19 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace
end

else
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
candidates |= ReservedWords

if doc_namespace
candidates.find{ |i| i == input }
vars = eval("local_variables | instance_variables", bind).collect{|m| m.to_s}
perfect_match_var = vars.find{|m| m.to_s == input}
if perfect_match_var
eval("#{perfect_match_var}.class.name", bind)
else
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
candidates |= ReservedWords
candidates.find{ |i| i == input }
end
else
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
candidates |= ReservedWords
candidates.grep(/^#{Regexp.quote(input)}/)
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/irb/test_completion.rb
Expand Up @@ -83,5 +83,11 @@ def test_complete_require_relative
assert_include candidates, word
end
end

def test_complete_variable
str_example = ''
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")
end
end
end

0 comments on commit 33b9bec

Please sign in to comment.