Fix #8123 - experiment with lang server - docsymbols works with vapi
authorAlan Knowles <alan@roojs.com>
Sat, 30 Mar 2024 08:13:44 +0000 (16:13 +0800)
committerAlan Knowles <alan@roojs.com>
Sat, 30 Mar 2024 08:13:44 +0000 (16:13 +0800)
src/Application.vala
src/Builder4/Editor.bjs
src/Builder4/Editor.vala
src/JsRender/PlainFile.vala
src/Palete/LanguageClient.vala
src/Palete/LanguageClientDummy.vala
src/Palete/LanguageClientJavascript.vala
src/Palete/LanguageClientVala.vala
src/Project/Gtk.vala

index 9ba9057..ba342a0 100644 (file)
                        var file = cur_project.getByRelPath(BuilderApplication.opt_language_server);
                        if (file == null) {
                                // then compile them all, and compare them...
-                                GLib.error("missing file %s in project %s", BuilderApplication.opt_language_server, cur_project.name);
+
+                               if (!GLib.FileUtils.test(BuilderApplication.opt_language_server, FileTest.EXISTS)) {
+                                       GLib.error("missing file %s in project %s", BuilderApplication.opt_language_server, cur_project.name);
+
+                               }
+                               // in theory we can test a vapi?
+                               file = new JsRender.PlainFile(cur_project,BuilderApplication.opt_language_server);
                        }
                        
                        var ls = file.getLanguageServer();
                        //Posix.sleep( 30 );
                        var loop = new MainLoop();
                        GLib.Timeout.add_seconds(1, () => {
-                        
-                               GLib.debug("Sending document_open");
+                               if (!ls.isReady()) {
+                                       GLib.debug("LS not ready - try again");
+                               
+                                       return true;
+                               }
+                               //GLib.debug("Sending document_open");
                                // it's ready..
                                 
-                               ls.document_open(file);
-                               ls.document_save.begin( file, (o,res) => {
-                                       ls.document_save.end(res);
-                                });
+                               //ls.document_open(file);
+                               //ls.document_save.begin( file, (o,res) => {
+                               //      ls.document_save.end(res);
+                                //});
                                
                                //ls.syntax.begin(file, (obj,res) => {
                                //      ls.syntax.end(res);
                                
-                               //});
+                               //});                           
+                               GLib.debug("Sending docSybmols");
                                
+                               ls.documentSymbols.begin(file, (o,res) => {
+                                       GLib.debug("Got doc symbols return");
+                                       ls.documentSymbols.end(res);
+                               });
                                
                                return false;
                                
index 1c1a75b..ed341c2 100644 (file)
            "| void show" : [
             "(Gee.ArrayList<Lsp.DocumentSymbol> syms) {",
             "\t",
-            "\tif (!_this.navigation_holder.el.visible) {",
+            "\tif (!_this.navigation_holder.el.visible && syms.size > 0) {",
             "\t\t_this.navigation_holder.el.show();",
             "\t\t_this.paned.el.position  = ",
             "\t\t\t_this.paned.el.get_width() - 200;",
index fe1fb9f..825f993 100644 (file)
@@ -2042,7 +2042,7 @@ public class Editor : Object
                 }
                public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
                        
-                       if (!_this.navigation_holder.el.visible) {
+                       if (!_this.navigation_holder.el.visible && syms.size > 0) {
                                _this.navigation_holder.el.show();
                                _this.paned.el.position  = 
                                        _this.paned.el.get_width() - 200;
index 29f8284..e3ce7c0 100644 (file)
@@ -161,9 +161,13 @@ namespace JsRender {
 
                public   override string language_id() 
                {
+                       
+                       GLib.debug("file ext: %s", this.file_ext);
                        switch(this.file_ext) {
                                case "js": return "javascript";
                                case "vala": return "vala";
+                               case "vapi": return "vala";
+                               case "c": return "c";                           
                                case "php": return "php";
                                case "css": return "css";
                                case "sql": return "sql";
index 3f69830..82fd2c8 100644 (file)
@@ -76,7 +76,7 @@ namespace Palete {
                
                public abstract  void initialize_server();
  
-               
+               public abstract bool isReady () ; 
                public abstract void document_open (JsRender.JsRender file) ; 
                public abstract async void document_save (JsRender.JsRender file); 
                public abstract void document_close (JsRender.JsRender file);
index 544f56b..8c4507f 100644 (file)
@@ -13,6 +13,7 @@ namespace Palete {
                public override   void  initialize_server()   {
                        GLib.debug("initialize dummy server");                  
                }
+               public override bool isReady ()  { return true; } 
                public override void document_open (JsRender.JsRender file)  {}
                public override async void document_save (JsRender.JsRender file)   {}
                public override void document_change (JsRender.JsRender file    )     {}
index a6b12c7..b283835 100644 (file)
@@ -15,7 +15,7 @@ namespace Palete {
                public override   void  initialize_server()   {
                        GLib.debug("initialize javascript server");                     
                }
-                
+               public override bool isReady ()  { return true; } 
                 
                public override void document_open (JsRender.JsRender file)  
                {
index 03c1634..f49bbd8 100644 (file)
@@ -195,7 +195,6 @@ namespace Palete {
 
                                this.initialize_server ();
                        } 
-                                        
                         
                }
                
@@ -279,7 +278,7 @@ namespace Palete {
                         
                }
        
-               public bool isReady()
+               public override bool isReady()
                {
                        if (this.closed) {
                                this.log(LanguageClientAction.RESTART,"closed is set - restarting");
@@ -740,9 +739,11 @@ namespace Palete {
                        var ret = new Gee.ArrayList<Lsp.DocumentSymbol>();      
                        //ret = null;
                    if (!this.isReady()) {
+                       GLib.debug("docsymbols not ready");
                                return ret;
                        }
                        if (this.getting_symbols) {
+                               GLib.debug("docsymbols currently getting symbols");
                                return ret;
                        }
 
@@ -750,7 +751,7 @@ namespace Palete {
                        doc_symbol_queue_call_count++;
                        var call_id = yield this.queuer(doc_symbol_queue_call_count);
                        if (call_id != doc_symbol_queue_call_count) {
-                               
+                               GLib.debug("docsymbols call id does not match %d %d" ,call_id , doc_symbol_queue_call_count);
                                return ret;
                        }
                        this.getting_symbols = true;
index 42afbc9..9433e62 100644 (file)
@@ -234,8 +234,11 @@ namespace Project
                        if (this.language_servers.has_key(lang)) {
                                return this.language_servers.get(lang);
                        }
+                       
+                       GLib.debug("Get language Server %s", lang);
                        switch( lang ) {
                                case "vala":
+                               case "c": // not really... but we like it..
                                        var ls = new Palete.LanguageClientVala(this);
                                        ls.log.connect((act, msg) => {
                                                //GLib.debug("log %s: %s", act.to_string(), msg);