Skip to content

Commit 41892a6

Browse files
committed
Fix setting the project ID for the tests
1 parent 83f73c5 commit 41892a6

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,36 +211,47 @@ public void OnStatusMessageUpdate(string message)
211211

212212
public void AddProject(string projectId)
213213
{
214-
VBProject project = null;
214+
var projects = new List<VBProject>();
215215
foreach (VBProject p in _vbe.VBProjects)
216216
{
217-
if (p.HelpFile == projectId)
217+
if (p.HelpFile != null && _projects.Keys.Contains(p.HelpFile))
218218
{
219-
project = p;
219+
continue;
220220
}
221+
222+
projects.Add(p);
221223
}
222224

223-
if (project == null)
225+
if (projects.Count == 0)
224226
{
225227
Logger.Debug("Project was not found and will not be added to parser state.");
226228
return;
227229
}
228230

229-
if (project.Protection == vbext_ProjectProtection.vbext_pp_locked)
230-
{
231-
// adding protected project to parser state is asking for COMExceptions..
232-
Logger.Debug("Project is protected and will not be added to parser state.");
233-
return;
234-
}
235-
236-
if (!_projects.ContainsKey(projectId))
231+
foreach (var project in projects)
237232
{
238-
_projects.Add(projectId, project);
239-
}
233+
if (project.Protection == vbext_ProjectProtection.vbext_pp_locked)
234+
{
235+
// adding protected project to parser state is asking for COMExceptions..
236+
Logger.Debug("Project is protected and will not be added to parser state.");
237+
return;
238+
}
240239

241-
foreach (VBComponent component in project.VBComponents)
242-
{
243-
_moduleStates.TryAdd(new QualifiedModuleName(component), new ModuleState(ParserState.Pending));
240+
if (string.IsNullOrEmpty(project.HelpFile))
241+
{
242+
// assigns the help file and returns the value to reduce COM calls
243+
projectId = project.AssignProjectId();
244+
}
245+
246+
if (!_projects.ContainsKey(projectId))
247+
{
248+
_projects.Add(projectId, project);
249+
}
250+
251+
foreach (VBComponent component in project.VBComponents)
252+
{
253+
_moduleStates.TryAdd(new QualifiedModuleName(component), new ModuleState(ParserState.Pending));
254+
}
244255
}
245256
}
246257

@@ -670,7 +681,7 @@ public void AddDeclaration(Declaration declaration)
670681
}
671682
}
672683

673-
public void ClearStateCache(VBProject project, bool notifyStateChanged = false)
684+
private void ClearStateCache(VBProject project, bool notifyStateChanged = false)
674685
{
675686
try
676687
{

0 commit comments

Comments
 (0)