Fix #8103 - updating of tree
authorAlan Knowles <alan@roojs.com>
Wed, 20 Mar 2024 15:51:21 +0000 (23:51 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 20 Mar 2024 15:51:21 +0000 (23:51 +0800)
src/Builder4/Editor.bjs
src/Builder4/Editor.vala
src/JsRender/JsRender.vala
src/Palete/LanguageClient.vala
src/Palete/LanguageClientDummy.vala
src/Palete/LanguageClientJavascript.vala
src/Palete/LanguageClientVala.vala

index 365c280..890179b 100644 (file)
               "        _this.file.setSource(str);",
               "\t    BuilderApplication.showSpinner(\"appointment soon\",\"document change pending\");",
               "    \t_this.file.getLanguageServer().document_change(_this.file);",
-              "",
+              "\t\t_this.file.getLanguageServer().queueDocumentSymbols(_this.file);",
               "        _this.file.setSource(oldcode);",
               "        ",
               "\t\t ",
           "\tforeach(var sym in syms) {",
           "\t\t_this.navliststore.el.append(sym);",
           "\t}",
-          "\t",
+          "\tthis.last_selected_line = -1;",
+          "\tGLib.Idle.add(() => {",
+          "",
+          "\t\tGtk.TextIter iter;",
+          "\t\t_this.buffer.el.get_iter_at_offset (",
+          "\t\t\t\tout iter, _this.buffer.el.cursor_position);",
+          "\t\t",
+          "\t\tGLib.debug(\"idle update scroll %d, %d\", iter.get_line(),",
+          "\t\t\t\titer.get_line_offset());",
+          "\t\tthis.updateSelectedLine(",
+          "\t\t\t\t(uint)iter.get_line(),",
+          "\t\t\t\t(uint)iter.get_line_offset()",
+          "\t\t);",
+          "\t\treturn false;",
+          "\t});",
           "",
           "}"
          ],
     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
     "{",
     "    this.reset();",
+    "    if (this.file != null) {",
+    "    \tthis.file.navigation_tree_updated.disconnect(",
+    "    \t\t_this.navigation.show",
+    "    \t);",
+    "    }",
     "    this.file = file;    ",
-    "    ",
+    "    this.file.navigation_tree_updated.connect(",
+    "\t\t_this.navigation.show",
+    "\t);",
     "    if (file.xtype != \"PlainFile\") {",
     "    \tthis.prop = prop;",
     "        this.node = node;",
     "    ",
     "    } else {",
     "        this.view.load(        file.toSource() );",
-    "         this.updateErrorMarks();",
+    "        this.updateErrorMarks();",
     "        this.close_btn.el.hide();",
     "        var ls = file.getLanguageServer();",
-    "        ls.documentSymbols.begin(file, (a,o) => {",
-    "        \t_this.navigation.show(ls.documentSymbols.end(o)); ",
-    "        });",
+    "        ls.queueDocumentSymbols(file);",
+    "        ////ls.documentSymbols.begin(file, (a,o) => {",
+    "        //\t_this.navigation.show(ls.documentSymbols.end(o)); ",
+    "       //});",
     "        //documentSymbols",
     "        ",
     "    }",
index b8975b0..1231711 100644 (file)
@@ -138,8 +138,15 @@ public class Editor : Object
        public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
        {
            this.reset();
+           if (this.file != null) {
+               this.file.navigation_tree_updated.disconnect(
+                       _this.navigation.show
+               );
+           }
            this.file = file;    
-           
+           this.file.navigation_tree_updated.connect(
+                       _this.navigation.show
+               );
            if (file.xtype != "PlainFile") {
                this.prop = prop;
                this.node = node;
@@ -154,12 +161,13 @@ public class Editor : Object
            
            } else {
                this.view.load(        file.toSource() );
-                this.updateErrorMarks();
+               this.updateErrorMarks();
                this.close_btn.el.hide();
                var ls = file.getLanguageServer();
-               ls.documentSymbols.begin(file, (a,o) => {
-                       _this.navigation.show(ls.documentSymbols.end(o)); 
-               });
+               ls.queueDocumentSymbols(file);
+               ////ls.documentSymbols.begin(file, (a,o) => {
+               //      _this.navigation.show(ls.documentSymbols.end(o)); 
+              //});
                //documentSymbols
                
            }
@@ -1092,7 +1100,7 @@ public class Editor : Object
                        _this.file.setSource(str);
                            BuilderApplication.showSpinner("appointment soon","document change pending");
                        _this.file.getLanguageServer().document_change(_this.file);
-               
+                               _this.file.getLanguageServer().queueDocumentSymbols(_this.file);
                        _this.file.setSource(oldcode);
                        
                                 
@@ -1844,7 +1852,21 @@ public class Editor : Object
                        foreach(var sym in syms) {
                                _this.navliststore.el.append(sym);
                        }
-                       
+                       this.last_selected_line = -1;
+                       GLib.Idle.add(() => {
+               
+                               Gtk.TextIter iter;
+                               _this.buffer.el.get_iter_at_offset (
+                                               out iter, _this.buffer.el.cursor_position);
+                               
+                               GLib.debug("idle update scroll %d, %d", iter.get_line(),
+                                               iter.get_line_offset());
+                               this.updateSelectedLine(
+                                               (uint)iter.get_line(),
+                                               (uint)iter.get_line_offset()
+                               );
+                               return false;
+                       });
                
                }
                public int getRowAt (double x,  double  y, out string pos) {
index cc8060b..5f37888 100644 (file)
@@ -129,7 +129,7 @@ namespace JsRender {
                }
 
                //public signal void changed (Node? node, string source);  (not used?)
-               
+               public signal void navigation_tree_updated( Gee.ArrayList<Lsp.DocumentSymbol> syms);
                 
                public signal void compile_notice(string type, string file, int line, string message);
                
index 6d4cfce..8b97ca0 100644 (file)
@@ -89,6 +89,7 @@ namespace Palete {
                public abstract async void shutdown () throws GLib.Error;
                public abstract async Lsp.CompletionList?  completion(JsRender.JsRender file, int line, int offset , int triggerType = 1) throws GLib.Error;
                public abstract async Lsp.Hover hover (JsRender.JsRender file, int line, int offset) throws GLib.Error;
+               public abstract void queueDocumentSymbols (JsRender.JsRender file); 
                public abstract async Gee.ArrayList<Lsp.DocumentSymbol> documentSymbols (JsRender.JsRender file) throws GLib.Error;     
        }
        
index 533458d..8c1911a 100644 (file)
@@ -29,6 +29,7 @@ namespace Palete {
                public override async  Lsp.Hover hover (JsRender.JsRender file, int line, int offset) throws GLib.Error {
                        return new Lsp.Hover();
                }
+               public override void queueDocumentSymbols (JsRender.JsRender file) { }
                public override async Gee.ArrayList<Lsp.DocumentSymbol> documentSymbols (JsRender.JsRender file) throws GLib.Error {
                        var ret = new Gee.ArrayList<Lsp.DocumentSymbol>();      
                        return ret;
index b5bec50..876a49c 100644 (file)
@@ -288,6 +288,7 @@ namespace Palete {
                public override async  Lsp.Hover hover (JsRender.JsRender file, int line, int offset) throws GLib.Error {
                        return new Lsp.Hover();
                }
+               public override void queueDocumentSymbols (JsRender.JsRender file) { }
                public override async Gee.ArrayList<Lsp.DocumentSymbol> documentSymbols (JsRender.JsRender file) throws GLib.Error {
                        var ret = new Gee.ArrayList<Lsp.DocumentSymbol>();      
                        return ret;
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 {