Skip to content

Commit 87c28e9

Browse files
authored
Merge branch 'next' into parserCancellationBug
2 parents d85543b + a904f35 commit 87c28e9

File tree

3 files changed

+73
-167
lines changed

3 files changed

+73
-167
lines changed

RetailCoder.VBE/App.cs

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -155,168 +155,6 @@ public void Shutdown()
155155
}
156156
}
157157

158-
/*#region sink handlers.
159-
async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
160-
{
161-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
162-
163-
if (e.Item.Protection == vbext_ProjectProtection.vbext_pp_locked)
164-
{
165-
Logger.Debug("Locked project '{0}' was removed.", e.Item.Name);
166-
return;
167-
}
168-
169-
_parser.Cancel();
170-
171-
var projectId = e.Item.HelpFile;
172-
Debug.Assert(projectId != null);
173-
174-
_parser.State.RemoveProject(e.Item);
175-
_parser.State.OnParseRequested(this);
176-
}
177-
178-
async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
179-
{
180-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
181-
182-
Logger.Debug("Project '{0}' was added.", e.Item.Name);
183-
if (e.Item.Protection == vbext_ProjectProtection.vbext_pp_locked)
184-
{
185-
Logger.Debug("Project is protected and will not be added to parser state.");
186-
return;
187-
}
188-
189-
_parser.State.AddProject(e.Item); // note side-effect: assigns ProjectId/HelpFile
190-
var projectId = e.Item.HelpFile;
191-
RegisterComponentsEventSink(e.Item.VBComponents, projectId);
192-
193-
if (!_parser.State.AllDeclarations.Any())
194-
{
195-
// forces menus to evaluate their CanExecute state:
196-
Parser_StateChanged(this, new ParserStateEventArgs(ParserState.Pending));
197-
_stateBar.SetStatusText();
198-
return;
199-
}
200-
201-
_parser.State.OnParseRequested(sender);
202-
}
203-
204-
async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
205-
{
206-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
207-
208-
if (!_parser.State.AllDeclarations.Any())
209-
{
210-
return;
211-
}
212-
}
213-
214-
async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBComponent> e)
215-
{
216-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
217-
218-
if (!_parser.State.AllDeclarations.Any())
219-
{
220-
return;
221-
}
222-
223-
_parser.Cancel();
224-
225-
_sourceControlPanelVM.HandleRenamedComponent(e.Item, e.OldName);
226-
227-
Logger.Debug("Component '{0}' was renamed to '{1}'.", e.OldName, e.Item.Name);
228-
229-
var projectId = e.Item.Collection.Parent.HelpFile;
230-
var componentDeclaration = _parser.State.AllDeclarations.FirstOrDefault(f =>
231-
f.ProjectId == projectId &&
232-
f.DeclarationType == DeclarationType.ClassModule &&
233-
f.IdentifierName == e.OldName);
234-
235-
if (e.Item.Type == vbext_ComponentType.vbext_ct_Document &&
236-
componentDeclaration != null &&
237-
238-
// according to ThunderFrame, Excel is the only one we explicitly support
239-
// with two Document-component types just skip the Worksheet component
240-
((ClassModuleDeclaration) componentDeclaration).Supertypes.All(a => a.IdentifierName != "Worksheet"))
241-
{
242-
_parser.State.RemoveProject(projectId);
243-
244-
_parser.State.AddProject(e.Item.Collection.Parent);
245-
}
246-
else
247-
{
248-
_parser.State.RemoveRenamedComponent(e.Item, e.OldName);
249-
}
250-
251-
_parser.State.OnParseRequested(this);
252-
}
253-
254-
async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent> e)
255-
{
256-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
257-
258-
if (!_parser.State.AllDeclarations.Any())
259-
{
260-
return;
261-
}
262-
263-
_parser.Cancel(e.Item);
264-
265-
_sourceControlPanelVM.HandleRemovedComponent(e.Item);
266-
267-
Logger.Debug("Component '{0}' was removed.", e.Item.Name);
268-
_parser.State.ClearStateCache(e.Item, true);
269-
}
270-
271-
async void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent> e)
272-
{
273-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
274-
275-
if (!_parser.State.AllDeclarations.Any())
276-
{
277-
return;
278-
}
279-
280-
_parser.Cancel(e.Item);
281-
282-
_parser.State.OnParseRequested(sender, e.Item);
283-
}
284-
285-
async void sink_ComponentAdded(object sender, DispatcherEventArgs<VBComponent> e)
286-
{
287-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
288-
289-
if (!_parser.State.AllDeclarations.Any())
290-
{
291-
return;
292-
}
293-
294-
_sourceControlPanelVM.HandleAddedComponent(e.Item);
295-
296-
Logger.Debug("Component '{0}' was added.", e.Item.Name);
297-
_parser.State.OnParseRequested(sender, e.Item);
298-
}
299-
300-
async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProject> e)
301-
{
302-
if (!_handleSinkEvents || !_vbe.IsInDesignMode()) { return; }
303-
304-
if (!_parser.State.AllDeclarations.Any())
305-
{
306-
return;
307-
}
308-
309-
_parser.Cancel();
310-
311-
Logger.Debug("Project '{0}' (ID {1}) was renamed to '{2}'.", e.OldName, e.Item.HelpFile, e.Item.Name);
312-
313-
_parser.State.RemoveProject(e.Item.HelpFile);
314-
_parser.State.AddProject(e.Item);
315-
316-
_parser.State.OnParseRequested(sender);
317-
}
318-
#endregion*/
319-
320158
private void _stateBar_Refresh(object sender, EventArgs e)
321159
{
322160
// handles "refresh" button click on "Rubberduck" command bar

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)