Skip to content

Commit 68267e5

Browse files
committed
Refresh CE and TE after declarations are resolved, rather than waiting for inspections and reference resolving. Prevent reparse without changes from firing Ready when state is Error.
1 parent 2f77ea3 commit 68267e5

File tree

5 files changed

+47
-35
lines changed

5 files changed

+47
-35
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,36 +245,39 @@ public ObservableCollection<CodeExplorerItemViewModel> Projects
245245

246246
private void ParserState_StateChanged(object sender, EventArgs e)
247247
{
248-
if (Projects == null)
248+
UiDispatcher.InvokeAsync(() =>
249249
{
250-
Projects = new ObservableCollection<CodeExplorerItemViewModel>();
251-
}
250+
if (Projects == null)
251+
{
252+
Projects = new ObservableCollection<CodeExplorerItemViewModel>();
253+
}
252254

253-
IsBusy = _state.Status == ParserState.Parsing;
254-
if (_state.Status != ParserState.Ready)
255-
{
256-
return;
257-
}
258-
259-
var userDeclarations = _state.AllUserDeclarations
260-
.GroupBy(declaration => declaration.Project)
261-
.Where(grouping => grouping.Key != null)
262-
.ToList();
255+
IsBusy = _state.Status < ParserState.ResolvedDeclarations;
256+
if (_state.Status != ParserState.ResolvedDeclarations)
257+
{
258+
return;
259+
}
263260

264-
if (userDeclarations.Any(
261+
var userDeclarations = _state.AllUserDeclarations
262+
.GroupBy(declaration => declaration.Project)
263+
.Where(grouping => grouping.Key != null)
264+
.ToList();
265+
266+
if (userDeclarations.Any(
265267
grouping => grouping.All(declaration => declaration.DeclarationType != DeclarationType.Project)))
266-
{
267-
return;
268-
}
268+
{
269+
return;
270+
}
269271

270-
var newProjects = userDeclarations.Select(grouping =>
271-
new CodeExplorerProjectViewModel(_folderHelper,
272-
grouping.SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.Project),
273-
grouping)).ToList();
272+
var newProjects = userDeclarations.Select(grouping =>
273+
new CodeExplorerProjectViewModel(_folderHelper,
274+
grouping.SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.Project),
275+
grouping)).ToList();
274276

275-
UpdateNodes(Projects, newProjects);
276-
277-
Projects = new ObservableCollection<CodeExplorerItemViewModel>(newProjects);
277+
UpdateNodes(Projects, newProjects);
278+
279+
Projects = new ObservableCollection<CodeExplorerItemViewModel>(newProjects);
280+
});
278281
}
279282

280283
private void UpdateNodes(IEnumerable<CodeExplorerItemViewModel> oldList,

RetailCoder.VBE/UI/Command/MenuItems/RubberduckCommandBar.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ private void SetSelectionText(QualifiedSelection selection)
9494
private void State_StateChanged(object sender, EventArgs e)
9595
{
9696
_logger.Debug("RubberduckCommandBar handles StateChanged...");
97-
SetStatusText(RubberduckUI.ResourceManager.GetString("ParserState_" + _state.Status));
97+
98+
if (_state.Status != ParserState.ResolvedDeclarations)
99+
{
100+
SetStatusText(RubberduckUI.ResourceManager.GetString("ParserState_" + _state.Status));
101+
}
98102
}
99103

100104
public event EventHandler Refresh;

RetailCoder.VBE/UI/UnitTesting/TestExplorerModel.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@ public TestExplorerModel(VBE vbe, RubberduckParserState state)
2626

2727
private void State_StateChanged(object sender, ParserStateEventArgs e)
2828
{
29-
if (e.State != ParserState.Ready) { return; }
30-
31-
var tests = UnitTestHelpers.GetAllTests(_vbe, _state).ToList();
32-
33-
var removedTests = Tests.Where(test =>
34-
!tests.Any(t =>
35-
t.Declaration.ComponentName == test.Declaration.ComponentName &&
36-
t.Declaration.IdentifierName == test.Declaration.IdentifierName &&
37-
t.Declaration.ProjectId == test.Declaration.ProjectId)).ToList();
29+
if (e.State != ParserState.ResolvedDeclarations) { return; }
3830

3931
_dispatcher.Invoke(() =>
4032
{
33+
var tests = UnitTestHelpers.GetAllTests(_vbe, _state).ToList();
34+
35+
var removedTests = Tests.Where(test =>
36+
!tests.Any(t =>
37+
t.Declaration.ComponentName == test.Declaration.ComponentName &&
38+
t.Declaration.IdentifierName == test.Declaration.IdentifierName &&
39+
t.Declaration.ProjectId == test.Declaration.ProjectId)).ToList();
4140

4241
// remove old tests
4342
foreach (var test in removedTests)

Rubberduck.Parsing/VBA/ParserState.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public enum ParserState
2424
/// </summary>
2525
Resolving,
2626
/// <summary>
27+
/// Resolving identifier references.
28+
/// </summary>
29+
ResolvedDeclarations,
30+
/// <summary>
2731
/// Parser state is in sync with the actual code in the VBE.
2832
/// </summary>
2933
Ready,

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void ParseAll()
143143

144144
if (!toParse.Any())
145145
{
146-
State.SetStatusAndFireStateChanged(ParserState.Ready);
146+
State.SetStatusAndFireStateChanged(_state.Status);
147147
return;
148148
}
149149

@@ -496,6 +496,8 @@ private void ResolveInternal(CancellationToken token)
496496
ResolveDeclarations(qualifiedName.Component, kvp.Value);
497497
}
498498

499+
_state.SetStatusAndFireStateChanged(ParserState.ResolvedDeclarations);
500+
499501
// walk all parse trees (modified or not) for identifier references
500502
var finder = new DeclarationFinder(_state.AllDeclarations, _state.AllComments, _state.AllAnnotations);
501503
var passes = new List<ICompilationPass>

0 commit comments

Comments
 (0)