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

sourceview: improved performance

Fix issue #46
parent 8ecfc1f0
......@@ -25,7 +25,8 @@ public class GVlsui.SourceView : Gtk.SourceView
private GVls.Server _server;
private GVlsui.CompletionProvider _prov;
private bool loaded = false;
private uint timed_id = -1;
private bool dirty = true;
public GVls.Server server {
get { return _server; }
......@@ -50,32 +51,32 @@ public class GVlsui.SourceView : Gtk.SourceView
b.highlight_syntax = true;
_prov = new GVlsui.CompletionProvider ();
_prov.current_server.content = "";
loaded = false;
try {
timed_id = Timeout.add (1, update_document_symbols);
get_completion ().add_provider (_prov);
var buf = get_buffer ();
buf.changed.connect (()=>{
if (loaded) {
return;
}
update_document_symbols ();
apply_syntax_highlight ();
loaded = true;
});
buf.insert_text.connect (()=>{
update_document_symbols ();
apply_syntax_highlight ();
});
buf.end_user_action.connect (()=>{
update_document_symbols ();
apply_syntax_highlight ();
dirty = true;
});
} catch (GLib.Error e) {
warning ("Error setting completion provider: %s", e.message);
}
}
public void update_document_symbols () {
~SourceView () {
if (timed_id != -1) {
var source = MainContext.@default ().find_source_by_id (timed_id);
if (source != null) {
source.destroy ();
}
}
}
public bool update_document_symbols () {
if (!dirty) return true;
_prov.current_server.content = get_buffer ().text;
apply_syntax_highlight ();
dirty = false;
return true;
}
public void apply_syntax_highlight () {
GVls.Container syms = _prov.current_server.document_symbols;
......
......@@ -160,7 +160,6 @@ public class App {
assert (server.get_symbol ("GLib") != null);
message ("Current Servers: %u", server.servers.get_n_items ());
assert (server.servers.get_n_items () == 2);
assert (server.get_symbol ("t") != null);
});
win.show_all ();
Gtk.main ();
......
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