[macruby-changes] [4754] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 04:10:03 PDT 2010
Revision: 4754
http://trac.macosforge.org/projects/ruby/changeset/4754
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 04:10:02 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Complete instance variables and make sure that if some code wasn't completed it will never try to filter them.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/ext/completion.rb
DietRB/trunk/spec/ext/completion_spec.rb
Modified: DietRB/trunk/lib/irb/ext/completion.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/completion.rb 2010-10-08 11:09:52 UTC (rev 4753)
+++ DietRB/trunk/lib/irb/ext/completion.rb 2010-10-08 11:10:02 UTC (rev 4754)
@@ -59,6 +59,14 @@
evaluate('local_variables').map(&:to_s)
end
+ def instance_variables
+ context.object.instance_variables.map(&:to_s)
+ end
+
+ def global_variables
+ super.map(&:to_s)
+ end
+
def instance_methods
context.object.methods.map(&:to_s)
end
@@ -106,7 +114,11 @@
end
if call
- format_methods(receiver, methods || methods_of_object(root), filter)
+ if results = (methods || methods_of_object(root))
+ format_methods(receiver, results, filter)
+ else
+ []
+ end
else
match_methods_vars_or_consts_in_scope(root)
end.sort.uniq
@@ -129,8 +141,10 @@
case var[TYPE]
when :@ident
local_variables + instance_methods + RESERVED_DOWNCASE_WORDS
+ when :@ivar
+ instance_variables
when :@gvar
- global_variables.map(&:to_s)
+ global_variables
when :@const
if symbol[TYPE] == :top_const_ref
filter = "::#{filter}"
@@ -174,8 +188,10 @@
case type
when :@ident
evaluate(name).methods if local_variables.include?(name)
+ when :@ivar
+ evaluate(name).methods if instance_variables.include?(name)
when :@gvar
- eval(name).methods if global_variables.include?(name.to_sym)
+ eval(name).methods if global_variables.include?(name)
when :@const
evaluate(name).methods if constants.include?(name)
end
Modified: DietRB/trunk/spec/ext/completion_spec.rb
===================================================================
--- DietRB/trunk/spec/ext/completion_spec.rb 2010-10-08 11:09:52 UTC (rev 4753)
+++ DietRB/trunk/spec/ext/completion_spec.rb 2010-10-08 11:10:02 UTC (rev 4754)
@@ -58,6 +58,11 @@
complete('foo.').should include('foo.singleton_method')
end
+ it "matches as an instance variable" do
+ @context.__evaluate__('@an_instance_variable = ::CompletionStub.new')
+ complete('@an_instance_variable.').should == imethods(::CompletionStub, '@an_instance_variable')
+ end
+
it "matches as a global variable" do
complete('$a_completion_stub.').should == imethods(::CompletionStub, '$a_completion_stub')
end
@@ -193,9 +198,10 @@
end
it "filters the methods, of the variable receiver, by the given method name" do
- @context.__evaluate__('foo = ::CompletionStub.new')
+ @context.__evaluate__('foo = @an_instance_variable = ::CompletionStub.new')
complete('foo.an_im').should == %w{ foo.an_imethod }
complete('$a_completion_stub.an_im').should == %w{ $a_completion_stub.an_imethod }
+ complete('@an_instance_variable.an_im').should == %w{ @an_instance_variable.an_imethod }
# TODO: fix
# complete('CompletionStub.a_sing').should == %w{ CompletionStub.a_singleton_method }
end
@@ -204,7 +210,7 @@
describe "when *not* doing a method call on an explicit receiver" do
before do
- @context.__evaluate__("a_local_variable = :ok")
+ @context.__evaluate__("a_local_variable = @an_instance_variable = :ok")
end
it "matches local variables" do
@@ -219,6 +225,10 @@
complete("a_loc").should == %w{ a_local_method a_local_variable }
end
+ it "matches instance variables" do
+ complete("@an_inst").should == %w{ @an_instance_variable }
+ end
+
it "matches global variables" do
complete("$a_completion_s").should == %w{ $a_completion_stub }
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/f080d9a8/attachment-0001.html>
More information about the macruby-changes
mailing list