@@ -16,8 +16,11 @@ internal class ASTCache
16
16
{
17
17
public event Action FinishedUpdate ;
18
18
19
- Dictionary < ClassModel , CachedClassModel > cache = new Dictionary < ClassModel , CachedClassModel > ( new ClassModelComparer ( ) ) ;
19
+ Dictionary < ClassModel , CachedClassModel > cache =
20
+ new Dictionary < ClassModel , CachedClassModel > ( new ClassModelComparer ( ) ) ;
21
+
20
22
readonly List < ClassModel > outdatedModels = new List < ClassModel > ( ) ;
23
+
21
24
/// <summary>
22
25
/// A list of ClassModels that extend / implement something that does not exist yet
23
26
/// </summary>
@@ -79,61 +82,67 @@ public void UpdateOutdatedModels()
79
82
{
80
83
var action = new Action ( ( ) =>
81
84
{
82
- var context = ASContext . GetLanguageContext ( PluginBase . CurrentProject . Language ) ;
83
- if ( context == null || context . Classpath == null )
84
- return ;
85
-
86
- List < ClassModel > outdated ;
87
- lock ( outdatedModels )
88
- {
89
- outdated = new List < ClassModel > ( outdatedModels ) ;
90
- outdatedModels . Clear ( ) ;
91
- }
92
-
93
- foreach ( var cls in outdated )
85
+ try
94
86
{
95
- cls . ResolveExtends ( ) ;
87
+ var context = ASContext . GetLanguageContext ( PluginBase . CurrentProject . Language ) ;
88
+ if ( context == null || context . Classpath == null )
89
+ return ;
96
90
97
- lock ( cache )
91
+ List < ClassModel > outdated ;
92
+ lock ( outdatedModels )
98
93
{
99
- //get the old CachedClassModel
100
- var cachedClassModel = GetCachedModel ( cls ) ;
101
- var connectedClasses = cachedClassModel ? . ConnectedClassModels ;
94
+ outdated = new List < ClassModel > ( outdatedModels ) ;
95
+ outdatedModels . Clear ( ) ;
96
+ }
97
+
98
+ foreach ( var cls in outdated )
99
+ {
100
+ cls . ResolveExtends ( ) ;
101
+
102
+ lock ( cache )
103
+ {
104
+ //get the old CachedClassModel
105
+ var cachedClassModel = GetCachedModel ( cls ) ;
106
+ var connectedClasses = cachedClassModel ? . ConnectedClassModels ;
102
107
103
- //remove old cls
104
- Remove ( cls ) ;
108
+ //remove old cls
109
+ Remove ( cls ) ;
105
110
106
- UpdateClass ( cls , cache ) ;
111
+ UpdateClass ( cls , cache ) ;
107
112
108
- //also update all classes / interfaces that are connected to cls
109
- if ( connectedClasses != null )
110
- foreach ( var connection in connectedClasses )
111
- if ( GetCachedModel ( connection ) != null ) //only update existing connections, so a removed class is not reintroduced
112
- UpdateClass ( connection , cache ) ;
113
+ //also update all classes / interfaces that are connected to cls
114
+ if ( connectedClasses != null )
115
+ foreach ( var connection in connectedClasses )
116
+ if ( GetCachedModel ( connection ) != null )
117
+ //only update existing connections, so a removed class is not reintroduced
118
+ UpdateClass ( connection , cache ) ;
119
+ }
113
120
}
114
- }
115
-
116
- var newModels = outdated . Any ( m => GetCachedModel ( m ) == null ) ;
117
- //for new ClassModels, we need to update everything in the list of classes that extend / implement something that does not exist
118
- if ( newModels )
119
- {
120
- HashSet < ClassModel > toUpdate ;
121
- lock ( unfinishedModels )
122
- toUpdate = new HashSet < ClassModel > ( unfinishedModels ) ;
123
121
124
- foreach ( var model in toUpdate )
122
+ var newModels = outdated . Any ( m => GetCachedModel ( m ) == null ) ;
123
+ //for new ClassModels, we need to update everything in the list of classes that extend / implement something that does not exist
124
+ if ( newModels )
125
125
{
126
+ HashSet < ClassModel > toUpdate ;
126
127
lock ( unfinishedModels )
127
- unfinishedModels . Remove ( model ) ; //will be added back by UpdateClass if needed
128
+ toUpdate = new HashSet < ClassModel > ( unfinishedModels ) ;
128
129
129
- lock ( cache )
130
- UpdateClass ( model , cache ) ;
130
+ foreach ( var model in toUpdate )
131
+ {
132
+ lock ( unfinishedModels )
133
+ unfinishedModels . Remove ( model ) ; //will be added back by UpdateClass if needed
134
+
135
+ lock ( cache )
136
+ UpdateClass ( model , cache ) ;
137
+ }
131
138
}
132
- }
133
-
134
- if ( FinishedUpdate != null )
135
- PluginBase . RunAsync ( new MethodInvoker ( FinishedUpdate ) ) ;
136
139
140
+ if ( FinishedUpdate != null )
141
+ PluginBase . RunAsync ( new MethodInvoker ( FinishedUpdate ) ) ;
142
+ }
143
+ catch ( Exception )
144
+ {
145
+ }
137
146
} ) ;
138
147
139
148
action . BeginInvoke ( null , null ) ;
@@ -146,29 +155,36 @@ public void UpdateCompleteCache()
146
155
{
147
156
var action = new Action ( ( ) =>
148
157
{
149
- var context = ASContext . GetLanguageContext ( PluginBase . CurrentProject . Language ) ;
150
- if ( context == null || context . Classpath == null || PathExplorer . IsWorking )
158
+ try
151
159
{
160
+ var context = ASContext . GetLanguageContext ( PluginBase . CurrentProject . Language ) ;
161
+ if ( context == null || context . Classpath == null || PathExplorer . IsWorking )
162
+ {
163
+ if ( FinishedUpdate != null )
164
+ PluginBase . RunAsync ( new MethodInvoker ( FinishedUpdate ) ) ;
165
+ return ;
166
+ }
167
+
168
+ var c = new Dictionary < ClassModel , CachedClassModel > ( cache . Comparer ) ;
169
+
170
+ foreach ( MemberModel memberModel in context . GetAllProjectClasses ( ) )
171
+ {
172
+ if ( PluginBase . MainForm . ClosingEntirely )
173
+ return ; //make sure we leave if the form is closing, so we do not block it
174
+
175
+ var cls = GetClassModel ( memberModel ) ;
176
+ UpdateClass ( cls , c ) ;
177
+ }
178
+
179
+ lock ( cache )
180
+ cache = c ;
181
+
152
182
if ( FinishedUpdate != null )
153
183
PluginBase . RunAsync ( new MethodInvoker ( FinishedUpdate ) ) ;
154
- return ;
155
184
}
156
-
157
- var c = new Dictionary < ClassModel , CachedClassModel > ( cache . Comparer ) ;
158
-
159
- foreach ( MemberModel memberModel in context . GetAllProjectClasses ( ) )
185
+ catch ( Exception )
160
186
{
161
- if ( PluginBase . MainForm . ClosingEntirely )
162
- return ; //make sure we leave if the form is closing, so we do not block it
163
-
164
- var cls = GetClassModel ( memberModel ) ;
165
- UpdateClass ( cls , c ) ;
166
187
}
167
-
168
- lock ( cache )
169
- cache = c ;
170
- if ( FinishedUpdate != null )
171
- PluginBase . RunAsync ( new MethodInvoker ( FinishedUpdate ) ) ;
172
188
} ) ;
173
189
action . BeginInvoke ( null , null ) ;
174
190
}
0 commit comments