Skip to content

Commit b267a50

Browse files
jeremypwzeebok
andauthored
Timeout tree construction (#1515)
Co-authored-by: Ryan Kornheisl <ryan@skarva.tech>
1 parent c6960ca commit b267a50

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/SymbolPane/SymbolOutline.vala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
7979
protected Code.Widgets.SourceList.ExpandableItem root;
8080
protected Gtk.CssProvider source_list_style_provider;
8181
public Gtk.Widget get_widget () { return this; }
82+
public bool tool_box_sensitive {
83+
set {
84+
search_entry.sensitive = value;
85+
filter_button.sensitive = value;
86+
}
87+
}
88+
8289
public virtual void parse_symbols () {}
8390

8491
Gtk.MenuButton filter_button;

src/SymbolPane/Vala/ValaSymbolOutline.vala

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline {
20+
public const int PARSE_TIME_MAX_MSEC = 1000;
2021
private Code.Plugins.ValaSymbolResolver resolver;
2122
private Vala.Parser parser;
2223
private GLib.Cancellable cancellable;
@@ -71,7 +72,9 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
7172
}
7273
}
7374

75+
private uint parse_timeout_id = 0;
7476
public override void parse_symbols () {
77+
tool_box_sensitive = true;
7578
var context = new Vala.CodeContext ();
7679
#if VALA_0_50
7780
context.set_target_profile (Vala.Profile.GOBJECT, false);
@@ -92,8 +95,20 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
9295
resolver.resolve (context);
9396
Vala.CodeContext.pop ();
9497

98+
bool took_too_long = false;
99+
parse_timeout_id = Timeout.add_full (Priority.LOW, PARSE_TIME_MAX_MSEC, () => {
100+
parse_timeout_id = 0;
101+
took_too_long = true;
102+
cancellable.cancel ();
103+
return Source.REMOVE;
104+
});
105+
95106
var new_root = construct_tree (cancellable);
96-
if (!cancellable.is_cancelled ()) {
107+
if (parse_timeout_id > 0) {
108+
Source.remove (parse_timeout_id);
109+
}
110+
111+
if (!cancellable.is_cancelled () || took_too_long) {
97112
Idle.add (() => {
98113
double adjustment_value = store.vadjustment.value;
99114
var root_children = store.root.children; // Keep reference to children for later destruction
@@ -102,7 +117,21 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
102117
destroy_all_children ((Code.Widgets.SourceList.ExpandableItem)child);
103118
}
104119

105-
store.root.add (new_root);
120+
if (took_too_long) {
121+
var warning_item = new Code.Widgets.SourceList.Item () {
122+
icon = new ThemedIcon ("dialog-warning"),
123+
markup = "<big>%s</big>".printf (_("Too Many Symbols")),
124+
tooltip = _("%s contains too many Vala symbols.\nParsing and showing them took long").printf (doc.file.get_basename ()),
125+
selectable = false
126+
};
127+
128+
store.root.add (warning_item);
129+
tool_box_sensitive = false;
130+
131+
} else {
132+
store.root.add (new_root);
133+
}
134+
106135
store.root.expand_all ();
107136
store.vadjustment.set_value (adjustment_value);
108137

@@ -111,6 +140,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
111140
} else {
112141
destroy_all_children (new_root);
113142
}
143+
114144
return null;
115145
});
116146
}
@@ -146,6 +176,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
146176

147177
construct_child (symbol, new_root, cancellable);
148178
}
179+
149180
return new_root;
150181
}
151182

0 commit comments

Comments
 (0)