more hidden files for flatpack
[roobuilder] / src / Project / Project.vala
index 7213b22..0d9a8ad 100644 (file)
@@ -83,7 +83,12 @@ namespace Project {
                 
                private bool is_scanned = false; 
                public  Gee.HashMap<string,Palete.GirObject> gir_cache = null; // used by Gir ??? is this used by Roo?
-                public Palete.ValaCompileRequest last_request = null;
+               //public Palete.ValaCompileRequest last_request = null; // depricated?
+               public Gee.HashMap<string,GLib.ListStore>? errorsByType = null;
+               
+               
+               protected Gee.HashMap<string,Palete.LanguageClient> language_servers;
                
                protected Project (string path) {
                        
@@ -96,8 +101,9 @@ namespace Project {
                        //XObject.extend(this, cfg);
                        //this.files = { }; 
                        this.path = path;
-                        
-                       
+                       this.language_servers = new Gee.HashMap<string,Palete.LanguageClient>();
+                       this.language_servers.set("dummy", new Palete.LanguageClientDummy(this));
+                       this.errorsByType = new  Gee.HashMap<string,GLib.ListStore>();
                        
                }
                 
@@ -116,7 +122,7 @@ namespace Project {
                                try {
                                        dir.make_directory();
                                } catch(GLib.Error e) {
-                                       GLib.error("could not make builder directory");
+                                       GLib.error("could not make builder directory %s", e.message);
                                }
                                return;
                        }
@@ -410,14 +416,7 @@ namespace Project {
 
                public void save()
                {
-                               // fixme..
-                       
-                
-
-                       
-
-                       //var dirname = GLib.Environment.get_home_dir() + "/.Builder";
-                       
+                         
                        var  s =  this.toJSON();
                        GLib.debug("Save Project %s\n%s", this.name, s);
                        try {
@@ -426,6 +425,7 @@ namespace Project {
                        } catch (GLib.Error e) {
                                GLib.error("failed  to save file %s", e.message);
                        }
+                       this.onSave();
                        
                }
 
@@ -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,19 +520,12 @@ 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");
                        
                }
                
-               public abstract void loadJson(Json.Object obj); 
-               public abstract void saveJson(Json.Object obj);
                
                /*
                
@@ -603,10 +604,10 @@ namespace Project {
         
         
         
-               public JsRender.JsRender? getByName(string name)
+               public JsRender.JsRender? getByRelPath(string relpath)
                {
                        foreach(var f in this.files.values) {
-                               if (f.name == name) {
+                               if (f.relpath == relpath || f.relTargetName() == relpath) {
                                        return f;
                                }
                        };
@@ -619,7 +620,7 @@ namespace Project {
                 
                        // keys are not paths...
                        foreach(var f in this.files.values) {
-                               GLib.debug("check %s = %s ? %s", path, f.path, f.targetName());
+                               //GLib.debug("check %s = %s ? %s", path, f.path, f.targetName());
                                if (f.path == path || f.targetName() == path) {
                                        return f;
                                }
@@ -691,13 +692,21 @@ namespace Project {
                        if (subdir == "build") { // cmake!
                                return;
                        }
-                       
+                       if (subdir == "build-dir") { // flatpack
+                               return;
+                       }
+                       if (subdir == "repo") { // flatpack ?? wrong command?
+                               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;
@@ -732,10 +741,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..
@@ -815,7 +829,7 @@ namespace Project {
                }
                
                // calle dfrom new file dialog
-               // add files to dires 
+               // add files to dires (and main file list)
                // update 
                        
                 
@@ -860,6 +874,8 @@ namespace Project {
 
                        
                        file.remove();
+                       this.save();
+                       
                        // remove it from 
                        
                        
@@ -969,9 +985,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;
@@ -981,6 +994,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>();
@@ -995,9 +1023,68 @@ namespace Project {
                        return ret;
                }
                
-                
-                public abstract void initDatabase();
-                public abstract void initialize(); // for new projects (make dirs?);
+               // called from file..
+               public void addError(JsRender.JsRender f, Lsp.Diagnostic diag)
+               {
+                       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 void removeError(JsRender.JsRender f, Lsp.Diagnostic diag)
+               {
+                       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) {
+                                       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;
+                                       }
+                               }
+                       }
+
+               }
+               public GLib.ListStore getErrors(string n)
+               {
+                       var ls = this.errorsByType.get(n);
+                       if (ls == null) {
+                               ls = new GLib.ListStore(typeof(Palete.CompileError));
+                               this.errorsByType.set(n, ls );
+                       }
+                       return ls;
+               }
+               
+               
+               public abstract Palete.LanguageClient  getLanguageServer(string lang);
+               
+               
+               public abstract void onSave(); // write meson?
+               public abstract void initDatabase();
+               public abstract void initialize(); // for new projects (make dirs?);
+               public abstract void loadJson(Json.Object obj); 
+               public abstract void saveJson(Json.Object obj);
                  
        }
 }