Commit 3617a8a0 authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

sourceview: improve performance on buffer changes

parent c6833af5
......@@ -29,7 +29,7 @@ public class GVlsui.CompletionProvider : GLib.Object, Gtk.SourceCompletionProvid
set {
_server = value;
try {
current_server.add_to_root_server (_server);
_server.add_server (current_server);
} catch (GLib.Error e) {
message ("Error setting completion provider's server': %s", e.message);
}
......
......@@ -25,6 +25,7 @@ public class GVlsui.SourceView : Gtk.SourceView
private GVls.Server _server;
private GVlsui.CompletionProvider _prov;
private bool loaded = false;
public GVls.Server server {
get { return _server; }
......@@ -49,21 +50,33 @@ public class GVlsui.SourceView : Gtk.SourceView
b.highlight_syntax = true;
_prov = new GVlsui.CompletionProvider ();
_prov.current_server.content = "";
loaded = false;
try {
get_completion ().add_provider (_prov);
get_buffer ().changed.connect (()=>{
if (_server == null) return;
try {
_prov.current_server.content = get_buffer ().text;
apply_syntax_highlight ();
} catch (GLib.Error e) {
warning ("Error parsing buffer: %s", e.message);
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 ();
});
} catch (GLib.Error e) {
warning ("Error setting completion provider: %s", e.message);
}
}
public void update_document_symbols () {
_prov.current_server.content = get_buffer ().text;
}
public void apply_syntax_highlight () {
GVls.Container syms = _prov.current_server.document_symbols;
Gtk.TextBuffer buffer = get_buffer ();
......
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