Skip to content

Commit 8fc93ec

Browse files
authored
Merge pull request #1994 from Hosch250/parserUpdates
Get rid of single-component parse. Fix bug in cache. Fix bug in New…
2 parents 1a0ddf4 + 26cbb1a commit 8fc93ec

File tree

13 files changed

+44
-155
lines changed

13 files changed

+44
-155
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
3232

3333
_refreshCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param => _state.OnParseRequested(this),
3434
param => !IsBusy && _state.IsDirty());
35-
36-
_refreshComponentCommand = commands.OfType<CodeExplorer_RefreshComponentCommand>().FirstOrDefault();
35+
3736
_navigateCommand = commands.OfType<CodeExplorer_NavigateCommand>().FirstOrDefault();
3837

3938
_addTestModuleCommand = commands.OfType<CodeExplorer_AddTestModuleCommand>().FirstOrDefault();
@@ -413,9 +412,6 @@ private void SetErrorState(CodeExplorerItemViewModel itemNode, VBComponent compo
413412
private readonly CommandBase _refreshCommand;
414413
public CommandBase RefreshCommand { get { return _refreshCommand; } }
415414

416-
private readonly CommandBase _refreshComponentCommand;
417-
public CommandBase RefreshComponentCommand { get { return _refreshComponentCommand; } }
418-
419415
private readonly CommandBase _navigateCommand;
420416
public CommandBase NavigateCommand { get { return _navigateCommand; } }
421417

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@
418418
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_AddUserFormCommand.cs" />
419419
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_CopyResultsCommand.cs" />
420420
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_OpenProjectPropertiesCommand.cs" />
421-
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RefreshComponentCommand.cs" />
422421
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RenameCommand.cs" />
423422
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_FindAllReferencesCommand.cs" />
424423
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_FindAllImplementationsCommand.cs" />
@@ -952,7 +951,7 @@
952951
<Compile Include="UnitTesting\AssertClass.cs" />
953952
<Compile Include="UnitTesting\AssertCompletedEventArgs.cs" />
954953
<Compile Include="UnitTesting\AssertHandler.cs" />
955-
<Compile Include="UnitTesting\UnitTestHelpers.cs" />
954+
<Compile Include="UnitTesting\UnitTestUtils.cs" />
956955
<Compile Include="UnitTesting\IAssert.cs" />
957956
<Compile Include="UnitTesting\ITestEngine.cs" />
958957
<Compile Include="UnitTesting\ITestRunner.cs" />

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,8 @@
357357
<Setter Property="ContextMenu">
358358
<Setter.Value>
359359
<ContextMenu DataContext="{Binding DataContext, Source={x:Reference CodeExplorer}}">
360-
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_RefreshComponent}"
361-
Command="{Binding RefreshComponentCommand}"
362-
CommandParameter="{Binding SelectedItem}">
360+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Refresh}"
361+
Command="{Binding RefreshCommand}">
363362
<MenuItem.Icon>
364363
<Image Source="{StaticResource RefreshImage}" />
365364
</MenuItem.Icon>

RetailCoder.VBE/UI/CodeExplorer/Commands/CodeExplorer_RefreshComponentCommand.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,9 +1565,6 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
15651565
<data name="SortStyle_ByCodeOrder" xml:space="preserve">
15661566
<value>By code order</value>
15671567
</data>
1568-
<data name="CodeExplorer_RefreshComponent" xml:space="preserve">
1569-
<value>Refresh component</value>
1570-
</data>
15711568
<data name="TestOutcome_Ignored" xml:space="preserve">
15721569
<value>Ignored</value>
15731570
</data>

RetailCoder.VBE/UI/UnitTesting/TestExplorerModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private void State_StateChanged(object sender, ParserStateEventArgs e)
3131

3232
_dispatcher.Invoke(() =>
3333
{
34-
var tests = UnitTestHelpers.GetAllTests(_vbe, _state).ToList();
34+
var tests = UnitTestUtils.GetAllTests(_vbe, _state).ToList();
3535

3636
var removedTests = Tests.Where(test =>
3737
!tests.Any(t =>

RetailCoder.VBE/UnitTesting/NewTestMethodCommand.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System.Linq;
22
using System.Runtime.InteropServices;
33
using Microsoft.Vbe.Interop;
4-
using Rubberduck.Parsing.Annotations;
5-
using Rubberduck.Parsing.Symbols;
64
using Rubberduck.Parsing.VBA;
75
using Rubberduck.UI;
86

@@ -68,12 +66,10 @@ public void NewTestMethod()
6866

6967
try
7068
{
71-
var declaration = _state.AllUserDeclarations.FirstOrDefault(f =>
69+
var declaration = _state.GetTestModules().FirstOrDefault(f =>
7270
f.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.ActiveCodePane.CodeModule);
7371

74-
if (declaration != null &&
75-
declaration.DeclarationType == DeclarationType.ProceduralModule &&
76-
declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
72+
if (declaration != null)
7773
{
7874
var module = _vbe.ActiveCodePane.CodeModule;
7975
var name = GetNextTestMethodName(module.Parent);
@@ -97,12 +93,10 @@ public void NewExpectedErrorTestMethod()
9793

9894
try
9995
{
100-
var declaration = _state.AllUserDeclarations.FirstOrDefault(f =>
96+
var declaration = _state.GetTestModules().FirstOrDefault(f =>
10197
f.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.ActiveCodePane.CodeModule);
10298

103-
if (declaration != null &&
104-
declaration.DeclarationType == DeclarationType.ProceduralModule &&
105-
declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
99+
if (declaration != null)
106100
{
107101
var module = _vbe.ActiveCodePane.CodeModule;
108102
var name = GetNextTestMethodName(module.Parent);

RetailCoder.VBE/UnitTesting/UnitTestHelpers.cs renamed to RetailCoder.VBE/UnitTesting/UnitTestUtils.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Rubberduck.UnitTesting
1010
{
11-
public static class UnitTestHelpers
11+
public static class UnitTestUtils
1212
{
1313
public static IEnumerable<TestMethod> GetAllTests(VBE vbe, RubberduckParserState state)
1414
{
@@ -77,5 +77,12 @@ private static IEnumerable<Declaration> GetTestModuleProcedures(RubberduckParser
7777
item.ParentDeclaration.DeclarationType == DeclarationType.ProceduralModule &&
7878
item.ParentDeclaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
7979
}
80+
81+
public static IEnumerable<Declaration> GetTestModules(this RubberduckParserState state)
82+
{
83+
return state.AllUserDeclarations.Where(item =>
84+
item.DeclarationType == DeclarationType.ProceduralModule &&
85+
item.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
86+
}
8087
}
8188
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using System;
2-
using Microsoft.Vbe.Interop;
32
using Rubberduck.Parsing.VBA;
43

54
namespace Rubberduck.Parsing
65
{
76
public interface IRubberduckParser : IDisposable
87
{
98
RubberduckParserState State { get; }
10-
void Cancel(VBComponent component = null);
119
}
1210
}

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -51,50 +51,10 @@ public RubberduckParser(
5151
// but the cancelees need to use their own token.
5252
private readonly List<CancellationTokenSource> _cancellationTokens = new List<CancellationTokenSource> {new CancellationTokenSource()};
5353

54-
private void ReparseRequested(object sender, ParseRequestEventArgs e)
54+
private void ReparseRequested(object sender, EventArgs e)
5555
{
56-
if (e.IsFullReparseRequest)
57-
{
58-
Cancel();
59-
Task.Run(() => ParseAll(_cancellationTokens[0]));
60-
}
61-
else
62-
{
63-
Cancel(e.Component);
64-
Task.Run(() =>
65-
{
66-
State.SetModuleState(e.Component, ParserState.Pending);
67-
68-
SyncComReferences(State.Projects);
69-
AddBuiltInDeclarations();
70-
71-
if (_cancellationTokens[0].IsCancellationRequested)
72-
{
73-
return;
74-
}
75-
76-
ParseAsync(e.Component, _cancellationTokens[0]).Wait();
77-
78-
if (_cancellationTokens[0].IsCancellationRequested)
79-
{
80-
return;
81-
}
82-
83-
if (State.Status == ParserState.Error) { return; }
84-
85-
var qualifiedName = new QualifiedModuleName(e.Component);
86-
87-
State.SetModuleState(e.Component, ParserState.ResolvingDeclarations);
88-
ResolveDeclarations(qualifiedName.Component,
89-
State.ParseTrees.Find(s => s.Key == qualifiedName).Value);
90-
91-
if (State.Status < ParserState.Error)
92-
{
93-
State.SetStatusAndFireStateChanged(ParserState.ResolvedDeclarations);
94-
ResolveReferencesAsync(_cancellationTokens[0].Token);
95-
}
96-
});
97-
}
56+
Cancel();
57+
Task.Run(() => ParseAll(_cancellationTokens[0]));
9858
}
9959

10060
/// <summary>
@@ -505,29 +465,15 @@ private Task ParseAsync(VBComponent component, CancellationTokenSource token, To
505465
return task;
506466
}
507467

508-
public void Cancel(VBComponent component = null)
468+
private void Cancel()
509469
{
510470
lock (_cancellationTokens[0])
511471
{
512-
if (component == null)
513-
{
514-
_cancellationTokens[0].Cancel();
472+
_cancellationTokens[0].Cancel();
515473

516-
_cancellationTokens[0].Dispose();
517-
_cancellationTokens.Add(new CancellationTokenSource());
518-
_cancellationTokens.RemoveAt(0);
519-
}
520-
else
521-
{
522-
_cancellationTokens[0].Cancel();
523-
524-
Tuple<Task, CancellationTokenSource> result;
525-
if (_currentTasks.TryGetValue(component, out result))
526-
{
527-
result.Item2.Cancel();
528-
result.Item2.Dispose();
529-
}
530-
}
474+
_cancellationTokens[0].Dispose();
475+
_cancellationTokens.Add(new CancellationTokenSource());
476+
_cancellationTokens.RemoveAt(0);
531477
}
532478
}
533479

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,6 @@ public ParserStateEventArgs(ParserState state)
2929
public ParserState State { get { return _state; } }
3030
}
3131

32-
public class ParseRequestEventArgs : EventArgs
33-
{
34-
private readonly VBComponent _component;
35-
36-
public ParseRequestEventArgs(VBComponent component)
37-
{
38-
_component = component;
39-
}
40-
41-
public VBComponent Component { get { return _component; } }
42-
public bool IsFullReparseRequest { get { return _component == null; } }
43-
}
44-
4532
public class RubberduckStatusMessageEventArgs : EventArgs
4633
{
4734
private readonly string _message;
@@ -63,7 +50,7 @@ public sealed class RubberduckParserState : IDisposable
6350
private readonly ConcurrentDictionary<QualifiedModuleName, ModuleState> _moduleStates =
6451
new ConcurrentDictionary<QualifiedModuleName, ModuleState>();
6552

66-
public event EventHandler<ParseRequestEventArgs> ParseRequest;
53+
public event EventHandler<EventArgs> ParseRequest;
6754
public event EventHandler<RubberduckStatusMessageEventArgs> StatusMessageUpdate;
6855

6956
private static readonly List<ParserState> States = new List<ParserState>();
@@ -217,15 +204,23 @@ public void OnStatusMessageUpdate(string message)
217204
/// </summary>
218205
public void RefreshProjects()
219206
{
220-
_projects.Clear();
221-
foreach (VBProject project in _vbe.VBProjects)
207+
lock (_projects)
222208
{
223-
if (string.IsNullOrEmpty(project.HelpFile) || _projects.Keys.Contains(project.HelpFile))
209+
_projects.Clear();
210+
foreach (VBProject project in _vbe.VBProjects)
224211
{
225-
project.AssignProjectId();
226-
}
212+
if (project.Protection == vbext_ProjectProtection.vbext_pp_locked)
213+
{
214+
continue;
215+
}
227216

228-
_projects.Add(project.HelpFile, project);
217+
if (string.IsNullOrEmpty(project.HelpFile) || _projects.Keys.Contains(project.HelpFile))
218+
{
219+
project.AssignProjectId();
220+
}
221+
222+
_projects.Add(project.HelpFile, project);
223+
}
229224
}
230225
}
231226

@@ -861,7 +856,7 @@ public void OnParseRequested(object requestor, VBComponent component = null)
861856
var handler = ParseRequest;
862857
if (handler != null)
863858
{
864-
var args = new ParseRequestEventArgs(component);
859+
var args = EventArgs.Empty;
865860
handler.Invoke(requestor, args);
866861
}
867862
}

RubberduckTests/UnitTesting/DiscoveryTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Public Sub TestMethod1()
3434
parser.Parse(new CancellationTokenSource());
3535
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
3636

37-
Assert.AreEqual(1, UnitTestHelpers.GetAllTests(vbe.Object, parser.State).Count());
37+
Assert.AreEqual(1, UnitTestUtils.GetAllTests(vbe.Object, parser.State).Count());
3838
}
3939

4040
[TestMethod]
@@ -55,7 +55,7 @@ public void Discovery_IgnoresNonAnnotatedTestMethods()
5555
parser.Parse(new CancellationTokenSource());
5656
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
5757

58-
Assert.IsFalse(UnitTestHelpers.GetAllTests(vbe.Object, parser.State).Any());
58+
Assert.IsFalse(UnitTestUtils.GetAllTests(vbe.Object, parser.State).Any());
5959
}
6060

6161
[TestMethod]
@@ -77,7 +77,7 @@ Public Sub TestMethod1()
7777
parser.Parse(new CancellationTokenSource());
7878
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
7979

80-
Assert.IsFalse(UnitTestHelpers.GetAllTests(vbe.Object, parser.State).Any());
80+
Assert.IsFalse(UnitTestUtils.GetAllTests(vbe.Object, parser.State).Any());
8181
}
8282

8383
[TestMethod]

0 commit comments

Comments
 (0)