Skip to content

Commit 33ca3c0

Browse files
committed
Put the resolver back on the parser state event to make the tests pass
1 parent 9bea200 commit 33ca3c0

File tree

1 file changed

+28
-43
lines changed

1 file changed

+28
-43
lines changed

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ namespace Rubberduck.Parsing.VBA
2323
{
2424
public class RubberduckParser : IRubberduckParser, IDisposable
2525
{
26-
public RubberduckParserState State { get { return _state; } }
26+
public RubberduckParserState State
27+
{
28+
get
29+
{
30+
return _state;
31+
}
32+
}
2733

2834
private CancellationTokenSource _central = new CancellationTokenSource();
2935
private CancellationTokenSource _resolverTokenSource; // linked to _central later
@@ -39,11 +45,11 @@ private readonly IDictionary<VBComponent, IDictionary<Tuple<string, DeclarationT
3945
private readonly VBE _vbe;
4046
private readonly RubberduckParserState _state;
4147
private readonly IAttributeParser _attributeParser;
42-
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
4348
private readonly Func<IVBAPreprocessor> _preprocessorFactory;
49+
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
4450

4551
public RubberduckParser(
46-
VBE vbe,
52+
VBE vbe,
4753
RubberduckParserState state,
4854
IAttributeParser attributeParser,
4955
Func<IVBAPreprocessor> preprocessorFactory)
@@ -62,13 +68,13 @@ public RubberduckParser(
6268

6369
private void StateOnStateChanged(object sender, EventArgs e)
6470
{
65-
Logger.Debug("RubberduckParser handles OnStateChanged ({0})", _state.Status);
71+
_logger.Debug("RubberduckParser handles OnStateChanged ({0})", _state.Status);
6672

67-
/*if (_state.Status == ParserState.Parsed)
73+
if (_state.Status == ParserState.Parsed)
6874
{
69-
Logger.Debug("(handling OnStateChanged) Starting resolver task");
75+
_logger.Debug("(handling OnStateChanged) Starting resolver task");
7076
Resolve(_central.Token); // Tests expect this to be synchronous
71-
}*/
77+
}
7278
}
7379

7480
private void ReparseRequested(object sender, ParseRequestEventArgs e)
@@ -81,10 +87,7 @@ private void ReparseRequested(object sender, ParseRequestEventArgs e)
8187
else
8288
{
8389
Cancel(e.Component);
84-
ParseAsync(e.Component, CancellationToken.None).Wait();
85-
86-
Logger.Trace("Starting resolver task");
87-
Resolve(_central.Token); // Tests expect this to be synchronous
90+
ParseAsync(e.Component, CancellationToken.None);
8891
}
8992
}
9093

@@ -140,14 +143,6 @@ private void ParseAll()
140143
var toParse = components.Where(c => _state.IsNewOrModified(c)).ToList();
141144
var unchanged = components.Where(c => !_state.IsNewOrModified(c)).ToList();
142145

143-
File.AppendAllLines("C:/Users/hosch/Desktop/debug.txt", new[]
144-
{
145-
"Projects: " + projects.Count,
146-
"Components: " + components.Count,
147-
"ToParse: " + toParse.Count,
148-
"Unchanged: " + unchanged.Count
149-
});
150-
151146
AddBuiltInDeclarations(projects);
152147

153148
if (!toParse.Any())
@@ -179,11 +174,10 @@ private void ParseAll()
179174
_componentAttributes.Remove(invalidated);
180175
}
181176

182-
var parseTasks = toParse.Select(vbComponent => ParseAsync(vbComponent, CancellationToken.None)).ToArray();
183-
Task.WaitAll(parseTasks);
184-
185-
Logger.Trace("Starting resolver task");
186-
Resolve(_central.Token); // Tests expect this to be synchronous
177+
foreach (var vbComponent in toParse)
178+
{
179+
ParseAsync(vbComponent, CancellationToken.None);
180+
}
187181
}
188182

189183
private void AddBuiltInDeclarations(IReadOnlyList<VBProject> projects)
@@ -491,20 +485,16 @@ private void ResolveInternal(CancellationToken token)
491485
var components = _state.Projects
492486
.Where(project => project.Protection == vbext_ProjectProtection.vbext_pp_none)
493487
.SelectMany(p => p.VBComponents.Cast<VBComponent>()).ToList();
494-
495-
File.AppendAllLines("C:/Users/hosch/Desktop/debug.txt", new[]
488+
if (!_state.HasAllParseTrees(components))
496489
{
497-
"Parse tree count: " + _state.ParseTrees.Count()
498-
});
499-
500-
Debug.Assert(_state.HasAllParseTrees(components), string.Format("Expected parse trees: {0}\r\nParse trees: {1}", components.Count, _state.ParseTrees.Count()));
501-
490+
return;
491+
}
502492
_projectDeclarations.Clear();
503493
_state.ClearBuiltInReferences();
504494
foreach (var kvp in _state.ParseTrees)
505495
{
506496
var qualifiedName = kvp.Key;
507-
Logger.Debug("Module '{0}' {1}", qualifiedName.ComponentName, _state.IsNewOrModified(qualifiedName) ? "was modified" : "was NOT modified");
497+
_logger.Debug("Module '{0}' {1}", qualifiedName.ComponentName, _state.IsNewOrModified(qualifiedName) ? "was modified" : "was NOT modified");
508498
// modified module; walk parse tree and re-acquire all declarations
509499
if (token.IsCancellationRequested) return;
510500
ResolveDeclarations(qualifiedName.Component, kvp.Value);
@@ -548,12 +538,7 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
548538
_state.AddDeclaration(projectDeclaration);
549539
}
550540
}
551-
var declarationsListener = new DeclarationSymbolsListener(qualifiedModuleName, Accessibility.Implicit, component.Type, _state.GetModuleComments(component), _state.GetModuleAnnotations(component), _state.GetModuleAttributes(component), _projectReferences, projectDeclaration);
552-
// TODO: should we unify the API? consider working like the other listeners instead of event-based
553-
declarationsListener.NewDeclaration += (sender, e) => _state.AddDeclaration(e.Declaration);
554-
declarationsListener.CreateModuleDeclarations();
555-
556-
Logger.Debug("Walking parse tree for '{0}'... (acquiring declarations)", qualifiedModuleName.Name);
541+
_logger.Debug("Creating declarations for module {0}.", qualifiedModuleName.Name);
557542
var declarationsListener = new DeclarationSymbolsListener(qualifiedModuleName, component.Type, _state.GetModuleComments(component), _state.GetModuleAnnotations(component), _state.GetModuleAttributes(component), _projectReferences, projectDeclaration);
558543
ParseTreeWalker.Default.Walk(declarationsListener, tree);
559544
foreach (var createdDeclaration in declarationsListener.CreatedDeclarations)
@@ -563,7 +548,7 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
563548
}
564549
catch (Exception exception)
565550
{
566-
Logger.Error(exception, "Exception thrown acquiring declarations for '{0}' (thread {1}).", component.Name, Thread.CurrentThread.ManagedThreadId);
551+
_logger.Error(exception, "Exception thrown acquiring declarations for '{0}' (thread {1}).", component.Name, Thread.CurrentThread.ManagedThreadId);
567552
lock (_state)
568553
{
569554
_state.SetModuleState(component, ParserState.ResolverError);
@@ -593,7 +578,7 @@ private void ResolveReferences(DeclarationFinder finder, VBComponent component,
593578
return;
594579
}
595580
var qualifiedName = new QualifiedModuleName(component);
596-
Logger.Debug("Resolving identifier references in '{0}'... (thread {1})", qualifiedName.Name, Thread.CurrentThread.ManagedThreadId);
581+
_logger.Debug("Resolving identifier references in '{0}'... (thread {1})", qualifiedName.Name, Thread.CurrentThread.ManagedThreadId);
597582
var resolver = new IdentifierReferenceResolver(qualifiedName, finder);
598583
var listener = new IdentifierReferenceListener(resolver);
599584
if (!string.IsNullOrWhiteSpace(tree.GetText().Trim()))
@@ -604,19 +589,19 @@ private void ResolveReferences(DeclarationFinder finder, VBComponent component,
604589
Stopwatch watch = Stopwatch.StartNew();
605590
walker.Walk(listener, tree);
606591
watch.Stop();
607-
Logger.Debug("Binding Resolution done for component '{0}' in {1}ms (thread {2})", component.Name, watch.ElapsedMilliseconds, Thread.CurrentThread.ManagedThreadId);
592+
_logger.Debug("Binding Resolution done for component '{0}' in {1}ms (thread {2})", component.Name, watch.ElapsedMilliseconds, Thread.CurrentThread.ManagedThreadId);
608593
_state.RebuildSelectionCache();
609594
state = ParserState.Ready;
610595
}
611596
catch (Exception exception)
612597
{
613-
Logger.Error(exception, "Exception thrown resolving '{0}' (thread {1}).", component.Name, Thread.CurrentThread.ManagedThreadId);
598+
_logger.Error(exception, "Exception thrown resolving '{0}' (thread {1}).", component.Name, Thread.CurrentThread.ManagedThreadId);
614599
state = ParserState.ResolverError;
615600
}
616601
}
617602

618603
_state.SetModuleState(component, state);
619-
Logger.Debug("'{0}' is {1} (thread {2})", component.Name, _state.GetModuleState(component), Thread.CurrentThread.ManagedThreadId);
604+
_logger.Debug("'{0}' is {1} (thread {2})", component.Name, _state.GetModuleState(component), Thread.CurrentThread.ManagedThreadId);
620605
}
621606

622607
public void Dispose()

0 commit comments

Comments
 (0)