src/Palete/Gtk.vala
[app.Builder.js] / src / Palete / Gtk.vala
index 46e77cc..2bb7c2f 100644 (file)
@@ -34,6 +34,9 @@ namespace Palete {
                    var context = new Vala.CodeContext ();
                         
                    this.package_cache = this.loadPackages(Path.get_dirname (context.get_vapi_path("glib-2.0")));
+                   this.package_cache.add_all(
+                           this.loadPackages(Path.get_dirname (context.get_vapi_path("gee-1.0")))
+                   );
                                //this.load();
                    // various loader methods..
                      //this.map = [];
@@ -227,9 +230,15 @@ namespace Palete {
 
                        var ret = new  Gee.ArrayList<string>();
                        //this.package_cache = new Gee.ArrayList<string>();
-                        
+                       
+                       if (!GLib.FileUtils.test(dirname,  FileTest.IS_DIR)) {
+                               print("opps package directory %s does not exist", dirname);
+                               return ret;
+                       }
                         
                        var dir = File.new_for_path(dirname);
+                       
+                       
                        try {
                                var file_enum = dir.enumerate_children(
                                        GLib.FileAttribute.STANDARD_DISPLAY_NAME, 
@@ -298,6 +307,9 @@ namespace Palete {
                        var ret =  new List<SourceCompletionItem>();
                        // completion rules??
                        
+                       // make sure data is loaded
+                       Gir.factory("Gtk");
+                       
                        // Roo......
                        
                        // this. (based on the node type)
@@ -314,17 +326,29 @@ namespace Palete {
                                        var ss = s.slice(1,-1);
                                        if (s[0] == '`' && GLib.Regex.match_simple("^[a-z]+$", ss) &&
                                                complete_string != ss && ss.index_of(complete_string,0) == 0 ) {
-                                               ret.append(new SourceCompletionItem (ss, ss, null, "vala : " + str));
+                                               ret.append(new SourceCompletionItem (ss, ss, null, "vala : " + ss));
+                                       }
+                               }
+                               var miter = Gir.cache.map_iterator();
+                               while (miter.next()) {
+                                       var ss = miter.get_key();
+                                       
+                                       if (complete_string != ss && ss.index_of(complete_string,0) == 0 ) {
+                                               ret.append(new SourceCompletionItem (ss, ss, null, "vala namespace : " + ss));
                                        }
                                }
+                                
                                
                                if (complete_string != "_this" && "_this".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
                                        ret.append(new SourceCompletionItem ("_this - the top level element", "_this", null, "Top level element"));
                                }
+                               // basic types..
                                
                                return ret;
                        }
-                       // got at least one ".".
+                        
+                       
+                        // got at least one ".".
                        var parts = complete_string.split(".");
                        var curtype = "";
                        var cur_instance = false;
@@ -334,8 +358,13 @@ namespace Palete {
                                        print("node is empty - no return\n");
                                        return ret; // no idea..
                                }
-                               curtype = '*' +  node.fqn();
+                               curtype = "*" +  node.fqn();
                                cur_instance = true;
+                       } else {
+                                if (Gir.cache.get(parts[0]) == null) {
+                                       return ret;
+                               }
+                               curtype = parts[0];
                        }
                        // all Gtk.... etc.. types...
                        
@@ -350,8 +379,10 @@ namespace Palete {
                                print("matching %d/%d\n", i, parts.length);
                                var is_last = i == parts.length -1;
                                
+                               
+                                
                                // look up all the properties of the type...
-                               var cls = this.getClass(curtype);
+                               var cls = Gir.factoryFqn(curtype);
                                if (cls == null && curtype[0] != '*') {
                                        print("could not get class of curtype %s\n", curtype);
                                        return ret;
@@ -359,7 +390,7 @@ namespace Palete {
 
                                if (!is_last) {
                                        
-                                       if (curtype[0] == '*' && parts[i] = "el") {
+                                       if (curtype[0] == '*' && parts[i] == "el") {
                                                curtype = curtype.substring(1);
                                                prevbits += parts[i] + ".";
                                                continue;
@@ -367,6 +398,9 @@ namespace Palete {
                                        
                                        // only exact matches from here on...
                                        if (cur_instance) {
+                                               if (cls == null) {
+                                                       return ret;
+                                               }
                                                if (cls.props.has_key(parts[i])) {
                                                        var prop = cls.props.get(parts[i]);
                                                        if (prop.type.index_of(".",0) > -1) {
@@ -377,35 +411,23 @@ namespace Palete {
                                                        }
                                                        return ret;
                                                }
-                                               
+                                                
                                                
                                                
                                                // check methods?? - we do not export that at present..
                                                return ret;      //no idea...
                                        }
-                               
-                                       // not a instance..
-                                       //look for child classes.
-                                       var citer = this.classes.map_iterator();
-                                       var foundit = false;
-                                       while (citer.next()) {
-                                               var scls = citer.get_key();
-                                               var look = prevbits + parts[i];
-                                               if (scls.index_of(look,0) != 0) {
-                                                       continue;
-                                               }
-                                               // got a starting match..
-                                               curtype = look;
-                                               cur_instance = false;
-                                               foundit =true;
-                                               break;
-                                       }
-                                       if (!foundit) {
+                                       var look = prevbits + parts[i];
+                                       var scls = Gir.factoryFqn(look);
+                                       if (scls == null) {
                                                return ret;
                                        }
+                                       curtype = look;
                                        prevbits += parts[i] + ".";
                                        continue;
+                                        
                                }
+                               
                                // got to the last element..
                                print("Got last element\n");
                                if (curtype == "") { // should not happen.. we would have returned already..
@@ -415,24 +437,59 @@ namespace Palete {
                                if (!cur_instance) {
                                        print("matching instance");
                                        // it's a static reference..
-                                       var citer = this.classes.map_iterator();
+                                       var citer = cls.classes.map_iterator();
                                        while (citer.next()) {
                                                var scls = citer.get_key();
-                                               var look = prevbits + parts[i];
-                                               if (parts[i].length > 0 && scls.index_of(look,0) != 0) {
+                                               
+                                               if (parts[i].length > 0 && scls.index_of(parts[i],0) != 0) {
                                                        continue;
                                                }
                                                // got a starting match..
                                                ret.append(new SourceCompletionItem (
-                                                       scls,
-                                                       scls, 
+                                                       prevbits + scls,
+                                                       prevbits + scls, 
                                                        null, 
                                                        scls));
                                        }
+                                       // methods.... 
+                                       citer = cls.methods.map_iterator();
+                                       while (citer.next()) {
+                                               var scls = citer.get_key();
+                                               
+                                               if (parts[i].length > 0 && scls.index_of(parts[i],0) != 0) {
+                                                       continue;
+                                               }
+                                               // got a starting match..
+                                               ret.append(new SourceCompletionItem (
+                                                       prevbits + scls  + citer.get_value().sig ,
+                                                       prevbits + scls, 
+                                                       null, 
+                                                       scls));
+                                       }
+                                       
+                                       // enums.... 
+                                       citer = cls.consts.map_iterator();
+                                       while (citer.next()) {
+                                               var scls = citer.get_key();
+                                               
+                                               if (parts[i].length > 0 && scls.index_of(parts[i],0) != 0) {
+                                                       continue;
+                                               }
+                                               // got a starting match..
+                                               ret.append(new SourceCompletionItem (
+                                                       prevbits + scls  + citer.get_value().sig ,
+                                                       prevbits + scls, 
+                                                       null, 
+                                                       scls));
+                                       }
+                                       
+                                       
                                        return ret;
                                }
                                print("matching property");
-                               
+                               if (cls == null) {
+                                       return ret;
+                               }
                                
                                
                                var citer = cls.methods.map_iterator();