Commit ce2c631f authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

gedit-plugin: improved performance

Fix #45
parent 3617a8a0
......@@ -231,7 +231,11 @@ public interface GVls.Server : GLib.Object, ContainerHashable
}
for (int i = 0; i < nss.get_n_items (); i++) {
var ons = nss.get_item (i) as StringObject;
add_namespace (ons.val);
try {
add_namespace (ons.val);
} catch (GLib.Error e) {
message ("Error adding namespace: %s: %s", ons.val, e.message);
}
}
}
/**
......@@ -247,7 +251,12 @@ public interface GVls.Server : GLib.Object, ContainerHashable
return;
}
for (int j = 0; j < l.get_n_items (); j++) {
add_namespace ((l.get_item (j) as StringObject).val);
var ns = l.get_item (j) as StringObject;
try {
add_namespace (ns.val);
} catch (GLib.Error e) {
message ("Error adding namespace: %s: %s", ns.val, e.message);
}
}
}
}
......
......@@ -53,7 +53,6 @@ namespace GVlsEdit {
var prov = view.get_data<GVlsui.CompletionProvider> ("gvls-provider");
if (prov == null) return;
try {
message ("Document to parse: %s", doc.get_file ().location.get_uri ());
prov.current_server.parse (doc.get_file ().location);
prov.server = _server;
} catch (GLib.Error e) {
......@@ -64,6 +63,13 @@ namespace GVlsEdit {
public class View : Peas.ExtensionBase, Gedit.ViewActivatable
{
GVlsui.CompletionProvider prov = new GVlsui.CompletionProvider ();
Gtk.TextIter pos = Gtk.TextIter ();
bool dirty = true;
bool keep = true;
~View () {
keep = false;
}
public Gedit.View view {
owned get; construct;
......@@ -73,21 +79,24 @@ namespace GVlsEdit {
try {
view.get_completion ().add_provider (prov);
view.set_data<GVlsui.CompletionProvider> ("gvls-provider", prov);
message ("Provider data setted");
view.get_buffer ().changed.connect (()=>{
if (prov.current_server == null) return;
try {
prov.current_server.parse_string (view.get_buffer ().text);
prov.server.add_using_namespaces ();
} catch (GLib.Error e) {
warning ("Error parsing buffer: %s", e.message);
}
prov.current_server.parse_string (view.get_buffer ().text);
var buf = view.get_buffer ();
buf.insert_text.connect ((ref pos, ntext, tlen)=>{
dirty = true;
});
GLib.Timeout.add (1, update_symbols);
} catch (GLib.Error e) {
warning ("Error setting completion provider: %s", e.message);
}
}
private bool update_symbols () {
if (!dirty) return keep;
prov.current_server.parse_string (view.get_buffer ().text);
dirty = false;
return keep;
}
public void deactivate () {
try {
view.get_completion ().remove_provider (prov);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment