]> git.saurik.com Git - cycript.git/blobdiff - Complete.cpp
Use -Wl,dead_strip to cut a little readline cruft.
[cycript.git] / Complete.cpp
index 820895c9c91776af12b040caace6244758274367..47acf10263097d075274ef2625d76d40fc5de14c 100644 (file)
@@ -19,6 +19,8 @@
 **/
 /* }}} */
 
 **/
 /* }}} */
 
+#include <typeinfo>
+
 #include "cycript.hpp"
 
 #include "Driver.hpp"
 #include "cycript.hpp"
 
 #include "Driver.hpp"
@@ -84,7 +86,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
 
         case CYDriver::AutoMessage: {
             CYDriver::Context &thing(driver.contexts_.back());
 
         case CYDriver::AutoMessage: {
             CYDriver::Context &thing(driver.contexts_.back());
-            expression = $M($C1($V("object_getClass"), thing.context_), $S("messages"));
+            expression = $M($C1($V("object_getClass"), thing.context_), $S("prototype"));
             for (CYDriver::Context::Words::const_iterator part(thing.words_.begin()); part != thing.words_.end(); ++part)
                 prefix << (*part)->word_ << ':';
         } break;
             for (CYDriver::Context::Words::const_iterator part(thing.words_.begin()); part != thing.words_.end(); ++part)
                 prefix << (*part)->word_ << ':';
         } break;
@@ -109,8 +111,14 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
 
     std::string begin(prefix.str());
 
 
     std::string begin(prefix.str());
 
-    driver.script_ = $ CYScript($ CYExpress($C3(ParseExpression(pool,
-    "   function(object, prefix, word) {\n"
+    CYBoolean *message;
+    if (driver.mode_ == CYDriver::AutoMessage)
+        message = $ CYTrue();
+    else
+        message = $ CYFalse();
+
+    driver.script_ = $ CYScript($ CYExpress($C4(ParseExpression(pool,
+    "   function(object, prefix, word, message) {\n"
     "       var names = [];\n"
     "       var before = prefix.length;\n"
     "       prefix += word;\n"
     "       var names = [];\n"
     "       var before = prefix.length;\n"
     "       prefix += word;\n"
@@ -120,10 +128,8 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
     "               if (name.substring(0, entire) == prefix)\n"
     "                   names.push(name);\n"
     "       } else do {\n"
     "               if (name.substring(0, entire) == prefix)\n"
     "                   names.push(name);\n"
     "       } else do {\n"
-    "           if (object.hasOwnProperty(\"cy$complete\")) {\n"
-    "               names = names.concat(object.cy$complete(prefix));\n"
-    "               continue;\n"
-    "           }\n"
+    "           if (object.hasOwnProperty(\"cy$complete\"))\n"
+    "               names = names.concat(object.cy$complete(prefix, message));\n"
     "           try {\n"
     "               var local = Object.getOwnPropertyNames(object);\n"
     "           } catch (e) {\n"
     "           try {\n"
     "               var local = Object.getOwnPropertyNames(object);\n"
     "           } catch (e) {\n"
@@ -135,7 +141,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
     "       } while (object = typeof object === 'object' ? Object.getPrototypeOf(object) : object.__proto__);\n"
     "       return names;\n"
     "   }\n"
     "       } while (object = typeof object === 'object' ? Object.getPrototypeOf(object) : object.__proto__);\n"
     "       return names;\n"
     "   }\n"
-    ), expression, $S(begin.c_str()), $S(word))));
+    ), expression, $S(begin.c_str()), $S(word), message)));
 
     driver.script_->Replace(context);
 
 
     driver.script_->Replace(context);
 
@@ -167,20 +173,19 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
         _assert(value != NULL);
         element = value->next_;
 
         _assert(value != NULL);
         element = value->next_;
 
-        CYString *string(dynamic_cast<CYString *>(value->value_));
-        _assert(string != NULL);
-
-        CYUTF8String completion;
-        if (string->size_ != 0)
-            completion = {string->value_, string->size_};
-        else if (driver.mode_ == CYDriver::AutoMessage)
-            completion = "]";
-        else
-            continue;
+        _assert(value->value_ != NULL);
+        CYString *string(value->value_->String(context));
+        if (string == NULL)
+            CYThrow("string was actually %s", typeid(*value->value_).name());
 
 
+        CYUTF8String completion(string->value_, string->size_);
+        _assert(completion.size >= begin.size());
         completion.data += begin.size();
         completion.size -= begin.size();
 
         completion.data += begin.size();
         completion.size -= begin.size();
 
+        if (completion.size == 0 && driver.mode_ == CYDriver::AutoMessage)
+            completion = "]";
+
         if (CYStartsWith(completion, "$cy"))
             continue;
         completions.push_back(completion);
         if (CYStartsWith(completion, "$cy"))
             continue;
         completions.push_back(completion);