From dadd45b569c5e9f702d634085ed775bd51c957f1 Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 19 Oct 2023 00:00:59 +0900 Subject: [PATCH] Complete reserved words --- lib/irb/completion.rb | 47 ++++++++++++++-------------- lib/irb/type_completion/completor.rb | 4 +-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 9c3ea7836..e3ebe4abf 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -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 @@ -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 diff --git a/lib/irb/type_completion/completor.rb b/lib/irb/type_completion/completor.rb index 188535fee..95a447832 100644 --- a/lib/irb/type_completion/completor.rb +++ b/lib/irb/type_completion/completor.rb @@ -111,7 +111,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 @@ -125,7 +125,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