Fix #8104 - update nav tree by comparing changes
authorAlan Knowles <alan@roojs.com>
Thu, 21 Mar 2024 14:37:12 +0000 (22:37 +0800)
committerAlan Knowles <alan@roojs.com>
Thu, 21 Mar 2024 14:37:12 +0000 (22:37 +0800)
src/Builder4/Editor.bjs
src/Builder4/Editor.vala
src/Lsp.vala
src/Palete/LanguageClientVala.vala

index 484968a..af1b6bc 100644 (file)
                "\tsym.set_data<Gtk.Widget>(\"widget\", expand.get_parent());",
                "\texpand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>(\"symbol\", sym);",
                "\t",
-               "\tGLib.debug(\"save sym on %s\", expand.get_parent().get_parent().get_type().name());",
+               "\t//GLib.debug(\"save sym on %s\", expand.get_parent().get_parent().get_type().name());",
                "\t",
                "\t//GLib.debug(\"got %d children for %s\" , (int)sym.children.get_n_items(), sym.name);",
                "    ",
          "| void show" : [
           "(Gee.ArrayList<Lsp.DocumentSymbol> syms) {",
           "\t_this.navigationwindow.el.show();",
-          "\t_this.navliststore.el.remove_all();",
+          "\t//_this.navliststore.el.remove_all();",
+          "\t",
+          "\t",
+          "\tvar ls  = new GLib.ListStore(typeof(Lsp.DocumentSymbol));",
+          "\t",
           "\tforeach(var sym in syms) {",
-          "\t\t_this.navliststore.el.append(sym);",
+          "\t\tls.append(sym);",
           "\t}",
+          "\tLsp.DocumentSymbol.copyList(ls, _this.navliststore.el);",
+          "\t//_this.navliststore.el.append(sym);",
           "\tthis.last_selected_line = -1;",
           "\tGLib.Idle.add(() => {",
           "",
index afabae3..d54bc2a 100644 (file)
@@ -1848,10 +1848,16 @@ public class Editor : Object
                 }
                public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
                        _this.navigationwindow.el.show();
-                       _this.navliststore.el.remove_all();
+                       //_this.navliststore.el.remove_all();
+                       
+                       
+                       var ls  = new GLib.ListStore(typeof(Lsp.DocumentSymbol));
+                       
                        foreach(var sym in syms) {
-                               _this.navliststore.el.append(sym);
+                               ls.append(sym);
                        }
+                       Lsp.DocumentSymbol.copyList(ls, _this.navliststore.el);
+                       //_this.navliststore.el.append(sym);
                        this.last_selected_line = -1;
                        GLib.Idle.add(() => {
                
@@ -2042,7 +2048,7 @@ public class Editor : Object
                                sym.set_data<Gtk.Widget>("widget", expand.get_parent());
                                expand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>("symbol", sym);
                                
-                               GLib.debug("save sym on %s", expand.get_parent().get_parent().get_type().name());
+                               //GLib.debug("save sym on %s", expand.get_parent().get_parent().get_type().name());
                                
                                //GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
                            
index fbc1e9a..21ab644 100644 (file)
@@ -152,7 +152,9 @@ namespace Lsp {
 
         public bool equal_to (Range other) { return this.to_string () == other.to_string (); }
                public bool equals (Range o) {
-                       return this.filename == o.filename && this.start.equals(o.start) && this.end.equals(o.end);
+                       return this.filename == o.filename && 
+                                       this.start.equals(o.start) && 
+                                       this.end.equals(o.end);
                }
 
         public int compare_to (Range other) {
@@ -405,16 +407,16 @@ namespace Lsp {
 
         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) 
            {
-               GLib.debug("deserialise property %s" , property_name);
+               //GLib.debug("deserialise property %s" , property_name);
                if (property_name != "children") {
                    return default_deserialize_property (property_name, out value, pspec, property_node);
                }
             value = GLib.Value (typeof(GLib.ListStore));
                if (property_node.get_node_type () != Json.NodeType.ARRAY) {
-                   GLib.debug ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
+                  // GLib.debug ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
                    return false;
                }
-                       GLib.debug("got child length of %d", (int) property_node.get_array ().get_length());
+                       //GLib.debug("got child length of %d", (int) property_node.get_array ().get_length());
                var arguments = new GLib.ListStore(typeof(DocumentSymbol));
 
                property_node.get_array ().foreach_element ((array, index, element) => {
@@ -437,7 +439,7 @@ namespace Lsp {
                 
                public string tooltip {
                        owned get {
-                               GLib.debug("%s : %s", this.name, this.detail);
+                               //GLib.debug("%s : %s", this.name, this.detail);
                                //var detail = this.detail == "" ? (this.kind.to_string() + ": " + this.name) : this.detail;
                                 return GLib.Markup.escape_text(this.detail + "\nline: " + this.range.start.line.to_string());
                                
@@ -465,8 +467,57 @@ namespace Lsp {
                        return this;
                        
                }
+               // does not compare children...
                public bool equals(DocumentSymbol sym) {
-                       return this.name == sym.name && this.kind == sym.kind &&  sym.range.equals(this.range);
+                       return this.name == sym.name && 
+                                       this.kind == sym.kind && 
+                                       this.detail == sym.detail &&
+                                       sym.range.equals(this.range);
+               }
+               
+               public static void copyList(GLib.ListStore source, GLib.ListStore target) 
+               {
+                       //GLib.debug("copyList source=%d target=%d", (int)source.get_n_items(), (int)target.get_n_items());
+                       var i = 0;
+                       while (i < source.get_n_items()) {
+                               //GLib.debug("copyList compare %d", i);
+                               if (i >= target.get_n_items()) {
+                                       //GLib.debug("copyList append");
+                                       target.append(source.get_item(i));
+                                       i++;
+                                       continue;
+                               }
+                               var sel = (Lsp.DocumentSymbol) source.get_item(i);
+                               var tel = (Lsp.DocumentSymbol) target.get_item(i);
+                               if (!sel.equals(tel)) {
+                                       //GLib.debug("copyList replace");
+                                       target.remove(i);
+                                       target.insert(i, sel);
+                                       i++;
+                                       continue;
+                               }
+
+                               if (sel.children.get_n_items() < 1 && tel.children.get_n_items() < 1) {
+                                       i++;
+                                       //GLib.debug("copyList same  noChlidren %s", sel.name);
+                                       continue;
+
+                               }
+                               //GLib.debug("copyList same = updateChildren %s", sel.name);
+                               //
+                                       // they are the same (ignoring children
+                               copyList(sel.children,tel.children);
+                               i++;
+                       
+                       }
+                       // remove target items, that dont exist anymore
+                       while (i < target.get_n_items()) {
+                               //GLib.debug("copyList remove");
+                               target.remove(i);
+                       }
+                       
+                       
+               
                }
           
           
index 1be2b05..e8399fa 100644 (file)
@@ -57,7 +57,7 @@ namespace Palete {
                        base(project);
 
                        if (this.change_queue_id == 0 ) {
-                               this.change_queue_id = GLib.Timeout.add_seconds(1, () => {
+                               this.change_queue_id = GLib.Timeout.add(500, () => {
                                        this.run_change_queue();
                                        this.run_doc_queue();
                                        return true;
@@ -478,7 +478,7 @@ namespace Palete {
                                });
                        }
                        
-                       this.countdown = 3;
+                       this.countdown = 4;
                        this.change_queue_file = file;
                         
                        
@@ -493,7 +493,7 @@ namespace Palete {
                        if (!this.isReady()) {
                                return;
                        }
-                       this.countdown = 9; // not really relivant..
+                       this.countdown = -2; // not really relivant..
                        this.change_queue_file = null; // this is more important..
                        
                    if (!this.open_files.contains(file)) {
@@ -698,7 +698,7 @@ namespace Palete {
                                });
                        }
                        
-                       this.doc_countdown = 3;
+                       this.doc_countdown = 4;
                        this.doc_queue_file = file;
                }