change document_save and document_change_real to async
[roobuilder] / src / Palete / LanguageClientVala.vala
index f35f74f..fe37445 100644 (file)
@@ -50,7 +50,9 @@ namespace Palete {
                                }
                                this.countdown--;
                                if (this.countdown < 0){
-                                       this.document_change_force(this.change_queue_file,  this.change_queue_file_source);
+                                       this.document_change_force.begin(this.change_queue_file,  this.change_queue_file_source, (o, res) => {
+                                               this.document_change_force.end(res);
+                                       });
                                        this.change_queue_file = null;
                                           
                                }
@@ -196,6 +198,13 @@ namespace Palete {
                        this.in_close = false;
                }
        
+               public async void restartServer()
+               {
+                       this.startServer();
+                       foreach(var f in this.open_files) {
+                               this.document_open(f);
+                       }
+               }
        
                public bool isReady()
                {
@@ -204,10 +213,11 @@ namespace Palete {
                                GLib.debug("server stopped = restarting");
                                this.initialized = false;
                                this.closed = false;
-                               this.startServer();
-                               foreach(var f in this.open_files) {
-                                       this.document_open(f);
-                               }
+                               GLib.MainLoop loop = new GLib.MainLoop ();
+                               this.restartServer.begin ((obj, async_res) => {
+                                       this.restartServer.end(async_res);
+                                       loop.quit ();
+                               });
                                return false; // can't do an operation yet?
                                 
                        }
@@ -221,7 +231,7 @@ namespace Palete {
                                return false;
                        }
                        // restart server..
-
+               
                        
                        
                        return true;
@@ -301,22 +311,33 @@ namespace Palete {
 
                }
                
-               public override  void document_save (JsRender.JsRender file)  
+               public override  async void document_save (JsRender.JsRender file)  
        {
                        if (!this.isReady()) {
                                return;
                        }
+                       // save only really flags the file on the server - to actually force a change update - we need to 
+                       // flag it as changed.
+                       yield this.document_change_force(file, file.toSource());
+                       
                        this.change_queue_file = null;
                        GLib.debug ("LS send save");
                         try {
-                                 this.jsonrpc_client.send_notification  (
-                                       "textDocument/didChange",
-                                       this.buildDict (  
-                                               textDocument : this.buildDict (    ///TextDocumentItem;
-                                                       uri: new GLib.Variant.string (file.to_url()),
-                                                       version :  new GLib.Variant.uint64 ( (uint64) file.version)
-                                               )
-                                       ),
+                        
+                               var args = this.buildDict (  
+                                       textDocument : this.buildDict (    ///TextDocumentItem;
+                                               uri: new GLib.Variant.string (file.to_url()),
+                                               version :  new GLib.Variant.uint64 ( (uint64) file.version)
+                                       )
+                               );
+                        
+                               //GLib.debug ("textDocument/save send with %s", Json.to_string (Json.gvariant_serialize (args), true));                                 
+                       
+                        
+                        
+                                 yield this.jsonrpc_client.send_notification_async  (
+                                       "textDocument/didSave",
+                                       args,
                                        null 
                                );
                                this.log(LanguageClientAction.SAVE, file.path);
@@ -364,7 +385,9 @@ namespace Palete {
                public override void document_change (JsRender.JsRender file )    
                {
                        if (this.change_queue_file != null && this.change_queue_file.path != file.path) {
-                               this.document_change_force(this.change_queue_file, this.change_queue_file_source);
+                               this.document_change_force.begin(this.change_queue_file, this.change_queue_file_source, (o, res) => {
+                                       this.document_change_force.end(res);
+                               });
                        }
                        
                        this.countdown = 3;
@@ -375,7 +398,7 @@ namespace Palete {
                }
        
 
-               public override void document_change_force (JsRender.JsRender file, string contents)  
+               public override async void document_change_force (JsRender.JsRender file, string contents)  
        {
                        if (!this.isReady()) {
                                return;
@@ -391,7 +414,7 @@ namespace Palete {
                        node.set_array(ar);
                        this.log(LanguageClientAction.CHANGE, file.path);
                         try {
-                               this.jsonrpc_client.send_notification (
+                               yield this.jsonrpc_client.send_notification_async (
                                        "textDocument/didChange",
                                        this.buildDict (  
                                                textDocument : this.buildDict (    ///TextDocumentItem;