sync wip_alan_T7982_roo_javascript_completion origin/wip_alan_T7982_roo_javascript_completion
authorAlan <alan@roojs.com>
Tue, 23 Jan 2024 09:38:05 +0000 (17:38 +0800)
committerAlan <alan@roojs.com>
Tue, 23 Jan 2024 09:38:05 +0000 (17:38 +0800)
src/Builder4/DialogConfirm.bjs
src/Builder4/DialogConfirm.vala
src/Palete/CompletionProvider.vala
src/Palete/LanguageClientJavascript.vala

index 045bf89..551f453 100644 (file)
@@ -15,7 +15,7 @@
      "   this.el.response(Gtk.ResponseType.CANCEL);",
      "    this.el.hide();",
      "    return true;",
-     " ",
+     "",
      "}",
      ""
     ]
index dfb48ad..ef1281c 100644 (file)
@@ -1,53 +1,53 @@
-    static DialogConfirm  _DialogConfirm;
-
-    public class DialogConfirm : Object
-    {
-        public Gtk.MessageDialog el;
-        private DialogConfirm  _this;
-
-        public static DialogConfirm singleton()
-        {
-            if (_DialogConfirm == null) {
-                _DialogConfirm= new DialogConfirm();
-            }
-            return _DialogConfirm;
-        }
-
-            // my vars (def)
-
-        // ctor
-        public DialogConfirm()
-        {
-            _this = this;
-            this.el = new Gtk.MessageDialog( null, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Test" );
-
-            // my vars (dec)
-
-            // set gobject values
-            this.el.title = "Please Confirm ";
-            this.el.name = "DialogConfirm";
-            this.el.modal = true;
-            this.el.use_markup = true;
-
-            //listeners
-            this.el.close_request.connect( (event) => {
-               this.el.response(Gtk.ResponseType.CANCEL);
-                this.el.hide();
-                return true;
-             
-            });
-        }
-
-        // user defined functions
-        public void showIt // caller needs to connect to the  response -  to get the result.
-          
-          (string title, string msg) {
-             //if (!this.el) { this.init(); } 
-             //this.success = success;
-             this.el.title = title;
-            this.el.text =  msg;
-            this.el.show();
-           
-           
-        }
-    }
+static DialogConfirm  _DialogConfirm;
+
+public class DialogConfirm : Object
+{
+       public Gtk.MessageDialog el;
+       private DialogConfirm  _this;
+
+       public static DialogConfirm singleton()
+       {
+               if (_DialogConfirm == null) {
+                   _DialogConfirm= new DialogConfirm();
+               }
+               return _DialogConfirm;
+       }
+
+               // my vars (def)
+
+       // ctor
+       public DialogConfirm()
+       {
+               _this = this;
+               this.el = new Gtk.MessageDialog( null, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Test" );
+
+               // my vars (dec)
+
+               // set gobject values
+               this.el.title = "Please Confirm ";
+               this.el.name = "DialogConfirm";
+               this.el.modal = true;
+               this.el.use_markup = true;
+
+               //listeners
+               this.el.close_request.connect( (event) => {
+                  this.el.response(Gtk.ResponseType.CANCEL);
+                   this.el.hide();
+                   return true;
+               
+               });
+       }
+
+       // user defined functions
+       public void showIt // caller needs to connect to the  response -  to get the result.
+         
+         (string title, string msg) {
+            //if (!this.el) { this.init(); } 
+            //this.success = success;
+            this.el.title = title;
+           this.el.text =  msg;
+           this.el.show();
+          
+          
+       }
+}
index 4cb9f61..06259d4 100644 (file)
@@ -197,10 +197,15 @@ namespace Palete {
                                var offset =  end.get_line_offset();
                                if (this.editor.prop != null) {
                                //      tried line -1 (does not work)
-                               
+                                       GLib.debug("node pad = '%s' %d", this.editor.node.node_pad, this.editor.node.node_pad.length);
+                                       
                                        line += this.editor.prop.start_line ; 
                                        // this is based on Gtk using tabs (hence 1/2 chars);
-                                       offset += this.editor.file.file_namespace == "" ? 1 : 2; 
+                                       offset += this.editor.node.node_pad.length;
+                                       // javascript listeners are indented 2 more spaces.
+                                       if (this.editor.prop.ptype == JsRender.NodePropType.LISTENER) {
+                                               offset += 2;
+                                       }
                                } 
                                
                                this.file.getLanguageServer().document_change_force(this.file, this.editor.tempFileContents());                         
index f13e167..8f8b357 100644 (file)
@@ -56,20 +56,20 @@ namespace Palete {
                                GLib.debug("got file %s : MISSING ", file.path);                                
                                return ret;
                        }
-                       GLib.debug("got file %s : %s ", file.path, this.file_contents.get(file.path));
+                       //GLib.debug("got file %s : %s ", file.path, this.file_contents.get(file.path));
                        
                        var ar = this.file_contents.get(file.path).split("\n");
                        var ln = line >= ar.length ? "" :  ar[line-1];
-                       if (offset >= ln.length) {
-                               GLib.debug("request for complete on line %d > file length %d", offset, (int) ln.length);
+                       if (offset-1 >= ln.length) {
+                               GLib.debug("request for complete on line %d  @ pos %d > line length %d", line, offset, (int) ln.length);
                                return ret;
                        } 
                        GLib.debug("got Line %d:%d '%s' ", line, offset,  ln);
                        
                        var start = -1;
-                       for (var i = offset -1; i > 0; i--) {
-                               GLib.debug("check char %d '%c'", i, ln[i]);
-                               if (ln[i].isalpha() || ln[i] == '.') {
+                       for (var i = offset - 1; i > 0; i--) {
+                               GLib.debug("check char %d '%c'", i, ln[i]); 
+                               if (ln[i].isalpha() || ln[i] == '.' || ln[i] == '_') { // any other allowed chars?
                                        start = i;
                                        continue;
                                }
@@ -124,15 +124,32 @@ namespace Palete {
                        var parts = complete_string.split(".");
                        var curtype = "";
                        var cur_instance = false;
+                       if (parts[0] == "_this") {
+                               if (file.tree == null) {
+
+                                       GLib.debug("file has no tree");
+                                       return ret; // no idea..
+                               }
+                               curtype = file.tree.fqn();
+                               cur_instance = true;                            
+                               // work out from the node, what the type is...
+                               // fetch node from element.
+
+                               //curtype = node.fqn();
+                               cur_instance = true;
+                       }
+                       
+                       
                        if (parts[0] == "this") {
                                // work out from the node, what the type is...
                                // fetch node from element.
-                               //if (node == null) {
-                                       GLib.debug("node is empty - no return\n");
+                               var node = file.lineToNode(line -1); // hopefuly
+                               if (node == null) {
+                                       GLib.debug("could nt find scope for 'this'");
                                        return ret; // no idea..
-                               //}
-                               //curtype = node.fqn();
-                               //cur_instance = true;
+                               }
+                               curtype = node.fqn();
+                               cur_instance = true;
                        }
                        if (parts[0] == "Roo") {        
                                curtype = "Roo";
@@ -147,7 +164,7 @@ namespace Palete {
                                // look up all the properties of the type...
                                var cls = this.project.palete.getClass(curtype);
                                if (cls == null) {
-                                       GLib.debug("could not get class of curtype %s\n", curtype);
+                                       GLib.debug("could not get class of curtype '%s'\n", curtype);
                                        return ret;
                                }
 
@@ -231,7 +248,7 @@ namespace Palete {
                                        // got a matching property...
                                        // return type?
                                        
-                                       var sci =  new Lsp.CompletionItem.keyword( prevbits + prop.name + "(", prop.name + "(" , prop.doctxt );
+                                       var sci =  new Lsp.CompletionItem.keyword( prop.name + "(", prop.name + "(" , prop.doctxt );
                                        ret.items.add(sci);
 
                                 
@@ -244,11 +261,11 @@ namespace Palete {
                                while (citer.next()) {
                                        var prop = citer.get_value();
                                        // does the name start with ...
-                                       if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
-                                               continue;
-                                       }
+                                       //if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
+                                       //      continue;
+                                       //}
                                        
-                                       var sci =  new Lsp.CompletionItem.keyword( prevbits +  prop.name + "(", prop.name + "(" , prop.doctxt );
+                                       var sci =  new Lsp.CompletionItem.keyword( prop.name, prop.name , prop.doctxt );
                                        ret.items.add(sci);