Skip to content

Commit 16c548a

Browse files
committed
Merge pull request #1187 from retailcoder/TypeInfo
TypeInfo
2 parents 9a8c2ea + 97f3be3 commit 16c548a

File tree

96 files changed

+14981
-3237
lines changed

Some content is hidden

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

96 files changed

+14981
-3237
lines changed

RetailCoder.VBE/App.cs

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
9696

9797
async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
9898
{
99+
if (!_parser.State.AllDeclarations.Any())
100+
{
101+
// forces menus to evaluate their CanExecute state:
102+
Parser_StateChanged(this, new ParserStateEventArgs(ParserState.Pending));
103+
_stateBar.SetStatusText();
104+
return;
105+
}
106+
99107
Debug.WriteLine(string.Format("Project '{0}' was added.", e.Item.Name));
100108
var connectionPointContainer = (IConnectionPointContainer)e.Item.VBComponents;
101109
var interfaceId = typeof(_dispVBComponentsEvents).GUID;
@@ -115,57 +123,95 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
115123
connectionPoint.Advise(sink, out cookie);
116124

117125
_componentsEventsConnectionPoints.Add(e.Item.VBComponents, Tuple.Create(connectionPoint, cookie));
118-
_parser.State.OnParseRequested();
126+
_parser.State.OnParseRequested(sender);
119127
}
120128

121129
async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
122130
{
131+
if (!_parser.State.AllDeclarations.Any())
132+
{
133+
return;
134+
}
135+
123136
Debug.WriteLine(string.Format("Component '{0}' was selected.", e.Item.Name));
124137
// do something?
125138
}
126139

127140
async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBComponent> e)
128141
{
142+
if (!_parser.State.AllDeclarations.Any())
143+
{
144+
return;
145+
}
146+
129147
Debug.WriteLine(string.Format("Component '{0}' was renamed.", e.Item.Name));
130148

131-
_parser.State.ClearDeclarations(e.Item);
132-
_parser.State.OnParseRequested(e.Item);
149+
_parser.State.OnParseRequested(sender, e.Item);
133150
}
134151

135152
async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent> e)
136153
{
154+
if (!_parser.State.AllDeclarations.Any())
155+
{
156+
return;
157+
}
158+
137159
Debug.WriteLine(string.Format("Component '{0}' was removed.", e.Item.Name));
138160
_parser.State.ClearDeclarations(e.Item);
139161
}
140162

141163
async void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent> e)
142164
{
165+
if (!_parser.State.AllDeclarations.Any())
166+
{
167+
return;
168+
}
169+
143170
Debug.WriteLine(string.Format("Component '{0}' was reloaded.", e.Item.Name));
144-
_parser.State.ClearDeclarations(e.Item);
145-
_parser.State.OnParseRequested(e.Item);
171+
_parser.State.OnParseRequested(sender, e.Item);
146172
}
147173

148174
async void sink_ComponentAdded(object sender, DispatcherEventArgs<VBComponent> e)
149175
{
176+
if (!_parser.State.AllDeclarations.Any())
177+
{
178+
return;
179+
}
180+
150181
Debug.WriteLine(string.Format("Component '{0}' was added.", e.Item.Name));
151-
_parser.State.OnParseRequested(e.Item);
182+
_parser.State.OnParseRequested(sender, e.Item);
152183
}
153184

154185
async void sink_ComponentActivated(object sender, DispatcherEventArgs<VBComponent> e)
155186
{
187+
if (!_parser.State.AllDeclarations.Any())
188+
{
189+
return;
190+
}
191+
156192
Debug.WriteLine(string.Format("Component '{0}' was activated.", e.Item.Name));
157193
// do something?
158194
}
159195

160196
async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProject> e)
161197
{
198+
if (!_parser.State.AllDeclarations.Any())
199+
{
200+
return;
201+
}
202+
162203
Debug.WriteLine(string.Format("Project '{0}' was renamed.", e.Item.Name));
163204
_parser.State.ClearDeclarations(e.Item);
164-
_parser.State.OnParseRequested();
205+
_parser.State.OnParseRequested(sender);
165206
}
166207

167208
async void sink_ProjectActivated(object sender, DispatcherEventArgs<VBProject> e)
168209
{
210+
if (!_parser.State.AllDeclarations.Any())
211+
{
212+
return;
213+
}
214+
169215
Debug.WriteLine(string.Format("Project '{0}' was activated.", e.Item.Name));
170216
// do something?
171217
}
@@ -244,11 +290,12 @@ private async void hooks_MessageReceived(object sender, HookEventArgs e)
244290

245291
private void _stateBar_Refresh(object sender, EventArgs e)
246292
{
247-
_parser.State.OnParseRequested();
293+
_parser.State.OnParseRequested(sender);
248294
}
249295

250-
private void Parser_StateChanged(object sender, ParserStateEventArgs e)
296+
private void Parser_StateChanged(object sender, EventArgs e)
251297
{
298+
Debug.WriteLine("App handles StateChanged ({0}), evaluating menu states...", _parser.State.Status);
252299
_appMenus.EvaluateCanExecute(_parser.State);
253300
}
254301

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Microsoft.Vbe.Interop;
9+
using Rubberduck.VBEditor.Extensions;
10+
using Rubberduck.Parsing.VBA;
11+
12+
namespace Rubberduck.Common
13+
{
14+
public class ModuleExporter : IModuleExporter
15+
{
16+
public string ExportPath
17+
{
18+
get
19+
{
20+
var assemblyLocation = Assembly.GetAssembly(typeof(App)).Location;
21+
return Path.GetDirectoryName(assemblyLocation);
22+
}
23+
}
24+
25+
public string Export(VBComponent component)
26+
{
27+
return component.ExportAsSourceFile(ExportPath);
28+
}
29+
}
30+
}

RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/Inspections/InspectionsUI.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@
453453
<value>Pass parameter by value</value>
454454
</data>
455455
<data name="QuickFixUseTypedFunction_" xml:space="preserve">
456-
<value>Change '{0}$' to '{0}'</value>
456+
<value>Change '{0}' to '{0}$'</value>
457457
</data>
458458
<data name="QuickFix_ThisModule" xml:space="preserve">
459459
<value>Fix all occurrences in module</value>

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,96 +9,99 @@
99

1010
namespace Rubberduck.Inspections
1111
{
12-
public class Inspector : IInspector, IDisposable
12+
namespace Rubberduck.Inspections
1313
{
14-
private readonly IGeneralConfigService _configService;
15-
private readonly IEnumerable<IInspection> _inspections;
16-
17-
public Inspector(IGeneralConfigService configService, IEnumerable<IInspection> inspections)
14+
public class Inspector : IInspector, IDisposable
1815
{
19-
_inspections = inspections;
16+
private readonly IGeneralConfigService _configService;
17+
private readonly IEnumerable<IInspection> _inspections;
2018

21-
_configService = configService;
22-
configService.LanguageChanged += ConfigServiceLanguageChanged;
23-
UpdateInspectionSeverity();
24-
}
19+
public Inspector(IGeneralConfigService configService, IEnumerable<IInspection> inspections)
20+
{
21+
_inspections = inspections;
2522

26-
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
27-
{
28-
UpdateInspectionSeverity();
29-
}
23+
_configService = configService;
24+
configService.LanguageChanged += ConfigServiceLanguageChanged;
25+
UpdateInspectionSeverity();
26+
}
3027

31-
private void UpdateInspectionSeverity()
32-
{
33-
var config = _configService.LoadConfiguration();
28+
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
29+
{
30+
UpdateInspectionSeverity();
31+
}
3432

35-
foreach (var inspection in _inspections)
33+
private void UpdateInspectionSeverity()
3634
{
37-
foreach (var setting in config.UserSettings.CodeInspectionSettings.CodeInspections)
35+
var config = _configService.LoadConfiguration();
36+
37+
foreach (var inspection in _inspections)
3838
{
39-
if (inspection.Description == setting.Description)
39+
foreach (var setting in config.UserSettings.CodeInspectionSettings.CodeInspections)
4040
{
41-
inspection.Severity = setting.Severity;
41+
if (inspection.Description == setting.Description)
42+
{
43+
inspection.Severity = setting.Severity;
44+
}
4245
}
4346
}
4447
}
45-
}
4648

47-
public async Task<IList<ICodeInspectionResult>> FindIssuesAsync(RubberduckParserState state, CancellationToken token)
48-
{
49-
if (state == null || !state.AllUserDeclarations.Any())
49+
public async Task<IList<ICodeInspectionResult>> FindIssuesAsync(RubberduckParserState state, CancellationToken token)
5050
{
51-
return new ICodeInspectionResult[]{};
52-
}
53-
54-
await Task.Yield();
51+
if (state == null || !state.AllUserDeclarations.Any())
52+
{
53+
return new ICodeInspectionResult[] { };
54+
}
5555

56-
UpdateInspectionSeverity();
57-
//OnReset();
56+
await Task.Yield();
5857

59-
var allIssues = new ConcurrentBag<ICodeInspectionResult>();
58+
UpdateInspectionSeverity();
59+
//OnReset();
6060

61-
var inspections = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow)
62-
.Select(inspection =>
63-
new Task(() =>
64-
{
65-
token.ThrowIfCancellationRequested();
66-
var inspectionResults = inspection.GetInspectionResults();
67-
var results = inspectionResults as IList<InspectionResultBase> ?? inspectionResults.ToList();
61+
var allIssues = new ConcurrentBag<ICodeInspectionResult>();
6862

69-
if (results.Any())
63+
var inspections = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow)
64+
.Select(inspection =>
65+
new Task(() =>
7066
{
71-
//OnIssuesFound(results);
67+
token.ThrowIfCancellationRequested();
68+
var inspectionResults = inspection.GetInspectionResults();
69+
var results = inspectionResults as IList<InspectionResultBase> ?? inspectionResults.ToList();
7270

73-
foreach (var inspectionResult in results)
71+
if (results.Any())
7472
{
75-
allIssues.Add(inspectionResult);
76-
}
77-
}
78-
})).ToArray();
73+
//OnIssuesFound(results);
7974

80-
foreach (var inspection in inspections)
81-
{
82-
inspection.Start();
83-
}
75+
foreach (var inspectionResult in results)
76+
{
77+
allIssues.Add(inspectionResult);
78+
}
79+
}
80+
})).ToArray();
8481

85-
Task.WaitAll(inspections);
82+
foreach (var inspection in inspections)
83+
{
84+
inspection.Start();
85+
}
8686

87-
return allIssues.ToList();
88-
}
87+
Task.WaitAll(inspections);
8988

90-
public void Dispose()
91-
{
92-
Dispose(true);
93-
}
89+
return allIssues.ToList();
90+
}
9491

95-
protected virtual void Dispose(bool disposing)
96-
{
97-
if (!disposing) { return; }
92+
public void Dispose()
93+
{
94+
Dispose(true);
95+
}
9896

99-
if (_configService != null)
97+
protected virtual void Dispose(bool disposing)
10098
{
101-
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
99+
if (!disposing) { return; }
100+
101+
if (_configService != null)
102+
{
103+
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
104+
}
102105
}
103106
}
104107
}

RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Collections;
12
using System.Collections.Generic;
23
using System.Linq;
4+
using System.Windows.Threading;
35
using Rubberduck.Common;
46
using Rubberduck.Parsing.Grammar;
57
using Rubberduck.Parsing.Symbols;
@@ -12,8 +14,11 @@ public sealed class ParameterCanBeByValInspection : InspectionBase
1214
public ParameterCanBeByValInspection(RubberduckParserState state)
1315
: base(state, CodeInspectionSeverity.Suggestion)
1416
{
17+
_dispatcher = Dispatcher.CurrentDispatcher;
1518
}
1619

20+
private readonly Dispatcher _dispatcher;
21+
1722
public override string Meta { get { return InspectionsUI.ParameterCanBeByValInspectionMeta; } }
1823
public override string Description { get { return InspectionsUI.ParameterCanBeByValInspectionName; } }
1924
public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
@@ -39,9 +44,13 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3944
{
4045
var declarations = UserDeclarations.ToList();
4146

42-
var interfaceMembers = declarations.FindInterfaceMembers()
43-
.Concat(declarations.FindInterfaceImplementationMembers())
44-
.ToList();
47+
IEnumerable<Declaration> interfaceMembers = null;
48+
_dispatcher.Invoke(() =>
49+
{
50+
interfaceMembers = declarations.FindInterfaceMembers()
51+
.Concat(declarations.FindInterfaceImplementationMembers())
52+
.ToList();
53+
});
4554

4655
var formEventHandlerScopes = declarations.FindFormEventHandlers()
4756
.Select(handler => handler.Scope);

RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ParameterNotUsedInspection(VBE vbe, RubberduckParserState state, IMessage
3333

3434
public override IEnumerable<InspectionResultBase> GetInspectionResults()
3535
{
36-
var declarations = Declarations.ToList();
36+
var declarations = UserDeclarations.ToList();
3737

3838
var interfaceMemberScopes = declarations.FindInterfaceMembers().Select(m => m.Scope).ToList();
3939
var interfaceImplementationMemberScopes = declarations.FindInterfaceImplementationMembers().Select(m => m.Scope).ToList();

0 commit comments

Comments
 (0)