Skip to content

Commit 48d5ada

Browse files
committed
needs further stabilizing. COM references don't load because a full initial parse isn't happening yet.
1 parent a970e19 commit 48d5ada

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,7 @@ private void ParseAll()
148148
.ToList();
149149

150150
var components = projects.SelectMany(p => p.VBComponents.Cast<VBComponent>()).ToList();
151-
foreach (var component in components)
152-
{
153-
_state.SetModuleState(component, ParserState.LoadingReference);
154-
}
155-
156-
if (!_state.AllDeclarations.Any(item => item.IsBuiltIn))
157-
{
158-
var references = projects.SelectMany(p => p.References.Cast<Reference>()).ToList();
159-
foreach (var reference in references)
160-
{
161-
var items = _comReflector.GetDeclarationsForReference(reference).ToList();
162-
foreach (var declaration in items)
163-
{
164-
_state.AddDeclaration(declaration);
165-
}
166-
}
167-
}
151+
LoadComReferences(components, projects);
168152

169153
foreach (var component in components)
170154
{
@@ -185,18 +169,31 @@ private void ParseAll()
185169
}
186170
}
187171

172+
private void LoadComReferences(IEnumerable<VBComponent> components, IEnumerable<VBProject> projects)
173+
{
174+
foreach (var component in components)
175+
{
176+
_state.SetModuleState(component, ParserState.LoadingReference);
177+
}
178+
179+
if (!_state.AllDeclarations.Any(item => item.IsBuiltIn))
180+
{
181+
var references = projects.SelectMany(p => p.References.Cast<Reference>()).ToList();
182+
foreach (var reference in references)
183+
{
184+
var items = _comReflector.GetDeclarationsForReference(reference).ToList();
185+
foreach (var declaration in items)
186+
{
187+
_state.AddDeclaration(declaration);
188+
}
189+
}
190+
}
191+
}
192+
188193
public Task ParseAsync(VBComponent component, CancellationToken token, TokenStreamRewriter rewriter = null)
189194
{
190-
// Remove invalidated "things" from _state
191-
// this includes: Declarations, Comments, Attributes, Exceptions, ParseTree and TokenStream
192-
// how that works with the Inspecion results is not quite clear
193-
_state.ClearDeclarations(component);
194-
_state.AddParseTree(component, null);
195-
_state.AddTokenStream(component, null);
196-
195+
_state.ClearDeclarations(component);
197196
_state.SetModuleState(component, ParserState.Pending); // also clears module-exceptions
198-
_state.SetModuleComments(component, Enumerable.Empty<CommentNode>());
199-
_state.SetModuleAttributes(component, new Dictionary<Tuple<string, DeclarationType>, Attributes>());
200197

201198
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_central.Token, token);
202199

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ public void ClearBuiltInReferences()
307307

308308
public bool ClearDeclarations(VBComponent component)
309309
{
310-
var projectName = component.Collection.Parent.ProjectName();
311-
var keys = _declarations.Keys.Where(kvp =>
312-
kvp.ProjectName == projectName && kvp.ComponentName == component.Name);
310+
var match = new QualifiedModuleName(component);
311+
var keys = _declarations.Keys.Where(kvp => kvp.Equals(match));
313312

314313
var success = true;
315314
var declarationsRemoved = 0;

0 commit comments

Comments
 (0)