Skip to content

Commit

Permalink
Merge pull request #78 from no6v/reserved-words
Browse files Browse the repository at this point in the history
fix reserved words and completion for them
  • Loading branch information
aycabta authored Feb 15, 2020
2 parents 73cda56 + 6184b22 commit dfd4f92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ module InputCompletor # :nodoc:
# Set of reserved words used by Ruby, you should not use these for
# constants or variables
ReservedWords = %w[
__ENCODING__ __LINE__ __FILE__
BEGIN END
alias and
begin break
case class
def defined do
def defined? do
else elsif end ensure
false for
if in
Expand Down Expand Up @@ -255,7 +256,7 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace

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

if doc_namespace
candidates.find{ |i| i == input }
Expand Down
12 changes: 12 additions & 0 deletions test/irb/test_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,17 @@ def test_complete_symbol
def test_complete_symbol_failure
assert_nil(IRB::InputCompletor::PerfectMatchedProc.(":aiueo", bind: binding))
end

def test_complete_reserved_words
candidates = IRB::InputCompletor.retrieve_completion_data("de", bind: binding)
%w[def defined?].each do |word|
assert_include candidates, word
end

candidates = IRB::InputCompletor.retrieve_completion_data("__", bind: binding)
%w[__ENCODING__ __LINE__ __FILE__].each do |word|
assert_include candidates, word
end
end
end
end

0 comments on commit dfd4f92

Please sign in to comment.