[macruby-changes] [4633] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:51:40 PDT 2010
Revision: 4633
http://trac.macosforge.org/projects/ruby/changeset/4633
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:51:39 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Filter completion results by partial method name.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/ext/completion.rb
DietRB/trunk/spec/completion_spec.rb
Modified: DietRB/trunk/lib/irb/ext/completion.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/completion.rb 2010-10-08 10:51:29 UTC (rev 4632)
+++ DietRB/trunk/lib/irb/ext/completion.rb 2010-10-08 10:51:39 UTC (rev 4633)
@@ -38,19 +38,20 @@
src = src[0..-2] if call
# p src, call
- tree = Ripper::SexpBuilder.new(src).parse
- # p @source, tree
-
- # [:program, [:stmts_add, [:stmts_new], [x, …]]]
- # ^
- process_any(tree[1][2])
+ if tree = Ripper::SexpBuilder.new(src).parse
+ # p @source, tree
+ # [:program, [:stmts_add, [:stmts_new], [x, …]]]
+ # ^
+ process_any(tree[1][2])
+ end
end
def process_any(tree)
result = case tree[0]
- # [:program, [:stmts_add, [:stmts_new], [:unary, :-@, [x, …]]]]
- # ^
+ # [:unary, :-@, [x, …]]
+ # ^
when :unary then process_any(tree[2])
+ when :call then process_filter(tree)
when :var_ref, :top_const_ref then process_variable(tree)
when :array, :words_add, :qwords_add then Array
when :@int then Fixnum
@@ -69,6 +70,14 @@
end
end
+ def process_filter(tree)
+ # [:call, [:hash, nil], :".", [:@ident, x, …]]
+ # ^
+ if list = process_any(tree[1])
+ list.grep(/^#{tree[3][1]}/)
+ end
+ end
+
def process_variable(tree)
type, name = tree[1][0..1]
Modified: DietRB/trunk/spec/completion_spec.rb
===================================================================
--- DietRB/trunk/spec/completion_spec.rb 2010-10-08 10:51:29 UTC (rev 4632)
+++ DietRB/trunk/spec/completion_spec.rb 2010-10-08 10:51:39 UTC (rev 4633)
@@ -33,7 +33,7 @@
class Playground
CompletionStub = Object.new
- def CompletionStub.singleton_method; end
+ def CompletionStub.a_singleton_method; end
def a_local_method; end
end
@@ -174,4 +174,24 @@
complete('-100_000_000_000_000_000_000.0.').should == imethods(Float)
end
end
+end
+
+describe "IRB::Completion, when the source does not end with a period" do
+ extend CompletionHelper
+
+ before do
+ @context = IRB::Context.new(Playground.new)
+ end
+
+ it "filters the methods of a literal by the called method name" do
+ complete('//.nam').should == %w{ names named_captures }
+ complete('//.named').should == %w{ named_captures }
+ end
+
+ it "filters the methods of an object, reference by variable, by the called method name" do
+ @context.__evaluate__('foo = ::CompletionStub.new')
+ complete('foo.an_im').should == %w{ an_imethod }
+ complete('CompletionStub.a_sing').should == %w{ a_singleton_method }
+ complete('$a_completion_stub.an_im').should == %w{ an_imethod }
+ end
end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/82df7237/attachment-0001.html>
More information about the macruby-changes
mailing list