Fix #8005 - vala lang server path fix and crash on "..." in autocomplete signature
[roobuilder] / src / Palete / LanguageClientVala.vala
index a7b9146..ebe35e1 100644 (file)
@@ -35,7 +35,13 @@ namespace Palete {
                }
                void startServer()
                {
-                       this.initProcess("/usr/bin/vala-language-server");
+                       var exe = GLib.Environment.find_program_in_path( "vala-language-server");
+                       if (exe == null) {
+                               GLib.warning("could not find vala-language-server");
+                                
+                               return;
+                       }
+                       this.initProcess(exe);
                }
                
                
@@ -43,7 +49,7 @@ namespace Palete {
                {
                        // extend versions will proably call initialize to start and connect to server.
                        base(project);
-                       this.open_files = new   Gee.ArrayList<JsRender.JsRender>();
+
                        this.change_queue_id = GLib.Timeout.add_seconds(1, () => {
                                if (this.change_queue_file == null) {
                                        return true;
@@ -151,6 +157,9 @@ namespace Palete {
                                    out return_value
                                );
                                GLib.debug ("LS replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));
+                               this.open_files = new Gee.ArrayList<JsRender.JsRender>((a,b) => {
+                                       return a.path == b.path;
+                               });
                                this.initialized = true;
                                return;
                        } catch (GLib.Error e) {
@@ -201,9 +210,7 @@ namespace Palete {
                public async void restartServer()
                {
                        this.startServer();
-                       foreach(var f in this.open_files) {
-                               this.document_open(f);
-                       }
+                        
                }
        
                public bool isReady()
@@ -241,6 +248,7 @@ namespace Palete {
                {
                        switch (method) {
                                case "textDocument/publishDiagnostics":
+                                       //GLib.debug("got notification %s : %s",  method , Json.to_string (Json.gvariant_serialize (return_value), true));
                                        this.onDiagnostic(return_value);
                                        return;
                                default: 
@@ -256,26 +264,18 @@ namespace Palete {
                */
                public void onDiagnostic(Variant? return_value) 
                {
-
+                       //GLib.debug ("LS replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));                                     
                        var dg = Json.gobject_deserialize (typeof (Lsp.Diagnostics), Json.gvariant_serialize (return_value)) as Lsp.Diagnostics; 
                        this.log(LanguageClientAction.DIAG, dg.filename);
                        var f = this.project.getByPath(dg.filename);
                        if (f == null) {
                                //GLib.debug("no file %s", dg.uri);
-                               this.project.updateErrorsforFile(null);
+                               //this.project.updateErrorsforFile(null);
                                return;
                        }
-                       foreach(var v in f.errorsByType.values) {
-                               v.remove_all();
-                       }
-                       foreach(var diag in dg.diagnostics) {
-                               var ce = new CompileError.new_from_diagnostic(f, diag);
-                               if (!f.errorsByType.has_key(ce.category)) {
-                                       f.errorsByType.set(ce.category, new  GLib.ListStore(typeof(CompileError)));
-                               }
-                               f.errorsByType.get(ce.category).append(ce);
-                       }
-                       f.project.updateErrorsforFile(f);
+                       //GLib.debug("got Diagnostics for %s", f.path);
+                       f.updateErrors( dg.diagnostics );
+                        
                        
                }
                
@@ -284,9 +284,11 @@ namespace Palete {
                        if (!this.isReady()) {
                                return;
                        }
-                       if (!this.open_files.contains(file)) {
-                               this.open_files.add(file);
+                       if (this.open_files.contains(file)) {
+                               return;
                        }
+                       this.open_files.add(file);
+                       
                        
                        GLib.debug ("LS sent open");                     
                        try {
@@ -335,7 +337,7 @@ namespace Palete {
                        
                         
                         
-                                 this.jsonrpc_client.send_notification  (
+                                 yield this.jsonrpc_client.send_notification_async  (
                                        "textDocument/didSave",
                                        args,
                                        null 
@@ -403,9 +405,11 @@ namespace Palete {
                        if (!this.isReady()) {
                                return;
                        }
-                            
+                  if (!this.open_files.contains(file)) {
+                                this.document_open(file);
+                       }  
                        
-                       GLib.debug ("LS send change");
+                       GLib.debug ("LS send change %s rev %d", file.path, file.version);
                        var ar = new Json.Array();
                        var obj = new Json.Object();
                        obj.set_string_member("text", contents);