Fix #8011 - add resources
[roobuilder] / src / Project / Project.vala
index d10c23a..7060c2b 100644 (file)
@@ -492,6 +492,14 @@ namespace Project {
                        }
                        GLib.debug("load is_scanned = false");
                        
+                       
+                       // used to load paths..
+                       this.sub_paths = new Gee.ArrayList<JsRender.JsRender>();
+                       this.files = new Gee.HashMap<string,JsRender.JsRender>();
+                       this.loadSubDirectories("", 0); // must happend before loadJson! (as compile groups checks if file exists.
+                        
+
+                       
                        if (FileUtils.test(this.path + "/.roobuilder.jcfg", FileTest.EXISTS)) {
                                  
                                var pa = new Json.Parser();
@@ -512,12 +520,7 @@ namespace Project {
                                 
                                this.loadJson(obj);
                        } 
-                       // used to load paths..
-                       this.sub_paths = new Gee.ArrayList<JsRender.JsRender>();
-                       this.files = new Gee.HashMap<string,JsRender.JsRender>();
-                       this.loadSubDirectories("", 0);
-                        
-                       this.initDatabase();
+                       this.initDatabase();    
                        this.is_scanned = true; // loaded.. dont need to do it again..
                         GLib.debug("load is_scanned = true");
                        
@@ -689,13 +692,15 @@ namespace Project {
                        if (subdir == "build") { // cmake!
                                return;
                        }
-                       
                        if (subdir == "autom4te.cache") { // automake?
                                return;
                        }
-                       if (subdir == "debian") { // debian!?
+                       if (subdir == "obj-x86_64-linux-gnu") { // meson?
                                return;
                        }
+                       //if (subdir == "debian") { // debian!?
+                       //      return;
+                       //}
 
                        
                        var dir = this.path + (subdir.length > 0 ? "/" : "") + subdir;
@@ -730,10 +735,15 @@ namespace Project {
                                        }
                                        
                                        if (FileUtils.test(dir  + "/" + fn, GLib.FileTest.IS_DIR)) {
+                                               if (subdir == "debian") { // dont bother with subdirs  of debian.
+                                       continue;
+                               }
+
+                                               
                                                subs.add(dir  + "/" + fn);
                                                continue;
                                        }
-                                       if (Regex.match_simple("\\.(o|cache|gif|jpg|png|gif|out|stamp|~)$", fn)) { // object..
+                                       if (Regex.match_simple("\\.(o|cache|out|stamp|~)$", fn)) { // object..
                                                continue;
                                        }
                                        if (Regex.match_simple("^(config1.builder|a.out|stamp-h1|depcomp|config.log|config.status)$", fn)) { // object..
@@ -858,6 +868,8 @@ namespace Project {
 
                        
                        file.remove();
+                       this.save();
+                       
                        // remove it from 
                        
                        
@@ -967,9 +979,6 @@ namespace Project {
                        string[] ret = {};
                         
                        foreach(var jdir in this.sub_paths) { 
-                               
-
-                               
                                if (Path.get_basename (jdir.path) == name) {
                                        GLib.debug("pathsMatching %s\n", jdir.path);
                                        ret += full_path ? jdir.path : jdir.relpath;
@@ -979,6 +988,21 @@ namespace Project {
                        return ret;
                        
                }
+               
+               public Gee.ArrayList<JsRender.Dir> pathsUnder(string name)
+               {
+                       var ret = new Gee.ArrayList<JsRender.Dir>();
+                        
+                       foreach(var jdir in this.sub_paths) { 
+                               if (jdir.relpath.has_prefix(name + "/")) {
+                                       ret.add(jdir as JsRender.Dir);
+                               }
+                               
+                       }
+                       return ret;
+                       
+               }
+               
                public Gee.ArrayList<string> readArray(Json.Array ar) 
                {
                        var ret = new Gee.ArrayList<string>();
@@ -993,35 +1017,48 @@ namespace Project {
                        return ret;
                }
                
-               public void updateErrorsforFile(JsRender.JsRender f) 
+               // called from file..
+               public void addError(JsRender.JsRender f, Lsp.Diagnostic diag)
                {
-                       var n = this.updateErrorsByType(f, "WARN");
-                       n += this.updateErrorsByType(f, "ERR");
-                       n += this.updateErrorsByType(f, "DEPR");
-                       
-                       if (n > 0) {
-                               BuilderApplication.updateCompileResults();
+                       var new_ce = new Palete.CompileError.new_from_diagnostic(f, diag);
+                       var ls = this.getErrors(new_ce.category); // will create if necessary..
+                       // find the file in the list store.
+
+                       for(var i =0; i < ls.get_n_items(); i++) {
+                               var ce = ls.get_item(i) as Palete.CompileError;
+                               if (ce.file.path == f.path) {
+                                       ce.lines.append(new_ce);
+                                       return;
+                               } 
                        }
-                       
+                       // we did not have the file..
+                       var add = new Palete.CompileError.new_from_file(f, diag.category);
+                       ls.append(add);
+                       add.lines.append(new_ce);
+                         
                }
-               public int  updateErrorsByType(JsRender.JsRender f, string n) 
+               public void removeError(JsRender.JsRender f, Lsp.Diagnostic diag)
                {
-                       var ls = this.getErrors(n);
-                       
-                       // remove thie file from the list.      
+                       var ls = this.getErrors(diag.category);
                        for(var i =0; i < ls.get_n_items(); i++) {
                                var ce = ls.get_item(i) as Palete.CompileError;
-                               if (ce.file.path == f.path) {
-                                       ls.remove(i);
-                                       break;
+                               if (ce.file.path != f.path) {
+                                       continue;
+                               }
+                               for(var j =0; j < ce.lines.get_n_items(); j++) {
+                                       var  lce = ce.lines.get_item(j) as Palete.CompileError;
+                                       
+                                       if (!diag.equals( lce.diag)) {
+                                               continue;
+                                       }
+                                       ce.lines.remove(j);
+                                       if (ce.lines.get_n_items() < 1) {
+                                               ls.remove(i);
+                                               return;
+                                       }
                                }
                        }
-                       var add = new Palete.CompileError.new_from_file(f, n);
-                       if (add.hasErrors()) {
-                               ls.append(add);
-                               return 1;
-                       }
-                       return 0;
+
                }
                public GLib.ListStore getErrors(string n)
                {