Fix #8103 - updating of tree
[roobuilder] / src / Palete / LanguageClientVala.vala
index 57a082b..1be2b05 100644 (file)
@@ -1,7 +1,6 @@
 
 namespace Palete {
        public class LanguageClientVala : LanguageClient {
-               int countdown = 0;
                protected bool initialized = false;
                bool sent_shutdown = false;
                uint change_queue_id = 0;
@@ -20,9 +19,13 @@ namespace Palete {
                private IOStream? subprocess_stream = null;
            public Jsonrpc.Client? jsonrpc_client = null;
                
+               int countdown = 0;
                Gee.ArrayList<JsRender.JsRender> open_files;
                private JsRender.JsRender? _change_queue_file = null;
+               int doc_countdown = 0;
                private string change_queue_file_source = "";
+               private JsRender.JsRender? doc_queue_file = null;
+
                
                JsRender.JsRender? change_queue_file {
                        set {
@@ -33,6 +36,9 @@ namespace Palete {
                                return this._change_queue_file;
                        } 
                }
+               
+
+               
                void startServer()
                {
                        var exe = GLib.Environment.find_program_in_path( "vala-language-server");
@@ -50,30 +56,66 @@ namespace Palete {
                        // extend versions will proably call initialize to start and connect to server.
                        base(project);
 
-                       this.change_queue_id = GLib.Timeout.add_seconds(1, () => {
-                               if (this.change_queue_file == null) {
-                                       return true;
-                               }
-                               if (this.getting_diagnostics) {
-                                       return true;
-                               }
-                               this.countdown--;
-
+                       if (this.change_queue_id == 0 ) {
+                               this.change_queue_id = GLib.Timeout.add_seconds(1, () => {
+                                       this.run_change_queue();
+                                       this.run_doc_queue();
+                                       return true;
+                               });
+                       }
                        
-                               if (this.countdown < 0){
-                                       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;
-                                          
-                               }
-                               return true;
-                       });
                        this.startServer();
 
                }
                
+               void run_change_queue()
+               {
+               
+                       if (this.change_queue_file == null) {
+                               return ;
+                       }
+                       if (this.countdown < -1) {
+                               return;
+                       }
+                       if (this.getting_diagnostics) {
+                               return;
+                       }
+                       this.countdown--;
+
+               
+                       if (this.countdown < 0){
+                               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;
+                                  
+                       }
+                       return ;
+               }
                 
+                
+               void run_doc_queue()
+               {
+               
+                       if (this.doc_queue_file == null) {
+                               return ;
+                       }
+                       if (this.doc_countdown < -1) {
+                               return;
+                       }
+                       this.doc_countdown--;
+
+                       if (this.doc_countdown < 0){
+                               var sendfile = this.doc_queue_file;
+                               this.documentSymbols.begin(this.doc_queue_file, (o, res) => {
+                                       var ret = this.documentSymbols.end(res);
+                                       sendfile.navigation_tree_updated(ret);
+                               });
+                               this.doc_queue_file = null;
+                                  
+                       }
+                       return ;
+               }
                public bool initProcess(string process_path)
                {
                        this.onClose();
@@ -646,7 +688,19 @@ namespace Palete {
 
                }
                
-               
+               public override void queueDocumentSymbols (JsRender.JsRender file) 
+               {
+                       if (this.doc_queue_file != null && this.doc_queue_file.path != file.path) {
+                               var sendfile = this.doc_queue_file;
+                               this.documentSymbols.begin(this.doc_queue_file, (o, res) => {
+                                       var ret = documentSymbols.end(res);
+                                       sendfile.navigation_tree_updated(ret);
+                               });
+                       }
+                       
+                       this.doc_countdown = 3;
+                       this.doc_queue_file = file;
+               }
                
         
                public override async Gee.ArrayList<Lsp.DocumentSymbol> documentSymbols (JsRender.JsRender file) throws GLib.Error {