1717 */
1818
1919public 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