Skip to content

Commit 709e96d

Browse files
committed
Prevent recreating the list built-in declarations each time a reference is added. Make loading declarations from type libraries asynchronous.
1 parent c7fd2e5 commit 709e96d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public class RubberduckParser : IRubberduckParser
2929
private readonly IDictionary<VBComponent, IDictionary<Tuple<string, DeclarationType>, Attributes>> _componentAttributes
3030
= new Dictionary<VBComponent, IDictionary<Tuple<string, DeclarationType>, Attributes>>();
3131

32-
private readonly ReferencedDeclarationsCollector _comReflector;
33-
3432
private readonly VBE _vbe;
3533
private readonly RubberduckParserState _state;
3634
private readonly IAttributeParser _attributeParser;
@@ -52,8 +50,6 @@ public RubberduckParser(
5250
_preprocessorFactory = preprocessorFactory;
5351
_customDeclarationLoaders = customDeclarationLoaders;
5452

55-
_comReflector = new ReferencedDeclarationsCollector(_state);
56-
5753
state.ParseRequest += ReparseRequested;
5854
}
5955

@@ -69,6 +65,14 @@ private void ReparseRequested(object sender, ParseRequestEventArgs e)
6965
Cancel(e.Component);
7066
Task.Run(() =>
7167
{
68+
SyncComReferences(_state.Projects);
69+
AddBuiltInDeclarations();
70+
71+
if (_resolverTokenSource.IsCancellationRequested || _central.IsCancellationRequested)
72+
{
73+
return;
74+
}
75+
7276
ParseAsync(e.Component, CancellationToken.None).Wait();
7377

7478
if (_resolverTokenSource.IsCancellationRequested || _central.IsCancellationRequested)
@@ -388,11 +392,17 @@ private void SyncComReferences(IReadOnlyList<VBProject> projects)
388392
if (!map.IsLoaded)
389393
{
390394
_state.OnStatusMessageUpdate(ParserState.LoadingReference.ToString());
391-
var items = _comReflector.GetDeclarationsForReference(reference);
392-
foreach (var declaration in items)
395+
396+
Task.Run(() =>
393397
{
394-
_state.AddDeclaration(declaration);
395-
}
398+
var comReflector = new ReferencedDeclarationsCollector(_state);
399+
var items = comReflector.GetDeclarationsForReference(reference);
400+
401+
foreach (var declaration in items)
402+
{
403+
_state.AddDeclaration(declaration);
404+
}
405+
});
396406
map.IsLoaded = true;
397407
}
398408
}

0 commit comments

Comments
 (0)