Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit time vala symbol pane takes to parse and display symbols #1515

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/SymbolPane/SymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
protected Code.Widgets.SourceList.ExpandableItem root;
protected Gtk.CssProvider source_list_style_provider;
public Gtk.Widget get_widget () { return this; }
public bool tool_box_sensitive {
set {
search_entry.sensitive = value;
filter_button.sensitive = value;
}
}

public virtual void parse_symbols () {}

Gtk.MenuButton filter_button;
Expand Down
35 changes: 33 additions & 2 deletions src/SymbolPane/Vala/ValaSymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline {
public const int PARSE_TIME_MAX_MSEC = 1000;
private Code.Plugins.ValaSymbolResolver resolver;
private Vala.Parser parser;
private GLib.Cancellable cancellable;
Expand Down Expand Up @@ -66,7 +67,9 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
}
}

private uint parse_timeout_id = 0;
public override void parse_symbols () {
tool_box_sensitive = true;
var context = new Vala.CodeContext ();
#if VALA_0_50
context.set_target_profile (Vala.Profile.GOBJECT, false);
Expand All @@ -87,8 +90,20 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
resolver.resolve (context);
Vala.CodeContext.pop ();

bool took_too_long = false;
parse_timeout_id = Timeout.add_full (Priority.LOW, PARSE_TIME_MAX_MSEC, () => {
parse_timeout_id = 0;
took_too_long = true;
cancellable.cancel ();
return Source.REMOVE;
});

var new_root = construct_tree (cancellable);
if (!cancellable.is_cancelled ()) {
if (parse_timeout_id > 0) {
Source.remove (parse_timeout_id);
}

if (!cancellable.is_cancelled () || took_too_long) {
Idle.add (() => {
double adjustment_value = store.vadjustment.value;
var root_children = store.root.children; // Keep reference to children for later destruction
Expand All @@ -97,7 +112,21 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
destroy_all_children ((Code.Widgets.SourceList.ExpandableItem)child);
}

store.root.add (new_root);
if (took_too_long) {
var warning_item = new Code.Widgets.SourceList.Item () {
icon = new ThemedIcon ("dialog-warning"),
markup = "<big>%s</big>".printf (_("Too Many Symbols")),
tooltip = _("%s contains too many Vala symbols.\nParsing and showing them took long").printf (doc.file.get_basename ()),
selectable = false
};

store.root.add (warning_item);
tool_box_sensitive = false;

} else {
store.root.add (new_root);
}

store.root.expand_all ();
store.vadjustment.set_value (adjustment_value);

Expand All @@ -106,6 +135,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
} else {
destroy_all_children (new_root);
}

return null;
});
}
Expand Down Expand Up @@ -141,6 +171,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline

construct_child (symbol, new_root, cancellable);
}

return new_root;
}

Expand Down
Loading