Skip to content

Commit 75e4b0f

Browse files
committed
Close #1908
1 parent b657f37 commit 75e4b0f

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,29 @@ private void Refresh()
212212
name = selection.QualifiedName.Component.Name;
213213
}
214214

215-
Project.RemoveAllComponents();
216-
Project.ImportSourceFiles(CurrentRepository.LocalLocation);
215+
try
216+
{
217+
Project.LoadAllComponents(CurrentRepository.LocalLocation);
218+
}
219+
catch (AggregateException ex)
220+
{
221+
HandleVbeSinkEvents = true;
222+
throw new SourceControlException("Unknown exception.", ex);
223+
}
217224

218225
Project.VBE.SetSelection(selection.QualifiedName.Project, selection.Selection, name, _wrapperFactory);
219226
}
220227
else
221228
{
222-
Project.RemoveAllComponents();
223-
Project.ImportSourceFiles(CurrentRepository.LocalLocation);
229+
try
230+
{
231+
Project.LoadAllComponents(CurrentRepository.LocalLocation);
232+
}
233+
catch (AggregateException ex)
234+
{
235+
HandleVbeSinkEvents = true;
236+
throw new SourceControlException("Unknown exception.", ex);
237+
}
224238
}
225239

226240
HandleVbeSinkEvents = true;

Rubberduck.VBEEditor/Extensions/VbProjectExtensions.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Vbe.Interop;
1+
using System;
2+
using Microsoft.Vbe.Interop;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
@@ -102,5 +103,58 @@ public static void ImportSourceFiles(this VBProject project, string filePath)
102103
project.VBComponents.ImportSourceFile(file.FullName);
103104
}
104105
}
106+
107+
public static void LoadAllComponents(this VBProject project, string filePath)
108+
{
109+
var dirInfo = new DirectoryInfo(filePath);
110+
111+
var files = dirInfo.EnumerateFiles()
112+
.Where(f => f.Extension == VBComponentExtensions.StandardExtension ||
113+
f.Extension == VBComponentExtensions.ClassExtension ||
114+
f.Extension == VBComponentExtensions.DocClassExtension ||
115+
f.Extension == VBComponentExtensions.FormExtension
116+
);
117+
118+
var exceptions = new List<Exception>();
119+
120+
foreach (VBComponent component in project.VBComponents)
121+
{
122+
try
123+
{
124+
var name = component.Name;
125+
project.VBComponents.RemoveSafely(component);
126+
127+
var file = files.SingleOrDefault(f => f.Name == name + f.Extension);
128+
if (file != null)
129+
{
130+
project.VBComponents.ImportSourceFile(file.FullName);
131+
}
132+
}
133+
catch (Exception ex)
134+
{
135+
exceptions.Add(ex);
136+
}
137+
}
138+
139+
foreach (var file in files)
140+
{
141+
try
142+
{
143+
if (project.VBComponents.OfType<VBComponent>().All(v => v.Name + file.Extension != file.Name))
144+
{
145+
project.VBComponents.ImportSourceFile(file.FullName);
146+
}
147+
}
148+
catch (Exception ex)
149+
{
150+
exceptions.Add(ex);
151+
}
152+
}
153+
154+
if (exceptions.Count != 0)
155+
{
156+
throw new AggregateException(string.Empty, exceptions);
157+
}
158+
}
105159
}
106160
}

0 commit comments

Comments
 (0)