From aa3cb74b8105d362f48064f0798c794b7fcc9a72 Mon Sep 17 00:00:00 2001 From: keiju Date: Tue, 18 Jan 2011 09:34:10 +0000 Subject: * lib/irb/comletion.rb: Irb tab completion support for XX::method forms. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/irb/completion.rb | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'lib/irb/completion.rb') diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index e059bc4055..ee5cf69409 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -91,60 +91,73 @@ module IRB rescue Exception candidates = [] end - candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e} + select_message(receiver, message, candidates, "::") - when /^(:[^:.]+)\.([^.]*)$/ + when /^(:[^:.]+)(\.|::)([^.]*)$/ # Symbol receiver = $1 - message = Regexp.quote($2) + sep = $2 + message = Regexp.quote($3) candidates = Symbol.instance_methods.collect{|m| m.to_s} - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) - when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/ + when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)(\.|::)([^.]*)$/ # Numeric receiver = $1 - message = Regexp.quote($5) + sep = $5 + message = Regexp.quote($6) begin candidates = eval(receiver, bind).methods.collect{|m| m.to_s} rescue Exception candidates = [] end - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) - when /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/ + when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/ # Numeric(0xFFFF) receiver = $1 - message = Regexp.quote($2) + sep = $2 + message = Regexp.quote($3) begin candidates = eval(receiver, bind).methods.collect{|m| m.to_s} rescue Exception candidates = [] end - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) when /^(\$[^.]*)$/ + # global var regmessage = Regexp.new(Regexp.quote($1)) candidates = global_variables.collect{|m| m.to_s}.grep(regmessage) # when /^(\$?(\.?[^.]+)+)\.([^.]*)$/ # when /^((\.?[^.]+)+)\.([^.]*)$/ - when /^([^."].*)\.([^.]*)$/ - # variable +# when /^([^."].*)\.([^.]*)$/ + when /^([^."].*)(\.|::)([^.]*)$/ + # variable.func or func.func receiver = $1 - message = Regexp.quote($2) + sep = $2 + message = Regexp.quote($3) gv = eval("global_variables", bind).collect{|m| m.to_s} lv = eval("local_variables", bind).collect{|m| m.to_s} cv = eval("self.class.constants", bind).collect{|m| m.to_s} if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver - # foo.func and foo is local var. OR + # foo.func and foo is var. OR + # foo::func and foo is var. OR + # foo::Const and foo is var. OR # Foo::Bar.func begin - candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s} + candidates = [] + rec = eval(receiver, bind) + if sep == "::" and rec.kind_of?(Module) + candidates = rec.constants.collect{|m| m.to_s} + end + candidates |= rec.methods.collect{|m| m.to_s} rescue Exception candidates = [] end @@ -164,7 +177,7 @@ module IRB candidates.sort! candidates.uniq! end - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) when /^\.([^.]*)$/ # unknown(maybe String) @@ -186,11 +199,11 @@ module IRB "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>", "[]", "[]=", "^", "!", "!=", "!~"] - def self.select_message(receiver, message, candidates) + def self.select_message(receiver, message, candidates, sep = ".") candidates.grep(/^#{message}/).collect do |e| case e when /^[a-zA-Z_]/ - receiver + "." + e + receiver + sep + e when /^[0-9]/ when *Operators #receiver + " " + e -- cgit v1.2.3