[macruby-changes] [4866] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 1 16:06:45 PDT 2010
Revision: 4866
http://trac.macosforge.org/projects/ruby/changeset/4866
Author: eloy.de.enige at gmail.com
Date: 2010-11-01 16:06:43 -0700 (Mon, 01 Nov 2010)
Log Message:
-----------
Complete file paths in strings that aren't closed yet.
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-11-01 21:06:39 UTC (rev 4865)
+++ DietRB/trunk/lib/irb/ext/completion.rb 2010-11-01 23:06:43 UTC (rev 4866)
@@ -113,15 +113,28 @@
end
result = if call
- if m = (methods || methods_of_object(root))
- format_methods(receiver, m, filter)
- end
- else
- match_methods_vars_or_consts_in_scope(root)
- end
+ if m = (methods || methods_of_object(root))
+ format_methods(receiver, m, filter)
+ end
+ elsif root[TYPE] == :string_literal && root[VALUE][TYPE] == :string_content
+ # in the form of: "~/code/
+ expand_path(source)
+ else
+ match_methods_vars_or_consts_in_scope(root)
+ end
result.sort.uniq if result
end
end
+
+ def expand_path(source)
+ tokens = Ripper.lex(source)
+ path = tokens[0][2]
+ string_open = tokens[1][2]
+ end_with_slash = path.length > 1 && path.end_with?('/')
+ path = File.expand_path(path)
+ path << '/' if end_with_slash
+ Dir.glob("#{path}*", File::FNM_CASEFOLD).map { |f| "#{string_open}#{f}" }
+ end
def unwind_callstack(root, stack = [])
if root[TYPE] == :call
Modified: DietRB/trunk/spec/ext/completion_spec.rb
===================================================================
--- DietRB/trunk/spec/ext/completion_spec.rb 2010-11-01 21:06:39 UTC (rev 4865)
+++ DietRB/trunk/spec/ext/completion_spec.rb 2010-11-01 23:06:43 UTC (rev 4866)
@@ -249,6 +249,13 @@
end
end
+ it "completes file paths" do
+ complete("'/").should == Dir.glob('/*').sort.map { |f| "'#{f}" }
+ complete("'#{ROOT}/lib/../Ra").should == ["'#{File.join(ROOT, "Rakefile")}"]
+ complete("%{#{ROOT}/li").should == ['LICENSE', 'lib'].map { |f| "%{#{File.join(ROOT, f)}" }
+ complete("\"#{ROOT}/lib/").should == ['irb', 'irb.rb'].map { |f| "\"#{File.join(ROOT, 'lib', f)}" }
+ end
+
it "does not crash when trying to complete garbage" do
complete("/").should == nil
complete("./Rake").should == nil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101101/e00e6dff/attachment.html>
More information about the macruby-changes
mailing list