Skip to content

Commit 8dd6c9d

Browse files
committed
hooked up COM reflection, started optimizing parser+resolver code, removed parser tests newly relying on IO
1 parent ac429f3 commit 8dd6c9d

22 files changed

+712
-578
lines changed

RetailCoder.VBE/App.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
115115
connectionPoint.Advise(sink, out cookie);
116116

117117
_componentsEventsConnectionPoints.Add(e.Item.VBComponents, Tuple.Create(connectionPoint, cookie));
118-
_parser.State.OnParseRequested();
118+
_parser.State.OnParseRequested(sender);
119119
}
120120

121121
async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent> e)
@@ -129,7 +129,7 @@ async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBCom
129129
Debug.WriteLine(string.Format("Component '{0}' was renamed.", e.Item.Name));
130130

131131
_parser.State.ClearDeclarations(e.Item);
132-
_parser.State.OnParseRequested(e.Item);
132+
_parser.State.OnParseRequested(sender, e.Item);
133133
}
134134

135135
async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent> e)
@@ -142,13 +142,13 @@ async void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent
142142
{
143143
Debug.WriteLine(string.Format("Component '{0}' was reloaded.", e.Item.Name));
144144
_parser.State.ClearDeclarations(e.Item);
145-
_parser.State.OnParseRequested(e.Item);
145+
_parser.State.OnParseRequested(sender, e.Item);
146146
}
147147

148148
async void sink_ComponentAdded(object sender, DispatcherEventArgs<VBComponent> e)
149149
{
150150
Debug.WriteLine(string.Format("Component '{0}' was added.", e.Item.Name));
151-
_parser.State.OnParseRequested(e.Item);
151+
_parser.State.OnParseRequested(sender, e.Item);
152152
}
153153

154154
async void sink_ComponentActivated(object sender, DispatcherEventArgs<VBComponent> e)
@@ -161,7 +161,7 @@ async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProje
161161
{
162162
Debug.WriteLine(string.Format("Project '{0}' was renamed.", e.Item.Name));
163163
_parser.State.ClearDeclarations(e.Item);
164-
_parser.State.OnParseRequested();
164+
_parser.State.OnParseRequested(sender);
165165
}
166166

167167
async void sink_ProjectActivated(object sender, DispatcherEventArgs<VBProject> e)
@@ -244,7 +244,7 @@ private async void hooks_MessageReceived(object sender, HookEventArgs e)
244244

245245
private void _stateBar_Refresh(object sender, EventArgs e)
246246
{
247-
_parser.State.OnParseRequested();
247+
_parser.State.OnParseRequested(sender);
248248
}
249249

250250
private void Parser_StateChanged(object sender, ParserStateEventArgs e)

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45
using System.Linq;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -63,12 +64,14 @@ public async Task<IList<ICodeInspectionResult>> FindIssuesAsync(RubberduckParser
6364
new Task(() =>
6465
{
6566
token.ThrowIfCancellationRequested();
67+
Console.WriteLine("Running inspection {0} in thread {1}", inspection.Name, Thread.CurrentThread.ManagedThreadId);
6668
var inspectionResults = inspection.GetInspectionResults();
6769
var results = inspectionResults as IList<InspectionResultBase> ?? inspectionResults.ToList();
6870

6971
if (results.Any())
7072
{
7173
//OnIssuesFound(results);
74+
Console.WriteLine("Inspection '{0}' returned {1} results.", inspection.Name, results.Count);
7275

7376
foreach (var inspectionResult in results)
7477
{
@@ -77,13 +80,22 @@ public async Task<IList<ICodeInspectionResult>> FindIssuesAsync(RubberduckParser
7780
}
7881
})).ToArray();
7982

80-
foreach (var inspection in inspections)
83+
try
8184
{
82-
inspection.Start();
83-
}
84-
85-
Task.WaitAll(inspections);
85+
var stopwatch = Stopwatch.StartNew();
86+
Console.WriteLine("Starting code inspections in thread {0}", Thread.CurrentThread.ManagedThreadId);
87+
foreach (var inspection in inspections)
88+
{
89+
await inspection;
90+
}
8691

92+
//Task.WaitAll(inspections);
93+
Console.WriteLine("Code inspections completed ({0}ms) in thread {1}", stopwatch.ElapsedMilliseconds, Thread.CurrentThread.ManagedThreadId);
94+
}
95+
catch (AggregateException exceptions)
96+
{
97+
Console.WriteLine(exceptions);
98+
}
8799
return allIssues.ToList();
88100
}
89101

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();

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel
2424

2525
public CodeExplorerProjectViewModel(Declaration declaration, IEnumerable<Declaration> declarations)
2626
{
27-
_declaration = declaration;
28-
Items = FindFolders(declarations.ToList(), '.');
27+
try
28+
{
29+
_declaration = declaration;
30+
Items = FindFolders(declarations.ToList(), '.');
2931

30-
_icon = _declaration.Project.Protection == vbext_ProjectProtection.vbext_pp_locked
31-
? GetImageSource(resx.lock__exclamation)
32-
: GetImageSource(resx.VSObject_Library);
32+
_icon = _declaration.Project.Protection == vbext_ProjectProtection.vbext_pp_locked
33+
? GetImageSource(resx.lock__exclamation)
34+
: GetImageSource(resx.VSObject_Library);
35+
}
36+
catch (NullReferenceException e)
37+
{
38+
Console.WriteLine(e);
39+
}
3340
}
3441

3542
private static IEnumerable<CodeExplorerItemViewModel> FindFolders(IEnumerable<Declaration> declarations, char delimiter)

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ private void ParserState_StateChanged(object sender, ParserStateEventArgs e)
8585

8686
var userDeclarations = _state.AllUserDeclarations
8787
.GroupBy(declaration => declaration.Project)
88+
.Where(grouping => grouping.Key != null)
8889
.ToList();
8990

91+
if (userDeclarations.Any(grouping => grouping.All(declaration => declaration.DeclarationType != DeclarationType.Project)))
92+
{
93+
return;
94+
}
95+
9096
Projects = new ObservableCollection<CodeExplorerProjectViewModel>(userDeclarations.Select(grouping =>
91-
new CodeExplorerProjectViewModel(grouping.Single(declaration => declaration.DeclarationType == DeclarationType.Project), grouping)));
97+
new CodeExplorerProjectViewModel(grouping.SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.Project), grouping)));
9298
}
9399

94100
private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgressEventArgs e)
@@ -100,7 +106,7 @@ private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgress
100106
private void ExecuteRefreshCommand(object param)
101107
{
102108
Debug.WriteLine("CodeExplorerViewModel.ExecuteRefreshCommand - requesting reparse");
103-
_state.OnParseRequested();
109+
_state.OnParseRequested(this);
104110
}
105111
}
106112
}

RetailCoder.VBE/Refactorings/ExtractInterface/ExtractInterfaceRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void AddInterface()
7171
module.InsertLines(_insertionLine, Tokens.Implements + ' ' + _model.InterfaceName + Environment.NewLine);
7272

7373
_state.StateChanged += _state_StateChanged;
74-
_state.OnParseRequested();
74+
_state.OnParseRequested(this);
7575
}
7676

7777
private int _insertionLine;

RetailCoder.VBE/UI/CodeInspections/InspectionResultsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private async void ExecuteRefreshCommandAsync(object parameter)
147147
IsBusy = true;
148148

149149
Debug.WriteLine("InspectionResultsViewModel.ExecuteRefreshCommand - requesting reparse");
150-
_state.OnParseRequested();
150+
_state.OnParseRequested(this);
151151
}
152152

153153
private bool CanExecuteRefreshCommand(object parameter)

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ICommand RefreshCommand
4141
return _refreshCommand = new DelegateCommand(_ =>
4242
{
4343
_state.StateChanged += _state_StateChanged;
44-
_state.OnParseRequested();
44+
_state.OnParseRequested(this);
4545
});
4646
}
4747
}

Rubberduck.Parsing/IRubberduckParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Rubberduck.Parsing
99
public interface IRubberduckParser
1010
{
1111
RubberduckParserState State { get; }
12-
void ParseComponent(VBComponent component, bool resolve = true, TokenStreamRewriter rewriter = null);
12+
void ParseComponent(VBComponent component, TokenStreamRewriter rewriter = null);
1313
//Task ParseAsync(VBComponent component, CancellationToken token, TokenStreamRewriter rewriter = null);
1414
//void Resolve(CancellationToken token);
1515
}

Rubberduck.Parsing/Rubberduck.Parsing.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@
7272
<Compile Include="Symbols\AdodbObjectModel.cs" />
7373
<Compile Include="Symbols\CommentExtensions.cs" />
7474
<Compile Include="Symbols\DeclarationEventArgs.cs" />
75+
<Compile Include="Symbols\DeclarationFinder.cs" />
7576
<Compile Include="Symbols\ExcelObjectModel.cs" />
7677
<Compile Include="Symbols\ExceptionErrorListener.cs" />
7778
<Compile Include="Symbols\IdentifierReferenceResolver.cs" />
7879
<Compile Include="Symbols\MemberProcessedEventArgs.cs" />
80+
<Compile Include="Symbols\ParameterDeclaration.cs" />
7981
<Compile Include="Symbols\ReferencedDeclarationsCollector.cs" />
8082
<Compile Include="Symbols\SyntaxErrorException.cs" />
8183
<Compile Include="Nodes\CommentNode.cs" />

0 commit comments

Comments
 (0)