src/Palete/Palete.vala
[app.Builder.js] / src / Palete / Palete.vala
index 19c045c..88003c1 100644 (file)
@@ -360,23 +360,25 @@ namespace Palete
        
        
        
-               public   Gee.HashMap<int,string>  validateJavascript(
+               public   bool  javascriptHasErrors(
+                                       WindowState state,
                                        string code, 
                                        string property, 
                                        string ptype,
                                        JsRender.JsRender file,
-                                       JsRender.Node? node
+                                       JsRender.Node? node, 
+                                       out Gee.HashMap<int,string> errors
                                 ) 
                {   
 
                         print("validate code (%s) ptype=%s property=%s\n", file.language, ptype, property);
-                        var ret = new Gee.HashMap<int,string>();
+                          errors = new Gee.HashMap<int,string>();
                
                        if (file.language != "js") {
-                               return ret;
+                               return false;
                         }
                         if (ptype != "listener" && property.length > 0 && property[0] == '|') {
-                               return ret;
+                               return false;
                         }
                        
                        //var cd = new JSCore.ClassDefinitionEmpty();
@@ -386,32 +388,62 @@ namespace Palete
                        var line = Javascript.singleton().validate(
                                                                  testcode, out errmsg);
 
-                       if (line < 0) {
+                       if (line > -1) {
                                if (ptype == "file") {
-                                       return this.validateJavascriptCompression(code);
+                                       var err = new Json.Object();
+                                       err.set_int_member("ERR-TOTAL", 1);
+                                       var files_obj = new Json.Object();
+                                       var lines_obj = new Json.Object();
+                                       var lines_ar = new Json.Array();
+                                       lines_ar.add_string_element(errmsg);
+                                       lines_obj.set_array_member(line.to_string(), lines_ar);
+                                       files_obj.set_object_member(file.path, lines_obj);
+                                        
+                                       err.set_object_member("ERR", files_obj);
+                                       state.showCompileResult(err);
+                                       // do not set errors.. that's not done here..
+                                       return true;
                                }
-                               print("no errors\n");
-                               return ret;
+                               errors.set(line, errmsg); // depricated - this is used by the editor currently -- but we are planning to switch from that..
+                               print("got  errors\n");
+                               return true;
+
                        }
-                       ret.set(line, errmsg);
-                       print("got  errors\n");
-                       return ret;
+                       // now syntax is OK.. try the 
+                       
+                       
+                       
+                       if (ptype == "file") {
+                                return this.javascriptHasCompressionErrors(file, state, code);
+                       }
+                       print("no errors\n");
+                       return false;
                          
                } 
                
-               public Gee.HashMap<int,string>  validateJavascriptCompression(string code)
+               public bool  javascriptHasCompressionErrors(JsRender.JsRender file, WindowState state, string code)
                {
                        // this uses the roojspacker code to try and compress the code.
                        // it should highlight errors before we actually push live the code.
                        
+                       // standard error format:  file %s, line %s, Error 
+
                        var p = new JSDOC.Packer();
                        p.keepWhite = false;
                        p.skipScope = false;
                        p.dumpTokens = false;
-                       p.cleanup = false;
+                       p.cleanup = false; 
+                
                         
-                       var ret = new Gee.HashMap<int,string>();
-                       return ret;
+                       p.packFile(code, file.path,"");
+                       state.showCompileResult(p.result);
+                       if (p.hasErrors()) {
+                               return true;
+                       }
+                       return false;
+                       
+
                
                }