[macruby-changes] [4765] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 04:11:39 PDT 2010


Revision: 4765
          http://trac.macosforge.org/projects/ruby/changeset/4765
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 04:11:37 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Don't break when trying to complete a string or garbage. Fix for MacRuby ticket #943.

Also add TODO about completing file paths in strings.

From: Eloy Duran <eloy.de.enige at gmail.com>

Modified Paths:
--------------
    DietRB/trunk/TODO
    DietRB/trunk/lib/irb/ext/completion.rb
    DietRB/trunk/spec/ext/completion_spec.rb

Modified: DietRB/trunk/TODO
===================================================================
--- DietRB/trunk/TODO	2010-10-08 11:11:26 UTC (rev 4764)
+++ DietRB/trunk/TODO	2010-10-08 11:11:37 UTC (rev 4765)
@@ -1,3 +1,4 @@
+* Complete file paths in strings (for require etc)
 * Write docs for using a as library. Probably right after creating a Cocoa client.
 * Add specs for irb/driver/socket, and possibly for bin/dietrb
 * Configurable history file? (:HISTORY_FILE) Configurable number of saved history lines? (:SAVE_HISTORY)

Modified: DietRB/trunk/lib/irb/ext/completion.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/completion.rb	2010-10-08 11:11:26 UTC (rev 4764)
+++ DietRB/trunk/lib/irb/ext/completion.rb	2010-10-08 11:11:37 UTC (rev 4765)
@@ -89,11 +89,10 @@
       call = (source[-1,1] == '.')
       receiver = source = source[0..-2] if call
       
-      if sexp = Ripper::SexpBuilder.new(source).parse
-        # [:program, [:stmts_add, [:stmts_new], [x, …]]]
-        #                                        ^
-        root = sexp[1][2]
-        
+      # root node:
+      # [:program, [:stmts_add, [:stmts_new], [x, …]]]
+      #                                        ^
+      if (sexp = Ripper::SexpBuilder.new(source).parse) && root = sexp[1][2]
         # [:call, [:hash, nil], :".", [:@ident, x, …]]
         if root[TYPE] == :call
           call  = true
@@ -113,17 +112,14 @@
           end
         end
         
-        if call
-          if results = (methods || methods_of_object(root))
-            format_methods(receiver, results, filter)
-          else
-            # this is mainly because MacRuby currently has a problem with local_variables,
-            # normally I'd prefer to let the program die so the user might report it
-            []
-          end
-        else
-          match_methods_vars_or_consts_in_scope(root)
-        end.sort.uniq
+        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
+        result.sort.uniq if result
       end
     end
     
@@ -140,7 +136,7 @@
     def match_methods_vars_or_consts_in_scope(symbol)
       var    = symbol[VALUE]
       filter = var[VALUE]
-      case var[TYPE]
+      result = case var[TYPE]
       when :@ident
         local_variables + instance_methods + RESERVED_DOWNCASE_WORDS
       when :@ivar
@@ -154,7 +150,8 @@
         else
           constants + RESERVED_UPCASE_WORDS
         end
-      end.grep(/^#{Regexp.quote(filter)}/)
+      end
+      (result && filter) ? result.grep(/^#{Regexp.quote(filter)}/) : result
     end
     
     def format_methods(receiver, methods, filter)

Modified: DietRB/trunk/spec/ext/completion_spec.rb
===================================================================
--- DietRB/trunk/spec/ext/completion_spec.rb	2010-10-08 11:11:26 UTC (rev 4764)
+++ DietRB/trunk/spec/ext/completion_spec.rb	2010-10-08 11:11:37 UTC (rev 4765)
@@ -248,4 +248,9 @@
       complete(word[0..-2]).should include(word)
     end
   end
-end
\ No newline at end of file
+
+  it "does not crash when trying to complete garbage" do
+    complete("/").should == nil
+    complete("./Rake").should == nil
+  end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/c64fb039/attachment.html>


More information about the macruby-changes mailing list