Javascript instance = null;
public class Javascript {
-
-/*
- public static JSCore.Object class_constructor(
- JSCore.Context ctx,
- JSCore.Object constructor,
- JSCore.Value[] arguments,
- out JSCore.Value exception)
- {
- var c = new JSCore.Class (class_definition);
- var o = new JSCore.Object (ctx, c, null);
- exception = null;
- return o;
- }
- const JSCore.StaticFunction[] class_functions = {
- { null, null, 0 }
- };
- const JSCore.ClassDefinition class_definition = {
- 0,
- JSCore.ClassAttribute.None,
- "App",
- null,
-
- null,
- class_functions,
-
- null,
- null,
-
- null,
- null,
- null,
- null,
-
- null,
- null,
- class_constructor,
- null,
- null
- };
-
-
- public JSCore.GlobalContext js_global_context = null;
-*/
+
public static Javascript singleton()
{
if (instance == null) {
}
+
+
+
public void validate(string code, JsRender.JsRender file)
{
//GLib.debug("Check syntax %s", code);
ctx.check_syntax(code, code.length, JSC.CheckSyntaxMode.SCRIPT, "", 1 ,out ex);
- var ar = file.getErrors("ERR");
- ar.remove_all();
+ var ar = new Gee.ArrayList<Lsp.Diagnostic>((a,b) => { return a.equals(b); });
+
if (ex == null) {
- return ; // this.compressionErrors(code, fn); << to slow on large files?
+// file.updateErrors( ar ); // clear old errors ??
+ this.compressionErrors.begin(code, file.path, (obj, res) => {
+ ar = this.compressionErrors.end(res);
+ file.updateErrors( ar );
+ });
+
+ return ;
}
-
+
//GLib.debug("go t error %d %s", (int)ex.get_line_number() , ex.get_message() );
-
+ var diag = new Lsp.Diagnostic.simple((int) ex.get_line_number() -1 , 1, ex.get_message());
- var ret = new CompileError.new_jserror(file, "ERR", (int) ex.get_line_number(), ex.get_message());
-
- ar.append(ret);
-
+ ar.add(diag);
+ file.updateErrors( ar );
}
-
-
- public Json.Object compressionErrors(string code , string fn)
+
+ bool packer_running = false;
+ public async new Gee.ArrayList<Lsp.Diagnostic> compressionErrors(string code , string fn) throws ThreadError
{
// this uses the roojspacker code to try and compress the code.
// it should highlight errors before we actually push live the code.
+ SourceFunc callback = compressionErrors.callback;
+ Json.Object ret = new Json.Object();
+ var ar = new Gee.ArrayList<Lsp.Diagnostic>((a,b) => { return a.equals(b); });
+ if (this.packer_running) {
+ return ar;
+ }
+ this.packer_running = true;
+
+ ThreadFunc<bool> run = () => {
+
// standard error format: file %s, line %s, Error
-
-
- var cfg = new JSDOC.PackerRun();
- cfg.opt_keep_whitespace = false;
- cfg.opt_skip_scope = false;
- cfg.opt_dump_tokens = false;
- cfg.opt_clean_cache = false;
+
+ var cfg = new JSDOC.PackerRun();
+ cfg.opt_keep_whitespace = false;
+ cfg.opt_skip_scope = false;
+ cfg.opt_dump_tokens = false;
+ cfg.opt_clean_cache = false;
+
+
+ var p = new JSDOC.Packer(cfg);
+
+
+ p.packFile(code, fn,"");
+
+ ret = p.result;
+ Idle.add((owned) callback);
+ return true;
+ };
+ new Thread<bool>("roopacker", run);
+ yield;
+ this.packer_running = false;
+ if (!ret.has_member(fn)) {
+ return ar;
+ }
+ var jar = ret.get_array_member(fn);
+ for(var i = 0; i < jar.get_length(); i++ ){
+ var d = jar.get_object_element(i);
+
+ ar.add(
+ new Lsp.Diagnostic.simple((int) d.get_int_member("line") , 1, d.get_string_member("message"))
+ );
+ }
-
- var p = new JSDOC.Packer(cfg);
-
-
- p.packFile(code, fn,"");
- //state.showCompileResult(p.result);
- /*
- var g = new Json.Generator ();
-
- g.pretty = true;
- g.indent = 2;
- var n = new Json.Node(Json.NodeType.OBJECT);
- n.set_object(p.result);
- g.set_root (n);
-
- GLib.debug("got %s", g.to_data (null));
- */
- return p.result;
-
+ return ar;
+
+
}
+
+
/**
* extension API concept..