From 5d1cebf6dde6634da0fc2f17827259a6eeec0799 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 21 Mar 2024 22:37:12 +0800 Subject: [PATCH] Fix #8104 - update nav tree by comparing changes --- src/Builder4/Editor.bjs | 12 ++++-- src/Builder4/Editor.vala | 12 ++++-- src/Lsp.vala | 63 +++++++++++++++++++++++++++--- src/Palete/LanguageClientVala.vala | 8 ++-- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/src/Builder4/Editor.bjs b/src/Builder4/Editor.bjs index 484968ab8..af1b6bc81 100644 --- a/src/Builder4/Editor.bjs +++ b/src/Builder4/Editor.bjs @@ -973,7 +973,7 @@ "\tsym.set_data(\"widget\", expand.get_parent());", "\texpand.get_parent().get_parent().set_data(\"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);", " ", @@ -1278,10 +1278,16 @@ "| void show" : [ "(Gee.ArrayList 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(() => {", "", diff --git a/src/Builder4/Editor.vala b/src/Builder4/Editor.vala index afabae344..d54bc2ad5 100644 --- a/src/Builder4/Editor.vala +++ b/src/Builder4/Editor.vala @@ -1848,10 +1848,16 @@ public class Editor : Object } public void show (Gee.ArrayList 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("widget", expand.get_parent()); expand.get_parent().get_parent().set_data("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); diff --git a/src/Lsp.vala b/src/Lsp.vala index fbc1e9a5b..21ab644f2 100644 --- a/src/Lsp.vala +++ b/src/Lsp.vala @@ -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); + } + + + } diff --git a/src/Palete/LanguageClientVala.vala b/src/Palete/LanguageClientVala.vala index 1be2b0596..e8399fa71 100644 --- a/src/Palete/LanguageClientVala.vala +++ b/src/Palete/LanguageClientVala.vala @@ -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; } -- 2.39.2