src/Palete/Palete.vala
[app.Builder.js] / src / Palete / Palete.vala
index d9db977..44ed2e3 100644 (file)
@@ -361,6 +361,7 @@ namespace Palete
        
        
                public   Gee.HashMap<int,string>  validateJavascript(
+                                       WindowState state,
                                        string code, 
                                        string property, 
                                        string ptype,
@@ -386,20 +387,40 @@ 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.filename, lines_obj);
+                                        
+                                       err.set_object_member("ERR", files_obj);
+                                       state.showCompileResult(err);
+                                       return ret;
                                }
-                               print("no errors\n");
+                               ret.set(line, errmsg); // depricated - this is used by the editor currently -- but we are planning to switch from that..
+                               print("got  errors\n");
                                return ret;
+
+                       }
+                       // now syntax is OK.. try the 
+                       
+                       
+                       
+                       if (ptype == "file") {
+                                this.validateJavascriptCompression(file, state, code);
                        }
-                       ret.set(line, errmsg);
-                       print("got  errors\n");
+                       print("no errors\n");
                        return ret;
                          
                } 
                
-               public Gee.HashMap<int,string>  validateJavascriptCompression(string code)
+               public void  validateJavascriptCompression(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.
@@ -413,13 +434,12 @@ namespace Palete
                        p.cleanup = false; 
                        var estr = "";
                        var ret = new Gee.HashMap<int,string>();
-                       try { 
-                               p.packFile(code, "ANONFILE","");
-                       } catch (JSDOC.TokenReaderError e) {
-                               estr = e.message;
-                       } catch (JSDOC.ScopeParserError e) {
-                               estr = e.message;
+                        
+                       p.packFile(code, file.filename,"");
+                       if (!p.hasErrors("")) {
+                               state.showCompileResult(err);
                        }
+                         
                        if (estr.length > 0 ) {
 
                                var bits = estr.split(",");
@@ -427,7 +447,8 @@ namespace Palete
                                        var linebits = bits[1].strip().split(" ");
                                        if (linebits.length > 1) {
                                                var line = int.parse(linebits[1]);
-                                               ret.set(line, bits[2]);
+                                               // line is correct - but our standard for error messages is to do it start at '0'
+                                               ret.set(line -1 , bits[2]);
                                        }
                                        
                                }