Skip to content

Commit d25c512

Browse files
Merge pull request #1 from rubberduck-vba/next
update from next
2 parents 4a6db52 + 8db3f69 commit d25c512

File tree

496 files changed

+11017
-64281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

496 files changed

+11017
-64281
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Branch | Description | Build Status |
3535

3636
Rubberduck is a COM add-in for the VBA IDE (VBE).
3737

38-
Copyright (C) 2014-2017 Mathieu Guindon & Christopher McClellan
38+
Copyright (C) 2014-2018 Mathieu Guindon & Christopher McClellan
3939

4040
This program is free software: you can redistribute it and/or modify
4141
it under the terms of the GNU General Public License as published by

RetailCoder.VBE/API/VBA/ParserState.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using Rubberduck.Parsing.VBA;
1111
using Rubberduck.UI.Command.MenuItems;
1212
using Rubberduck.Parsing.Symbols;
13+
using Rubberduck.VBEditor.ComManagement;
14+
using Rubberduck.VBEditor.Events;
1315
using Rubberduck.VBEditor.SafeComWrappers.VBA;
1416

1517
namespace Rubberduck.API.VBA
@@ -64,14 +66,15 @@ public void Initialize(Microsoft.Vbe.Interop.VBE vbe)
6466

6567
_vbe = new VBE(vbe);
6668
var declarationFinderFactory = new ConcurrentlyConstructedDeclarationFinderFactory();
67-
_state = new RubberduckParserState(null, declarationFinderFactory);
69+
var projectRepository = new ProjectsRepository(_vbe);
70+
_state = new RubberduckParserState(null, projectRepository, declarationFinderFactory);
6871
_state.StateChanged += _state_StateChanged;
6972

7073
var exporter = new ModuleExporter();
7174

7275
Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(_vbe.Version, CultureInfo.InvariantCulture));
73-
_attributeParser = new AttributeParser(exporter, preprocessorFactory);
74-
var projectManager = new ProjectManager(_state, _vbe);
76+
_attributeParser = new AttributeParser(exporter, preprocessorFactory, _state.ProjectsProvider);
77+
var projectManager = new RepositoryProjectManager(projectRepository);
7578
var moduleToModuleReferenceManager = new ModuleToModuleReferenceManager();
7679
var parserStateManager = new ParserStateManager(_state);
7780
var referenceRemover = new ReferenceRemover(_state, moduleToModuleReferenceManager);

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public static Declaration FindInterface(this IEnumerable<Declaration> declaratio
573573
{
574574
foreach (var reference in declaration.References)
575575
{
576-
var implementsStmt = ParserRuleContextHelper.GetParent<VBAParser.ImplementsStmtContext>(reference.Context);
576+
var implementsStmt = reference.Context.GetAncestor<VBAParser.ImplementsStmtContext>();
577577

578578
if (implementsStmt == null) { continue; }
579579

RetailCoder.VBE/Extension.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class _Extension : IDTExtensibility2
4242

4343
private IWindsorContainer _container;
4444
private App _app;
45-
private IComSafe _comSafe;
4645
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
4746

4847
public void OnAddInsUpdate(ref Array custom) { }
@@ -52,16 +51,18 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
5251
{
5352
try
5453
{
55-
ComSafeManager.ResetComSafe();
56-
_comSafe = ComSafeManager.GetCurrentComSafe();
57-
5854
if (Application is Microsoft.Vbe.Interop.VBE vbe1)
5955
{
6056
_ide = new VBEditor.SafeComWrappers.VBA.VBE(vbe1);
6157
VBENativeServices.HookEvents(_ide);
6258

6359
var addin = (AddIn)AddInInst;
6460
_addin = new VBEditor.SafeComWrappers.VBA.AddIn(addin) { Object = this };
61+
62+
#if DEBUG
63+
// FOR DEBUGGING/DEVELOPMENT PURPOSES, ALLOW ACCESS TO SOME VBETypeLibsAPI FEATURES FROM VBA
64+
_addin.Object = new Rubberduck.VBEditor.ComManagement.TypeLibsAPI.VBETypeLibsAPI_Object(_ide);
65+
#endif
6566
}
6667
else if (Application is Microsoft.VB6.Interop.VBIDE.VBE vbe2)
6768
{
@@ -265,18 +266,6 @@ private void ShutdownAddIn()
265266
_container.Dispose();
266267
_container = null;
267268
}
268-
269-
if (_comSafe != null)
270-
{
271-
_logger.Log(LogLevel.Trace, "Disposing COM safe...");
272-
_comSafe.Dispose();
273-
_comSafe = null;
274-
_addin = null;
275-
_ide = null;
276-
}
277-
278-
_isInitialized = false;
279-
_logger.Log(LogLevel.Info, "No exceptions were thrown.");
280269
}
281270
catch (Exception e)
282271
{
@@ -286,11 +275,30 @@ private void ShutdownAddIn()
286275
}
287276
finally
288277
{
289-
_logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
290-
currentDomain.AssemblyResolve -= LoadFromSameFolder;
291-
currentDomain.UnhandledException -= HandlAppDomainException;
292-
_logger.Log(LogLevel.Trace, "Done. Main Shutdown completed. Toolwindows follow. Quack!");
293-
_isInitialized = false;
278+
try
279+
{
280+
_logger.Log(LogLevel.Trace, "Disposing COM safe...");
281+
ComSafeManager.DisposeAndResetComSafe();
282+
_addin = null;
283+
_ide = null;
284+
285+
_isInitialized = false;
286+
_logger.Log(LogLevel.Info, "No exceptions were thrown.");
287+
}
288+
catch (Exception e)
289+
{
290+
_logger.Error(e);
291+
_logger.Log(LogLevel.Warn, "Exception disposing the ComSafe has been swallowed.");
292+
//throw; // <<~ uncomment to crash the process
293+
}
294+
finally
295+
{
296+
_logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
297+
currentDomain.AssemblyResolve -= LoadFromSameFolder;
298+
currentDomain.UnhandledException -= HandlAppDomainException;
299+
_logger.Log(LogLevel.Trace, "Done. Main Shutdown completed. Toolwindows follow. Quack!");
300+
_isInitialized = false;
301+
}
294302
}
295303
}
296304
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
using Rubberduck.Parsing.Inspections.Abstract;
3+
4+
namespace Rubberduck.Inspections
5+
{
6+
public interface IInspectionProvider
7+
{
8+
IEnumerable<IInspection> Inspections { get; }
9+
}
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Parsing.Inspections.Abstract;
4+
using Rubberduck.Settings;
5+
6+
namespace Rubberduck.Inspections
7+
{
8+
public class InspectionProvider : IInspectionProvider
9+
{
10+
public InspectionProvider(IEnumerable<IInspection> inspections)
11+
{
12+
var defaultSettings = new DefaultSettings<CodeInspectionSettings>().Default;
13+
var defaultNames = defaultSettings.CodeInspections.Select(x => x.Name);
14+
var defaultInspections = inspections.Where(inspection => defaultNames.Contains(inspection.Name));
15+
16+
foreach (var inspection in defaultInspections)
17+
{
18+
inspection.InspectionType = defaultSettings.CodeInspections.First(setting => setting.Name == inspection.Name).InspectionType;
19+
}
20+
21+
Inspections = inspections;
22+
}
23+
24+
public IEnumerable<IInspection> Inspections { get; }
25+
}
26+
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Rubberduck.VBEditor;
88
using resx = Rubberduck.UI.CodeExplorer.CodeExplorer;
99
using Rubberduck.Parsing.Annotations;
10+
using Rubberduck.VBEditor.ComManagement;
1011
using Rubberduck.VBEditor.SafeComWrappers;
1112

1213
namespace Rubberduck.Navigation.CodeExplorer
@@ -33,10 +34,13 @@ public class CodeExplorerComponentViewModel : CodeExplorerItemViewModel, ICodeEx
3334
DeclarationType.Variable,
3435
};
3536

36-
public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable<Declaration> declarations)
37+
private readonly IProjectsProvider _projectsProvider;
38+
39+
public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable<Declaration> declarations, IProjectsProvider projectsProvider)
3740
{
3841
Parent = parent;
3942
Declaration = declaration;
43+
_projectsProvider = projectsProvider;
4044
_icon = Icons[DeclarationType];
4145
Items = declarations.GroupBy(item => item.Scope).SelectMany(grouping =>
4246
grouping.Where(item => item.ParentDeclaration != null
@@ -48,12 +52,17 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
4852

4953
_name = Declaration.IdentifierName;
5054

51-
var component = declaration.QualifiedName.QualifiedModuleName.Component;
55+
var qualifiedModuleName = declaration.QualifiedName.QualifiedModuleName;
5256
try
5357
{
54-
if (component.Type == ComponentType.Document)
58+
if (qualifiedModuleName.ComponentType == ComponentType.Document)
5559
{
56-
var parenthesizedName = component.Properties["Name"].Value.ToString();
60+
var component = _projectsProvider.Component(qualifiedModuleName);
61+
string parenthesizedName;
62+
using (var properties = component.Properties)
63+
{
64+
parenthesizedName = properties["Name"].Value.ToString() ?? String.Empty;
65+
}
5766

5867
if (ContainsBuiltinDocumentPropertiesProperty())
5968
{
@@ -79,7 +88,7 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
7988

8089
private bool ContainsBuiltinDocumentPropertiesProperty()
8190
{
82-
var properties = Declaration.QualifiedName.QualifiedModuleName.Component.Properties;
91+
using (var properties = _projectsProvider.Component(Declaration.QualifiedName.QualifiedModuleName).Properties)
8392
{
8493
return properties.Any(item => item.Name == "BuiltinDocumentProperties");
8594
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows.Media.Imaging;
55
using Rubberduck.Parsing.Symbols;
66
using Rubberduck.VBEditor;
7+
using Rubberduck.VBEditor.ComManagement;
78
using resx = Rubberduck.Properties.Resources;
89

910
namespace Rubberduck.Navigation.CodeExplorer
@@ -18,9 +19,12 @@ public class CodeExplorerCustomFolderViewModel : CodeExplorerItemViewModel
1819
DeclarationType.UserForm,
1920
};
2021

21-
public CodeExplorerCustomFolderViewModel(CodeExplorerItemViewModel parent, string name, string fullPath)
22+
private readonly IProjectsProvider _projectsProvider;
23+
24+
public CodeExplorerCustomFolderViewModel(CodeExplorerItemViewModel parent, string name, string fullPath, IProjectsProvider projectsProvider)
2225
{
2326
_parent = parent;
27+
_projectsProvider = projectsProvider;
2428
FullPath = fullPath;
2529
Name = name.Replace("\"", string.Empty);
2630
FolderAttribute = string.Format("@Folder(\"{0}\")", fullPath.Replace("\"", string.Empty));
@@ -42,7 +46,7 @@ public void AddNodes(List<Declaration> declarations)
4246
var members = declarations.Where(item =>
4347
!ComponentTypes.Contains(item.DeclarationType) && item.ComponentName == moduleName);
4448

45-
AddChild(new CodeExplorerComponentViewModel(this, parent, members));
49+
AddChild(new CodeExplorerComponentViewModel(this, parent, members, _projectsProvider));
4650
}
4751
catch (InvalidOperationException exception)
4852
{

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewMod
8585

8686
if (x.ExpandedIcon != y.ExpandedIcon)
8787
{
88-
// ReSharper disable PossibleInvalidOperationException - this will have a component
89-
var xComponent = x.QualifiedSelection.Value.QualifiedName.Component;
90-
var yComponent = y.QualifiedSelection.Value.QualifiedName.Component;
88+
// ReSharper disable PossibleInvalidOperationException - this will have a QualifiedSelection
89+
var xQmn = x.QualifiedSelection.Value.QualifiedName;
90+
var yQmn = y.QualifiedSelection.Value.QualifiedName;
9191

92-
if (xComponent.Type == ComponentType.Document ^ yComponent.Type == ComponentType.Document)
92+
if (xQmn.ComponentType == ComponentType.Document ^ yQmn.ComponentType == ComponentType.Document)
9393
{
94-
return xComponent.Type == ComponentType.Document ? -1 : 1;
94+
return xQmn.ComponentType == ComponentType.Document ? -1 : 1;
9595
}
9696
}
9797

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
2828
{
2929
private readonly FolderHelper _folderHelper;
3030
private readonly RubberduckParserState _state;
31-
private IConfigProvider<GeneralSettings> _generalSettingsProvider;
3231
private readonly IConfigProvider<WindowSettings> _windowSettingsProvider;
3332
private readonly GeneralSettings _generalSettings;
3433
private readonly WindowSettings _windowSettings;
@@ -42,7 +41,6 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
4241
_state = state;
4342
_state.StateChanged += HandleStateChanged;
4443
_state.ModuleStateChanged += ParserState_ModuleStateChanged;
45-
_generalSettingsProvider = generalSettingsProvider;
4644
_windowSettingsProvider = windowSettingsProvider;
4745

4846
if (generalSettingsProvider != null)
@@ -93,10 +91,7 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
9391
}
9492

9593
PrintCommand = commands.OfType<PrintCommand>().SingleOrDefault();
96-
97-
CommitCommand = commands.OfType<CommitCommand>().SingleOrDefault();
98-
UndoCommand = commands.OfType<UndoCommand>().SingleOrDefault();
99-
94+
10095
CopyResultsCommand = commands.OfType<CopyResultsCommand>().SingleOrDefault();
10196

10297
SetNameSortCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
@@ -374,8 +369,7 @@ private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgress
374369
return;
375370
}
376371

377-
var components = e.Module.Component.Collection;
378-
var componentProject = components.Parent;
372+
var componentProject = _state.ProjectsProvider.Project(e.Module.ProjectId);
379373
{
380374
var projectNode = Projects.OfType<CodeExplorerProjectViewModel>()
381375
.FirstOrDefault(p => p.Declaration.Project.Equals(componentProject));
@@ -399,13 +393,13 @@ private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgress
399393
{
400394
if (folderNode == null)
401395
{
402-
folderNode = new CodeExplorerCustomFolderViewModel(projectNode, projectName, projectName);
396+
folderNode = new CodeExplorerCustomFolderViewModel(projectNode, projectName, projectName, _state.ProjectsProvider);
403397
projectNode.AddChild(folderNode);
404398
}
405399

406400
var declaration = CreateDeclaration(e.Module);
407401
var newNode =
408-
new CodeExplorerComponentViewModel(folderNode, declaration, new List<Declaration>())
402+
new CodeExplorerComponentViewModel(folderNode, declaration, new List<Declaration>(), _state.ProjectsProvider)
409403
{
410404
IsErrorState = true
411405
};
@@ -427,7 +421,7 @@ private Declaration CreateDeclaration(QualifiedModuleName module)
427421
{
428422
var projectDeclaration =
429423
_state.DeclarationFinder.UserDeclarations(DeclarationType.Project)
430-
.FirstOrDefault(item => item.Project.VBComponents.Contains(module.Component));
424+
.FirstOrDefault(item => item.Project.ProjectId == module.ProjectId);
431425

432426
if (module.ComponentType == ComponentType.StandardModule)
433427
{
@@ -536,9 +530,6 @@ private void SwitchNodeState(CodeExplorerItemViewModel node, bool expandedState)
536530
public CommandBase RemoveCommand { get; }
537531

538532
public CommandBase PrintCommand { get; }
539-
540-
public CommandBase CommitCommand { get; }
541-
public CommandBase UndoCommand { get; }
542533

543534
private readonly CommandBase _externalRemoveCommand;
544535

@@ -557,9 +548,7 @@ private void ExecuteRemoveComand(object param)
557548
public Visibility ExportVisibility => CanExecuteExportAllCommand ? Visibility.Collapsed : Visibility.Visible;
558549

559550
public Visibility ExportAllVisibility => CanExecuteExportAllCommand ? Visibility.Visible : Visibility.Collapsed;
560-
561-
public bool EnableSourceControl => _generalSettings.EnableExperimentalFeatures.Any(a => a.Key == RubberduckUI.GeneralSettings_EnableSourceControl);
562-
551+
563552
public Visibility TreeViewVisibility => Projects == null || Projects.Count == 0 ? Visibility.Collapsed : Visibility.Visible;
564553

565554
public Visibility EmptyUIRefreshMessageVisibility => _isBusy ? Visibility.Hidden : Visibility.Visible;

0 commit comments

Comments
 (0)