Skip to content

Commit 7484c9e

Browse files
authored
Merge pull request #1909 from Hosch250/COMCollectorBugs
Prevent crash when renaming the main project component
2 parents 91d2bb8 + 5ec672d commit 7484c9e

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

RetailCoder.VBE/App.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,47 @@ async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBCom
337337
_sourceControlPanelVM.HandleRenamedComponent(e.Item, e.OldName);
338338

339339
_logger.Debug("Component '{0}' was renamed to '{1}'.", e.OldName, e.Item.Name);
340+
341+
var projectId = e.Item.Collection.Parent.HelpFile;
342+
var componentDeclaration = _parser.State.AllDeclarations.FirstOrDefault(f =>
343+
f.ProjectId == projectId &&
344+
f.DeclarationType == DeclarationType.ClassModule &&
345+
f.IdentifierName == e.OldName);
346+
347+
if (e.Item.Type == vbext_ComponentType.vbext_ct_Document &&
348+
componentDeclaration != null &&
349+
350+
// according to ThunderFrame, Excel is the only one we explicitly support
351+
// with two Document-component types just skip the Worksheet component
352+
((ClassModuleDeclaration) componentDeclaration).Supertypes.All(a => a.IdentifierName != "Worksheet"))
353+
{
354+
_componentsEventsSinks.Remove(projectId);
355+
_referencesEventsSinks.Remove(projectId);
356+
_parser.State.RemoveProject(projectId);
357+
358+
_logger.Debug("Project '{0}' was removed.", e.Item.Name);
359+
Tuple<IConnectionPoint, int> componentsTuple;
360+
if (_componentsEventsConnectionPoints.TryGetValue(projectId, out componentsTuple))
361+
{
362+
componentsTuple.Item1.Unadvise(componentsTuple.Item2);
363+
_componentsEventsConnectionPoints.Remove(projectId);
364+
}
365+
366+
Tuple<IConnectionPoint, int> referencesTuple;
367+
if (_referencesEventsConnectionPoints.TryGetValue(projectId, out referencesTuple))
368+
{
369+
referencesTuple.Item1.Unadvise(referencesTuple.Item2);
370+
_referencesEventsConnectionPoints.Remove(projectId);
371+
}
340372

341-
_parser.State.RemoveRenamedComponent(e.Item, e.OldName);
373+
_parser.State.AddProject(e.Item.Collection.Parent);
374+
}
375+
else
376+
{
377+
_parser.State.RemoveRenamedComponent(e.Item, e.OldName);
378+
}
379+
380+
_parser.State.OnParseRequested(this);
342381
}
343382

344383
async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent> e)

RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ private void Rename()
199199
if (ModuleDeclarationTypes.Contains(_model.Target.DeclarationType))
200200
{
201201
RenameModule();
202+
return; // renaming a component automatically triggers a reparse
202203
}
203204
else if (_model.Target.DeclarationType == DeclarationType.Project)
204205
{

0 commit comments

Comments
 (0)