зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
9ffaa7e96b
Коммит
aa3cb74b81
|
@ -1,3 +1,7 @@
|
||||||
|
Tue Jan 18 18:31:14 2011 Keiju Ishitsuka <keiju@ishitsuka.com>
|
||||||
|
|
||||||
|
* lib/irb/comletion.rb: Irb tab completion support for XX::method forms.
|
||||||
|
|
||||||
Tue Jan 18 15:05:55 2011 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
Tue Jan 18 15:05:55 2011 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* lib/logger.rb: added RDoc document for logging message escape
|
* lib/logger.rb: added RDoc document for logging message escape
|
||||||
|
|
|
@ -91,60 +91,73 @@ module IRB
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
|
select_message(receiver, message, candidates, "::")
|
||||||
|
|
||||||
when /^(:[^:.]+)\.([^.]*)$/
|
when /^(:[^:.]+)(\.|::)([^.]*)$/
|
||||||
# Symbol
|
# Symbol
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
sep = $2
|
||||||
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
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
|
# Numeric
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($5)
|
sep = $5
|
||||||
|
message = Regexp.quote($6)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
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)
|
# Numeric(0xFFFF)
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
sep = $2
|
||||||
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates, sep)
|
||||||
|
|
||||||
when /^(\$[^.]*)$/
|
when /^(\$[^.]*)$/
|
||||||
|
# global var
|
||||||
regmessage = Regexp.new(Regexp.quote($1))
|
regmessage = Regexp.new(Regexp.quote($1))
|
||||||
candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
|
candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
|
||||||
|
|
||||||
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
|
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
|
||||||
# when /^((\.?[^.]+)+)\.([^.]*)$/
|
# when /^((\.?[^.]+)+)\.([^.]*)$/
|
||||||
when /^([^."].*)\.([^.]*)$/
|
# when /^([^."].*)\.([^.]*)$/
|
||||||
# variable
|
when /^([^."].*)(\.|::)([^.]*)$/
|
||||||
|
# variable.func or func.func
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
sep = $2
|
||||||
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
gv = eval("global_variables", bind).collect{|m| m.to_s}
|
gv = eval("global_variables", bind).collect{|m| m.to_s}
|
||||||
lv = eval("local_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}
|
cv = eval("self.class.constants", bind).collect{|m| m.to_s}
|
||||||
|
|
||||||
if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
|
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
|
# Foo::Bar.func
|
||||||
begin
|
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
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
|
@ -164,7 +177,7 @@ module IRB
|
||||||
candidates.sort!
|
candidates.sort!
|
||||||
candidates.uniq!
|
candidates.uniq!
|
||||||
end
|
end
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates, sep)
|
||||||
|
|
||||||
when /^\.([^.]*)$/
|
when /^\.([^.]*)$/
|
||||||
# unknown(maybe String)
|
# 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|
|
candidates.grep(/^#{message}/).collect do |e|
|
||||||
case e
|
case e
|
||||||
when /^[a-zA-Z_]/
|
when /^[a-zA-Z_]/
|
||||||
receiver + "." + e
|
receiver + sep + e
|
||||||
when /^[0-9]/
|
when /^[0-9]/
|
||||||
when *Operators
|
when *Operators
|
||||||
#receiver + " " + e
|
#receiver + " " + e
|
||||||
|
|
Загрузка…
Ссылка в новой задаче