Fix #8028 - language server performance, fix warnings and critical errors
[roobuilder] / src / Palete / Gir.vala
index f9906b0..648f1c5 100644 (file)
@@ -58,7 +58,7 @@ namespace Palete {
                public static void checkParamOverride(GirObject c)
                {
                        
-                       print("checkParamOverride :check %s\n", c.name);
+                       //GLib.debug("checkParamOverride :check %s", c.name);
                        var parset = c.gparent;
                        if (parset == null || parset.nodetype != "Paramset") {
                                print("skip parent not Paramset\n");
@@ -87,6 +87,7 @@ namespace Palete {
                {
                        // overrides should be in a file Gir.overides
                        // in that "Gtk.Label.new.str" : "label"
+                       
                        loadOverrides();
                        var key = "%s.%s.%s".printf(cls,method,param);
                         //print("Chekcing for key %s\n", key);
@@ -98,19 +99,26 @@ namespace Palete {
 
                }
                 
-               public static void loadOverrides(bool force = false)
+               public static void loadOverrides(bool force = false) 
                {
                        if (overrides_loaded && ! force) {
                                return;
                        }
-               
+                       Json.Node node = null;
                        var pa = new Json.Parser();
-                       pa.load_from_file(BuilderApplication.configDirectory() + "/resources/Gir.overides");
-                       var node = pa.get_root();
-                   
-                       if (node.get_node_type () != Json.NodeType.OBJECT) {
-                               throw new GirError.INVALID_FORMAT ("Error loading gir.overides : Unexpected element type %s", node.type_name ());
+                       try {
+                               pa.load_from_file(BuilderApplication.configDirectory() + "/resources/Gir.overides");
+                               node = pa.get_root();
+                               if (node.get_node_type () != Json.NodeType.OBJECT) {
+                                       GLib.debug("Error loading gir.overides : Unexpected element type %s", node.type_name ());
+                                       
+                                       return;
+                                       //throw new GirError.INVALID_FORMAT ("Error loading gir.overides : Unexpected element type %s", node.type_name ());
+                               }
+                       } catch (GLib.Error e) {
+                               return;
                        }
+                       
                        overrides = new Gee.HashMap<string,string>();
                
                
@@ -133,32 +141,40 @@ namespace Palete {
                 * 
                 */
 
-               public static  Gee.HashMap<string,Gir> global_cache = null;
+       //      public static  Gee.HashMap<string,Gir> global_cache = null;
                
-               public static Gir?  factory(Project.Gtk? project, string ns) 
+               public static GirObject?  factory(Project.Project?  project, string ns) 
                {
-                       if (cache == null) {
-                               cache = new Gee.HashMap<string,Gir>();
-                               // this assumes we try and generate the tree once ...
-                               // but if we 'add' more vapi's it will not adjust...
-
-                                 
+                       
+                       if (project == null) {
+                               return null;
+                       }
+                       if (project.gir_cache == null) {
+                               project.gir_cache = new Gee.HashMap<string,GirObject>();
+                                
+                       }
+                       var cache = project.gir_cache;
+                       if (project != null && project is Project.Gtk) {
+                               var gproj = ((Project.Gtk)project);
+                               if (!gproj.gir_cache_loaded) {
+                                       var a = new VapiParser( (Project.Gtk)project );
+                                       a.create_valac_tree();
+                                       gproj.gir_cache_loaded = true;
+                               }
+                               cache = gproj.gir_cache;
+                               
+                               
                        }
-                       var ret = cache.get(ns);
                        
+                       var ret = cache.get(ns);
                        
-                       if (ret == null && project != null) {
-
-                               var a = new VapiParser(project );
-                               a.create_valac_tree();
-                               ret = cache.get(ns);
-                       }
+                        
                        
                        if (ret != null && !ret.is_overlaid) {
                                ret.is_overlaid = true;
                                var iter = ret.classes.map_iterator();
                                while(iter.next()) {
-                                       iter.get_value().overlayParent();
+                                       iter.get_value().overlayParent(project);
                                }
                                // loop again and add the ctor properties.
                                iter = ret.classes.map_iterator();
@@ -176,28 +192,35 @@ namespace Palete {
                
                
                
-               public static GirObject?  factoryFqn(Project.Gtk project, string fqn)  
+               public static GirObject?  factoryFqn(Project.Project project, string in_fqn)  
                {       
+                       var fqn = in_fqn;
+                       // swap Gtk.Source* to GtkSource.
+                       
+                       //GLib.debug("Gir.factoryFqn  search %s", fqn);
                        var bits = fqn.split(".");
                        if (bits.length < 1) {
+                               //GLib.debug("Gir.factoryFqn  fail - missing '.'");
                                return null;
                        }
                        
                        var f = (GirObject)factory(project , bits[0]);
 
                        if (bits.length == 1 || f ==null) {
+                               //GLib.debug("Gir.factoryFqn  fail - factory failed to load NS");
                                return f;
                        }
+                       //GLib.debug("Gir.factoryFqn  fetching child %s", fqn.substring(bits[0].length+1));
                        return f.fetchByFqn(fqn.substring(bits[0].length+1)); // since classes are stored in fqn format...?
                                            
                        
                }
-
+                
                        
                /**
                 * guess the fqn of a type == eg. gboolean or Widget etc...
                 */
-               public static string fqtypeLookup(Project.Gtk project, string type, string ns) {
+               public static string fqtypeLookup(Project.Project project, string type, string ns) {
                        var g = factory(project, ns);
                        if (g.classes.has_key(type)) {
                                return ns + "." + type;
@@ -232,12 +255,18 @@ namespace Palete {
                        if (type.length < 1 || type.contains(".")) {
                                return "null";
                        }
-                       switch(type) {
+                       switch(type.down()) {
+                               case "boolean":
+                               case "bool":
                                case "gboolean":
                                        return "true";
+                               case "int":                                     
                                case "guint":
                                        return "0";
+                               case "gdouble":
+                                       return "0f";
                                case "utf8":
+                               case "string":
                                        return "\"\"";
                                default:
                                        return "?"+  type + "?";