9
9
using Antlr4 . Runtime . Tree ;
10
10
using Rubberduck . Parsing . Symbols ;
11
11
using Rubberduck . VBEditor ;
12
- using System . Globalization ;
13
12
using Rubberduck . Parsing . Preprocessing ;
14
13
using System . Diagnostics ;
15
14
using Rubberduck . Parsing . Annotations ;
@@ -23,13 +22,7 @@ namespace Rubberduck.Parsing.VBA
23
22
{
24
23
public class RubberduckParser : IRubberduckParser , IDisposable
25
24
{
26
- public RubberduckParserState State
27
- {
28
- get
29
- {
30
- return _state ;
31
- }
32
- }
25
+ public RubberduckParserState State { get { return _state ; } }
33
26
34
27
private CancellationTokenSource _central = new CancellationTokenSource ( ) ;
35
28
private CancellationTokenSource _resolverTokenSource ; // linked to _central later
@@ -46,7 +39,7 @@ private readonly IDictionary<VBComponent, IDictionary<Tuple<string, DeclarationT
46
39
private readonly RubberduckParserState _state ;
47
40
private readonly IAttributeParser _attributeParser ;
48
41
private readonly Func < IVBAPreprocessor > _preprocessorFactory ;
49
- private static readonly Logger _logger = LogManager . GetCurrentClassLogger ( ) ;
42
+ private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
50
43
51
44
public RubberduckParser (
52
45
VBE vbe ,
@@ -68,13 +61,13 @@ public RubberduckParser(
68
61
69
62
private void StateOnStateChanged ( object sender , EventArgs e )
70
63
{
71
- _logger . Debug ( "RubberduckParser handles OnStateChanged ({0})" , _state . Status ) ;
64
+ Logger . Debug ( "RubberduckParser handles OnStateChanged ({0})" , _state . Status ) ;
72
65
73
- if ( _state . Status == ParserState . Parsed )
66
+ /* if (_state.Status == ParserState.Parsed)
74
67
{
75
68
_logger.Debug("(handling OnStateChanged) Starting resolver task");
76
69
Resolve(_central.Token); // Tests expect this to be synchronous
77
- }
70
+ }*/
78
71
}
79
72
80
73
private void ReparseRequested ( object sender , ParseRequestEventArgs e )
@@ -87,7 +80,10 @@ private void ReparseRequested(object sender, ParseRequestEventArgs e)
87
80
else
88
81
{
89
82
Cancel ( e . Component ) ;
90
- ParseAsync ( e . Component , CancellationToken . None ) ;
83
+ ParseAsync ( e . Component , CancellationToken . None ) . Wait ( ) ;
84
+
85
+ Logger . Trace ( "Starting resolver task" ) ;
86
+ Resolve ( _central . Token ) ; // Tests expect this to be synchronous
91
87
}
92
88
}
93
89
@@ -117,11 +113,17 @@ public void Parse()
117
113
_componentAttributes . Remove ( invalidated ) ;
118
114
}
119
115
120
- foreach ( var vbComponent in components )
116
+ /* foreach (var vbComponent in components)
121
117
{
122
118
_state.ClearStateCache(vbComponent);
123
119
ParseComponent(vbComponent);
124
- }
120
+ }*/
121
+
122
+ var parseTasks = components . Select ( vbComponent => ParseAsync ( vbComponent , CancellationToken . None ) ) . ToArray ( ) ;
123
+ Task . WaitAll ( parseTasks ) ;
124
+
125
+ Logger . Trace ( "Starting resolver task" ) ;
126
+ Resolve ( _central . Token ) ; // Tests expect this to be synchronous
125
127
}
126
128
127
129
/// <summary>
@@ -174,10 +176,11 @@ private void ParseAll()
174
176
_componentAttributes . Remove ( invalidated ) ;
175
177
}
176
178
177
- foreach ( var vbComponent in toParse )
178
- {
179
- ParseAsync ( vbComponent , CancellationToken . None ) ;
180
- }
179
+ var parseTasks = toParse . Select ( vbComponent => ParseAsync ( vbComponent , CancellationToken . None ) ) . ToArray ( ) ;
180
+ Task . WaitAll ( parseTasks ) ;
181
+
182
+ Logger . Trace ( "Starting resolver task" ) ;
183
+ Resolve ( _central . Token ) ; // Tests expect this to be synchronous
181
184
}
182
185
183
186
private void AddBuiltInDeclarations ( IReadOnlyList < VBProject > projects )
@@ -467,11 +470,6 @@ private void ParseAsyncInternal(VBComponent component, CancellationToken token,
467
470
parser . Start ( token ) ;
468
471
}
469
472
470
- private void ParseComponent ( VBComponent component , TokenStreamRewriter rewriter = null )
471
- {
472
- ParseAsync ( component , CancellationToken . None , rewriter ) . Wait ( ) ;
473
- }
474
-
475
473
private void Resolve ( CancellationToken token )
476
474
{
477
475
var sharedTokenSource = CancellationTokenSource . CreateLinkedTokenSource ( _resolverTokenSource . Token , token ) ;
@@ -494,7 +492,7 @@ private void ResolveInternal(CancellationToken token)
494
492
foreach ( var kvp in _state . ParseTrees )
495
493
{
496
494
var qualifiedName = kvp . Key ;
497
- _logger . Debug ( "Module '{0}' {1}" , qualifiedName . ComponentName , _state . IsNewOrModified ( qualifiedName ) ? "was modified" : "was NOT modified" ) ;
495
+ Logger . Debug ( "Module '{0}' {1}" , qualifiedName . ComponentName , _state . IsNewOrModified ( qualifiedName ) ? "was modified" : "was NOT modified" ) ;
498
496
// modified module; walk parse tree and re-acquire all declarations
499
497
if ( token . IsCancellationRequested ) return ;
500
498
ResolveDeclarations ( qualifiedName . Component , kvp . Value ) ;
@@ -538,7 +536,7 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
538
536
_state . AddDeclaration ( projectDeclaration ) ;
539
537
}
540
538
}
541
- _logger . Debug ( "Creating declarations for module {0}." , qualifiedModuleName . Name ) ;
539
+ Logger . Debug ( "Creating declarations for module {0}." , qualifiedModuleName . Name ) ;
542
540
var declarationsListener = new DeclarationSymbolsListener ( qualifiedModuleName , component . Type , _state . GetModuleComments ( component ) , _state . GetModuleAnnotations ( component ) , _state . GetModuleAttributes ( component ) , _projectReferences , projectDeclaration ) ;
543
541
ParseTreeWalker . Default . Walk ( declarationsListener , tree ) ;
544
542
foreach ( var createdDeclaration in declarationsListener . CreatedDeclarations )
@@ -548,7 +546,7 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
548
546
}
549
547
catch ( Exception exception )
550
548
{
551
- _logger . Error ( exception , "Exception thrown acquiring declarations for '{0}' (thread {1})." , component . Name , Thread . CurrentThread . ManagedThreadId ) ;
549
+ Logger . Error ( exception , "Exception thrown acquiring declarations for '{0}' (thread {1})." , component . Name , Thread . CurrentThread . ManagedThreadId ) ;
552
550
lock ( _state )
553
551
{
554
552
_state . SetModuleState ( component , ParserState . ResolverError ) ;
@@ -578,7 +576,7 @@ private void ResolveReferences(DeclarationFinder finder, VBComponent component,
578
576
return ;
579
577
}
580
578
var qualifiedName = new QualifiedModuleName ( component ) ;
581
- _logger . Debug ( "Resolving identifier references in '{0}'... (thread {1})" , qualifiedName . Name , Thread . CurrentThread . ManagedThreadId ) ;
579
+ Logger . Debug ( "Resolving identifier references in '{0}'... (thread {1})" , qualifiedName . Name , Thread . CurrentThread . ManagedThreadId ) ;
582
580
var resolver = new IdentifierReferenceResolver ( qualifiedName , finder ) ;
583
581
var listener = new IdentifierReferenceListener ( resolver ) ;
584
582
if ( ! string . IsNullOrWhiteSpace ( tree . GetText ( ) . Trim ( ) ) )
@@ -589,19 +587,19 @@ private void ResolveReferences(DeclarationFinder finder, VBComponent component,
589
587
Stopwatch watch = Stopwatch . StartNew ( ) ;
590
588
walker . Walk ( listener , tree ) ;
591
589
watch . Stop ( ) ;
592
- _logger . Debug ( "Binding Resolution done for component '{0}' in {1}ms (thread {2})" , component . Name , watch . ElapsedMilliseconds , Thread . CurrentThread . ManagedThreadId ) ;
590
+ Logger . Debug ( "Binding Resolution done for component '{0}' in {1}ms (thread {2})" , component . Name , watch . ElapsedMilliseconds , Thread . CurrentThread . ManagedThreadId ) ;
593
591
_state . RebuildSelectionCache ( ) ;
594
592
state = ParserState . Ready ;
595
593
}
596
594
catch ( Exception exception )
597
595
{
598
- _logger . Error ( exception , "Exception thrown resolving '{0}' (thread {1})." , component . Name , Thread . CurrentThread . ManagedThreadId ) ;
596
+ Logger . Error ( exception , "Exception thrown resolving '{0}' (thread {1})." , component . Name , Thread . CurrentThread . ManagedThreadId ) ;
599
597
state = ParserState . ResolverError ;
600
598
}
601
599
}
602
600
603
601
_state . SetModuleState ( component , state ) ;
604
- _logger . Debug ( "'{0}' is {1} (thread {2})" , component . Name , _state . GetModuleState ( component ) , Thread . CurrentThread . ManagedThreadId ) ;
602
+ Logger . Debug ( "'{0}' is {1} (thread {2})" , component . Name , _state . GetModuleState ( component ) , Thread . CurrentThread . ManagedThreadId ) ;
605
603
}
606
604
607
605
public void Dispose ( )
0 commit comments