Permalink
Browse files

Complete file paths in strings that aren't closed yet.

git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@4866 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 01c4c4e commit 9b3f0a44d49d8b2700c5b5c185db179fa4468855 @alloy alloy committed Nov 1, 2010
Showing with 26 additions and 6 deletions.
  1. +19 −6 lib/irb/ext/completion.rb
  2. +7 −0 spec/ext/completion_spec.rb
View
@@ -113,15 +113,28 @@ def results
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
@@ -249,6 +249,13 @@ def a_local_method; end
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

0 comments on commit 9b3f0a4

Please sign in to comment.