Fix #8047 - debugging language server and fix completion handling
authorAlan Knowles <alan@roojs.com>
Sun, 25 Feb 2024 04:15:48 +0000 (12:15 +0800)
committerAlan Knowles <alan@roojs.com>
Sun, 25 Feb 2024 04:15:48 +0000 (12:15 +0800)
src/Palete/CompletionProvider.vala
src/Palete/LanguageClientVala.vala

index cfc902c..5f5e527 100644 (file)
@@ -36,7 +36,7 @@ namespace Palete {
                
                public bool is_trigger(global::Gtk.TextIter  iter, unichar ch)
                {
-                       if (this.in_populate || ch == 32) {
+                       if (this.in_populate || ch == 32 || ch == 10) {
                                return false;
                        }
                        if (this.editor.buffer.el.iter_has_context_class(iter, "comment") ||
@@ -44,9 +44,13 @@ namespace Palete {
                        ) { 
                                return false;
                        }
+                       var back = iter.copy();
+                       back.backward_char();
                        
+                       // what's the character at the iter?
+                       var str = back.get_text(iter);
                        
-                       //GLib.debug("should trigger? %c", (int) ch);
+                       GLib.debug("Previos char to trigger is '%s;", str);
                        
                        
                        return true;
@@ -251,8 +255,14 @@ namespace Palete {
                        GLib.debug("pupoulate async  - got reply");
                        this.model = new CompletionModel(this, context, res, cancellable); 
                        var word = context.get_word();
-                       GLib.debug("Context word is %s, %d", word, (int)word.length);
-                       if (word.length < 1) {
+                       
+                       var lc = end.copy();
+                       lc.backward_char();
+                       var lchar = lc.get_text(end);
+                       
+                       
+                       GLib.debug("Context word is %s / '%s' , %d", word, lchar, (int)word.length);
+                       if (word.length < 1 && lchar != ".") {
                                word = " "; // this should filter out everything, and prevent it displaying 
                        }
                        
@@ -331,11 +341,12 @@ namespace Palete {
                                         if (comp.label == "_") { // skip '_'
                                                continue;
                                        }
+                                       GLib.debug("got suggestion %s", comp.label);
                                        this.items.add(new CompletionProposal(comp));   
                                        
                                }
                        }
-                   print("GOT %d results\n", (int) items.size); 
+                   GLib.debug("GOT %d results\n", (int) items.size); 
                        // WHY TWICE?
                    if (this.items.size < this.minimum_word_size) {
                                return;
index cd3e3b0..e0156aa 100644 (file)
@@ -80,11 +80,27 @@ namespace Palete {
                        this.log(LanguageClientAction.LAUNCH, process_path);
                        GLib.debug("Launching %s", process_path);
                        this.launcher = new GLib.SubprocessLauncher (SubprocessFlags.STDIN_PIPE | SubprocessFlags.STDOUT_PIPE);
-                       this.launcher.set_environ(GLib.Environ.get());
+                       var env = GLib.Environ.get();
+                       env += "G_MESSAGES_DEBUG=all";
+
+                       this.launcher.set_environ(env);
+                       var logpath = GLib.Environment.get_home_dir() + "/.cache/vala-language-server";
+                       
+                       if (!GLib.FileUtils.test(logpath, GLib.FileTest.IS_DIR)) {
+                               Posix.mkdir(logpath, 0700);
+                       }
+                       // not very reliable..
+                       //this.launcher.set_stderr_file_path( 
+                       //      logpath + "/" + 
+                       //      (new GLib.DateTime.now_local()).format("%Y-%m-%d") + ".log"
+                       //);
+                       //GLib.debug("log lang server to %s", logpath + "/" + 
+                       //      (new GLib.DateTime.now_local()).format("%Y-%m-%d") + ".log");
+
                        try {
 
                                
-                               this.subprocess = launcher.spawnv ({ process_path });
+                               this.subprocess = launcher.spawnv ({ process_path , "2>" , "/tmp/vala-language-server.log" });
                                
                                this.subprocess.wait_async.begin( null, ( obj,res ) => {
                                        try {
@@ -136,9 +152,10 @@ namespace Palete {
                                 
                                this.jsonrpc_client.failed.connect(() => {
                                        this.log(LanguageClientAction.ERROR_RPC, "client failed");
+                                       GLib.debug("language server server has failed");                                        
                                        this.onClose();
                                        
-                                       GLib.debug("language server server has failed");
+
                                });
 
                                this.initialize_server ();
@@ -256,7 +273,11 @@ namespace Palete {
                        switch (method) {
                                case "textDocument/publishDiagnostics":
                                        //GLib.debug("got notification %s : %s",  method , Json.to_string (Json.gvariant_serialize (return_value), true));
-                                       this.onDiagnostic(return_value);
+                                        
+                                       GLib.Idle.add(() => {
+                                               this.onDiagnostic(return_value);
+                                               return false;
+                                       });
                                        return;
                                default: 
                                        break;