Skip to content

Commit

Permalink
Complete reserved words
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Oct 18, 2023
1 parent 8adacb2 commit 14ca0bb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
47 changes: 24 additions & 23 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@

module IRB
class BaseCompletor # :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
else elsif end ensure
false for
if in
module
next nil not
or
redo rescue retry return
self super
then true
undef unless until
when while
yield
]

def completion_candidates(preposing, target, postposing, bind:)
raise NotImplementedError
end
Expand Down Expand Up @@ -98,29 +122,6 @@ def inspect
'RegexpCompletor'
end

# 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
else elsif end ensure
false for
if in
module
next nil not
or
redo rescue retry return
self super
then true
undef unless until
when while
yield
]

def complete_require_path(target, preposing, postposing)
if target =~ /\A(['"])([^'"]+)\Z/
quote = $1
Expand Down
4 changes: 2 additions & 2 deletions lib/irb/type_completion/completor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def candidates_from_result(result)
end
(scope_constants.compact | type.constants.map(&:to_s)).sort
else
scope.constants.sort
scope.constants.sort | ReservedWords
end
in [:ivar, name, scope]
ivars = scope.instance_variables.sort
Expand All @@ -134,7 +134,7 @@ def candidates_from_result(result)
in [:call, type, name, self_call]
(self_call ? type.all_methods : type.methods).map(&:to_s) - HIDDEN_METHODS
in [:lvar_or_method, name, scope]
scope.self_type.all_methods.map(&:to_s) | scope.local_variables
scope.self_type.all_methods.map(&:to_s) | scope.local_variables | ReservedWords
else
[]
end
Expand Down

0 comments on commit 14ca0bb

Please sign in to comment.