@@ -28,6 +28,7 @@ public class ParseCoordinator : IParseCoordinator
28
28
public RubberduckParserState State { get { return _state ; } }
29
29
30
30
private const int _maxDegreeOfParserParallelism = - 1 ;
31
+ private const int _maxDegreeOfModuleStateChangeParallelism = - 1 ;
31
32
32
33
private readonly IDictionary < IVBComponent , IDictionary < Tuple < string , DeclarationType > , Attributes > > _componentAttributes
33
34
= new Dictionary < IVBComponent , IDictionary < Tuple < string , DeclarationType > , Attributes > > ( ) ;
@@ -163,10 +164,12 @@ private void RefreshDeclarationFinder()
163
164
164
165
private void SetModuleStates ( List < IVBComponent > components , ParserState parserState )
165
166
{
166
- foreach ( var component in components )
167
- {
168
- State . SetModuleState ( component , parserState ) ;
169
- }
167
+ var options = new ParallelOptions ( ) ;
168
+ options . MaxDegreeOfParallelism = _maxDegreeOfModuleStateChangeParallelism ;
169
+
170
+ Parallel . ForEach ( components , options , component => State . SetModuleState ( component , parserState , null , false ) ) ;
171
+
172
+ State . EvaluateParserState ( ) ;
170
173
}
171
174
172
175
private void CleanUpComponentAttributes ( List < IVBComponent > components )
@@ -190,6 +193,8 @@ private void ClearComponentStateCacheForTests()
190
193
191
194
private void ParseComponents ( List < IVBComponent > components , CancellationToken token )
192
195
{
196
+ SetModuleStates ( components , ParserState . Parsing ) ;
197
+
193
198
var options = new ParallelOptions ( ) ;
194
199
options . CancellationToken = token ;
195
200
options . MaxDegreeOfParallelism = _maxDegreeOfParserParallelism ;
@@ -198,12 +203,12 @@ private void ParseComponents(List<IVBComponent> components, CancellationToken to
198
203
options ,
199
204
component =>
200
205
{
201
- State . SetModuleState ( component , ParserState . Parsing ) ;
202
206
State . ClearStateCache ( component ) ;
203
207
var finishedParseTask = FinishedParseComponentTask ( component , token ) ;
204
208
ProcessComponentParseResults ( component , finishedParseTask ) ;
205
209
}
206
210
) ;
211
+ State . EvaluateParserState ( ) ;
207
212
}
208
213
209
214
private Task < ComponentParseTask . ParseCompletionArgs > FinishedParseComponentTask ( IVBComponent component , CancellationToken token , TokenStreamRewriter rewriter = null )
@@ -233,6 +238,7 @@ private void ProcessComponentParseResults(IVBComponent component, Task<Component
233
238
finishedParseTask . Wait ( ) ;
234
239
if ( finishedParseTask . IsFaulted )
235
240
{
241
+ //In contrast to the situation in the success scenario, the overall parser state is reevaluated immediately.
236
242
State . SetModuleState ( component , ParserState . Error , finishedParseTask . Exception . InnerException as SyntaxErrorException ) ;
237
243
}
238
244
else if ( finishedParseTask . IsCompleted )
@@ -249,7 +255,9 @@ private void ProcessComponentParseResults(IVBComponent component, Task<Component
249
255
State . SetModuleAnnotations ( component , result . Annotations ) ;
250
256
251
257
// This really needs to go last
252
- State . SetModuleState ( component , ParserState . Parsed ) ;
258
+ //It does not reevaluate the overall parer state to avoid concurrent evaluation of all module states and for performance reasons.
259
+ //The evaluation has to be triggered manually in the calling procedure.
260
+ State . SetModuleState ( component , ParserState . Parsed , null , false ) ;
253
261
}
254
262
}
255
263
}
@@ -258,6 +266,8 @@ private void ProcessComponentParseResults(IVBComponent component, Task<Component
258
266
259
267
private void ResolveAllDeclarations ( List < IVBComponent > components , CancellationToken token )
260
268
{
269
+ SetModuleStates ( components , ParserState . ResolvingDeclarations ) ;
270
+
261
271
var options = new ParallelOptions ( ) ;
262
272
options . CancellationToken = token ;
263
273
options . MaxDegreeOfParallelism = _maxDegreeOfParserParallelism ;
@@ -267,7 +277,6 @@ private void ResolveAllDeclarations(List<IVBComponent> components, CancellationT
267
277
component =>
268
278
{
269
279
var qualifiedName = new QualifiedModuleName ( component ) ;
270
- State . SetModuleState ( component , ParserState . ResolvingDeclarations ) ;
271
280
ResolveDeclarations ( qualifiedName . Component ,
272
281
State . ParseTrees . Find ( s => s . Key == qualifiedName ) . Value ) ;
273
282
}
0 commit comments