Fix #8120 - more experiments with hover
authorAlan <alan@roojs.com>
Wed, 27 Mar 2024 10:06:37 +0000 (18:06 +0800)
committerAlan <alan@roojs.com>
Wed, 27 Mar 2024 10:06:37 +0000 (18:06 +0800)
src/Builder4/Editor.bjs
src/Builder4/Editor.vala
src/Palete/LanguageClient.vala
src/Palete/LanguageClientDummy.vala
src/Palete/LanguageClientJavascript.vala
src/Palete/LanguageClientVala.vala

index 8bb5e40..1c1a75b 100644 (file)
            "int margin_end" : 4,
            "int margin_start" : 4,
            "listeners" : {
+            "activate_link" : [
+             "(uri) => {",
+             "\tGLib.debug(\"got uri %s\", uri);",
+             "\tvar ls = _this.file.getLanguageServer();",
+             "\tls.symbol.begin(uri, (a,b) => {",
+             "\t\tls.symbol.end(b);",
+             "\t});",
+             "\t",
+             "\treturn true;",
+             "}",
+             ""
+            ],
             "query_tooltip" : [
              "(x, y, keyboard_tooltip, tooltip) => {",
              "\tGLib.debug(\"using quiery tooltip?\");",
             "\t\t\t\t",
             "\t\t\tdefault:",
             "\t",
-            "\t\t\t\tstr += (\"<span underline=\\\"single\\\" color=\\\"blue\\\" >\" + ",
+            "\t\t\t\tstr += (\"<a href=\\\"\" + GLib.Markup.escape_text(sig[i]) + \"\\\">\" + ",
             "\t\t\t\t\tGLib.Markup.escape_text(sig[i])",
-            "\t\t\t\t\t+\"</span>\");",
+            "\t\t\t\t\t+\"</a>\");",
             "\t\t\tcontinue;",
             "\t\t}",
             "\t}",
             "\tif (help.contents.size > 1) {",
             "\t\tthis.el.tooltip_markup =  GLib.Markup.escape_text(help.contents.get(1).value);",
+            "\t} else {",
+            "\t\tthis.el.tooltip_markup = GLib.Markup.escape_text(help.contents.get(0).value);",
             "\t}",
-            "\t",
             "\tthis.el.set_markup(string.joinv(\" \",str));",
             "\t",
             "}"
             "\t\t_this.navigation_holder.el.show();",
             "\t\t_this.paned.el.position  = ",
             "\t\t\t_this.paned.el.get_width() - 200;",
-            "\t}",
+            "\t} ",
             "\t//_this.navliststore.el.remove_all();",
             "\t",
             "\t",
             "\tforeach(var sym in syms) {",
             "\t\tls.append(sym);",
             "\t}",
+            "\t// if syms updated is empty, but we already have one..",
+            "\tif (_this.navliststore.el.get_n_items() > 0 && ls.get_n_items() < 1) {",
+            "\t\treturn;",
+            "\t}",
             "\tLsp.DocumentSymbol.copyList(ls, _this.navliststore.el);",
             "\t//_this.navliststore.el.append(sym);",
             "\tthis.last_selected_line = -1;",
index ad50296..fe1fb9f 100644 (file)
@@ -557,6 +557,15 @@ public class Editor : Object
                                lbl.width_request = 500;
                                tooltip.set_custom(lbl);
                        
+                               return true;
+                       });
+                       this.el.activate_link.connect( (uri) => {
+                               GLib.debug("got uri %s", uri);
+                               var ls = _this.file.getLanguageServer();
+                               ls.symbol.begin(uri, (a,b) => {
+                                       ls.symbol.end(b);
+                               });
+                               
                                return true;
                        });
                }
@@ -589,16 +598,17 @@ public class Editor : Object
                                                
                                        default:
                        
-                                               str += ("<span underline=\"single\" color=\"blue\" >" + 
+                                               str += ("<a href=\"" + GLib.Markup.escape_text(sig[i]) + "\">" + 
                                                        GLib.Markup.escape_text(sig[i])
-                                                       +"</span>");
+                                                       +"</a>");
                                        continue;
                                }
                        }
                        if (help.contents.size > 1) {
                                this.el.tooltip_markup =  GLib.Markup.escape_text(help.contents.get(1).value);
+                       } else {
+                               this.el.tooltip_markup = GLib.Markup.escape_text(help.contents.get(0).value);
                        }
-                       
                        this.el.set_markup(string.joinv(" ",str));
                        
                }
@@ -2036,7 +2046,7 @@ public class Editor : Object
                                _this.navigation_holder.el.show();
                                _this.paned.el.position  = 
                                        _this.paned.el.get_width() - 200;
-                       }
+                       } 
                        //_this.navliststore.el.remove_all();
                        
                        
@@ -2045,6 +2055,10 @@ public class Editor : Object
                        foreach(var sym in syms) {
                                ls.append(sym);
                        }
+                       // if syms updated is empty, but we already have one..
+                       if (_this.navliststore.el.get_n_items() > 0 && ls.get_n_items() < 1) {
+                               return;
+                       }
                        Lsp.DocumentSymbol.copyList(ls, _this.navliststore.el);
                        //_this.navliststore.el.append(sym);
                        this.last_selected_line = -1;
index 39cbc51..3f69830 100644 (file)
@@ -89,6 +89,7 @@ namespace Palete {
                public abstract void queueDocumentSymbols (JsRender.JsRender file); 
                public abstract async Gee.ArrayList<Lsp.DocumentSymbol> documentSymbols (JsRender.JsRender file) throws GLib.Error;     
                public abstract async Gee.ArrayList<Lsp.SignatureInformation> signatureHelp (JsRender.JsRender file, int line, int offset) throws GLib.Error;
+               public abstract async Gee.ArrayList<Lsp.SymbolInformation> symbol (string sym) throws GLib.Error;
        }
        
 }
index 400b59c..544f56b 100644 (file)
@@ -38,6 +38,10 @@ namespace Palete {
                {
                        return new Gee.ArrayList<Lsp.SignatureInformation>();   
                }
+               public override async Gee.ArrayList<Lsp.SymbolInformation> symbol (string sym) throws GLib.Error 
+               {
+                       return new Gee.ArrayList<Lsp.SymbolInformation>();
+               }
        }
        
 }
\ No newline at end of file
index 0b2772e..a6b12c7 100644 (file)
@@ -297,6 +297,10 @@ namespace Palete {
                {
                        return new Gee.ArrayList<Lsp.SignatureInformation>();   
                }
+               public override async Gee.ArrayList<Lsp.SymbolInformation> symbol (string sym) throws GLib.Error 
+               {
+                       return new Gee.ArrayList<Lsp.SymbolInformation>();
+               }
                
        }
        
index 5ae317e..03c1634 100644 (file)
@@ -58,8 +58,7 @@ namespace Palete {
 
                        if (this.change_queue_id == 0 ) {
                                this.change_queue_id = GLib.Timeout.add(500, () => {
-                                       this.run_change_queue();
-                                       this.run_doc_queue();
+                                       this.run_change_queue(); 
                                        return true;
                                });
                        }
@@ -93,29 +92,23 @@ namespace Palete {
                        return ;
                }
                 
-                
-               void run_doc_queue()
+               async int queuer(int cnt)
                {
-               
-                       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 ;
+                       SourceFunc cb = this.queuer.callback;
+                 
+                       GLib.Timeout.add(500, () => {
+                                GLib.Idle.add((owned) cb);
+                                return false;
+                       });
+                       
+                       yield;
+                       return cnt;
                }
+               static int doc_queue_id = 0;
+               
+        
+               
+               
                public bool initProcess(string process_path)
                {
                        this.onClose();
@@ -647,36 +640,63 @@ namespace Palete {
 
                }
                
+        
+               
+               static int hover_call_count = 1;
+               bool getting_hover = false;
                
                //CompletionListInfo.itmems.parse_varient  or CompletionListInfo.parsevarient
                public override async  Lsp.Hover hover (JsRender.JsRender file, int line, int offset) throws GLib.Error 
                 {
                        /* partial_result_token ,  work_done_token   context = null) */
-                       GLib.debug("get hover %s %d %d", file.relpath, (int)line, (int)offset);
+                       //GLib.debug("get hover %s %d %d", file.relpath, (int)line, (int)offset);
                        var ret = new Lsp.Hover();      
                        //ret = null;
                    if (!this.isReady()) {
                                return ret;
                        }
+                       if (this.getting_hover) {
+                               return ret;
+                       }
+                       
+                       hover_call_count++;
+                       var  call_id = yield this.queuer(hover_call_count);
+                       
+                       //GLib.debug("end hover call=%d   count=%d", call_id, hover_call_count);                        
+                       if (call_id != hover_call_count) {
+                               //GLib.debug("get hover CANCELLED %s %d %d", file.relpath, (int)line, (int)offset);
+                               return ret;
+                       }
+                       
+                       //GLib.debug("get hover RUN %s %d %d", file.relpath, (int)line, (int)offset);
+                       
+                       this.getting_hover = true;
+                       
                        Variant? return_value;
-                       yield this.jsonrpc_client.call_async (
-                               "textDocument/hover",
-                               this.buildDict (  
-                                        
-                                       textDocument : this.buildDict (    ///TextDocumentItem;
-                                               uri: new GLib.Variant.string (file.to_url()),
-                                               version :  new GLib.Variant.uint64 ( (uint64) file.version) 
+                       try {
+                               yield this.jsonrpc_client.call_async (
+                                       "textDocument/hover",
+                                       this.buildDict (  
+                                                
+                                               textDocument : this.buildDict (    ///TextDocumentItem;
+                                                       uri: new GLib.Variant.string (file.to_url()),
+                                                       version :  new GLib.Variant.uint64 ( (uint64) file.version) 
+                                               ),
+                                               position :  this.buildDict ( 
+                                                       line :  new GLib.Variant.uint64 ( (uint) line) ,
+                                                       character :  new GLib.Variant.uint64 ( uint.max(0,  (offset -1))) 
+                                               )
+                                                
                                        ),
-                                       position :  this.buildDict ( 
-                                               line :  new GLib.Variant.uint64 ( (uint) line) ,
-                                               character :  new GLib.Variant.uint64 ( uint.max(0,  (offset -1))) 
-                                       )
-                                        
-                               ),
-                               null,
-                               out return_value
-                       );
-                       GLib.debug ("LS hover replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));                                 
+                                       null,
+                                       out return_value
+                               );
+                       } catch(GLib.Error e) {
+                               this.getting_hover = false;
+                               throw e;
+                       }
+                       this.getting_hover = false;
+                        GLib.debug ("LS hover replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));                                        
                        if (return_value == null) {
                                return ret;
                        }
@@ -695,22 +715,26 @@ namespace Palete {
 
                }
                
+               
+               static int doc_symbol_queue_call_count = 1;
+               
+               
                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 = 2;
-                       this.doc_queue_file = file;
+                         
+                       this.documentSymbols.begin(file, (o, res) => {
+                               var ret = documentSymbols.end(res);
+                               file.navigation_tree_updated(ret);
+                       });
+                 
+                        
                }
                
+               bool getting_symbols = false;
         
-               public override async Gee.ArrayList<Lsp.DocumentSymbol> documentSymbols (JsRender.JsRender file) throws GLib.Error {
+               public override async Gee.ArrayList<Lsp.DocumentSymbol> documentSymbols (JsRender.JsRender file) throws GLib.Error 
+               {
                        /* partial_result_token ,  work_done_token   context = null) */
                        GLib.debug("get documentSymbols %s", file.relpath);
                        var ret = new Gee.ArrayList<Lsp.DocumentSymbol>();      
@@ -718,23 +742,41 @@ namespace Palete {
                    if (!this.isReady()) {
                                return ret;
                        }
-                       Variant? return_value;
-                       yield this.jsonrpc_client.call_async (
-                               "textDocument/documentSymbol",
-                               this.buildDict (  
-                                        
-                                       textDocument : this.buildDict (    ///TextDocumentItem;
-                                               uri: new GLib.Variant.string (file.to_url()),
-                                               version :  new GLib.Variant.uint64 ( (uint64) file.version) 
-                                       ) 
-                                        
-                               ),
-                               null,
-                               out return_value
-                       );
+                       if (this.getting_symbols) {
+                               return ret;
+                       }
+
                        
+                       doc_symbol_queue_call_count++;
+                       var call_id = yield this.queuer(doc_symbol_queue_call_count);
+                       if (call_id != doc_symbol_queue_call_count) {
+                               
+                               return ret;
+                       }
+                       this.getting_symbols = true;
                        
-                       //GLib.debug ("LS replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));                                     
+                       Variant? return_value;
+                       try { 
+                               yield this.jsonrpc_client.call_async (
+                                       "textDocument/documentSymbol",
+                                       this.buildDict (  
+                                                
+                                               textDocument : this.buildDict (    ///TextDocumentItem;
+                                                       uri: new GLib.Variant.string (file.to_url()),
+                                                       version :  new GLib.Variant.uint64 ( (uint64) file.version) 
+                                               ) 
+                                                
+                                       ),
+                                       null,
+                                       out return_value
+                               );
+                       } catch(Error e) {
+                               this.getting_symbols = false;                   
+                               throw e;
+                       }
+                       this.getting_symbols = false;
+                       
+                       GLib.debug ("LS replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));                                       
                        var json = Json.gvariant_serialize (return_value);
                         
                         
@@ -750,6 +792,7 @@ namespace Palete {
                        
                
                }
+               // cant seem to get this to show anything!!
                public override async Gee.ArrayList<Lsp.SignatureInformation> signatureHelp (JsRender.JsRender file, int line, int offset) throws GLib.Error {
                        /* partial_result_token ,  work_done_token   context = null) */
                        GLib.debug("get signatureHelp %s, %d, %d", file.relpath, line, offset);
@@ -796,7 +839,37 @@ namespace Palete {
                        
                
                }
+               // ok for general symbol search, not much details though.
+               public override async Gee.ArrayList<Lsp.SymbolInformation> symbol (string sym) throws GLib.Error
+               {
+                       /* partial_result_token ,  work_done_token   context = null) */
+                       GLib.debug("get symbol %s,", sym);
+                       var ret = new Gee.ArrayList<Lsp.SymbolInformation>();   
+                       //ret = null;
+                       if (!this.isReady()) {
+                               return ret;
+                       }
+                       Variant? return_value;
+                               yield this.jsonrpc_client.call_async (
+                               "workspace/symbol",
+                               this.buildDict (  
+                                       query :  new GLib.Variant.string (sym)                                   
+                               ),
+                               null,
+                               out return_value
+                       );
+                       
+GLib.debug ("LS replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));      
+                       return ret;
+               }
                
        }
        
+       
+       
+       
+       
+       
+       
+       
 }
\ No newline at end of file