Skip to content

Commit 63045fd

Browse files
committed
Close #1830
1 parent 50b5ddd commit 63045fd

File tree

9 files changed

+54
-41
lines changed

9 files changed

+54
-41
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,6 @@ public ObservableCollection<CodeExplorerItemViewModel> Projects
244244
}
245245
}
246246

247-
private Declaration FindNewProjectDeclaration(string id)
248-
{
249-
return _state.AllUserDeclarations.SingleOrDefault(item =>
250-
item.ProjectId == id &&
251-
item.DeclarationType == DeclarationType.Project);
252-
}
253-
254-
private Declaration FindNewDeclaration(Declaration declaration)
255-
{
256-
return _state.AllUserDeclarations.SingleOrDefault(item =>
257-
item.ProjectId == declaration.ProjectId &&
258-
item.ComponentName == declaration.ComponentName &&
259-
item.ParentScope == declaration.ParentScope &&
260-
item.IdentifierName == declaration.IdentifierName &&
261-
item.DeclarationType == declaration.DeclarationType);
262-
}
263-
264247
private void ParserState_StateChanged(object sender, ParserStateEventArgs e)
265248
{
266249
if (Projects == null)
@@ -332,7 +315,10 @@ private void UpdateNodes(IEnumerable<CodeExplorerItemViewModel> oldList,
332315

333316
private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgressEventArgs e)
334317
{
335-
if (e.State != ParserState.Error)
318+
// if we are resolving references, we already have the declarations and don't need to display error
319+
if (!(e.State == ParserState.Error ||
320+
(e.State == ParserState.ResolverError &&
321+
e.OldState == ParserState.ResolvingDeclarations)))
336322
{
337323
return;
338324
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public FindSymbolCommandMenuItem(ICommand command)
2222

2323
public override bool EvaluateCanExecute(RubberduckParserState state)
2424
{
25-
return state.Status == ParserState.Ready ||
26-
state.Status == ParserState.Resolving;
25+
return state.Status >= ParserState.ResolvedDeclarations;
2726
}
2827
}
2928
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public RunAllTestsCommandMenuItem(ICommand command)
2020

2121
public override bool EvaluateCanExecute(RubberduckParserState state)
2222
{
23-
return state.Status == ParserState.Ready ||
24-
state.Status == ParserState.Resolving;
23+
return state.Status >= ParserState.ResolvedDeclarations;
2524
}
2625
}
2726
}

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 12 additions & 3 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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,8 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
14001400
<data name="ParserState_ResolverError" xml:space="preserve">
14011401
<value>Resolver Error</value>
14021402
</data>
1403-
<data name="ParserState_Resolving" xml:space="preserve">
1404-
<value>Resolving...</value>
1403+
<data name="ParserState_ResolvingDeclarations" xml:space="preserve">
1404+
<value>Resolving declarations...</value>
14051405
</data>
14061406
<data name="AboutWindow_BlogsHeader" xml:space="preserve">
14071407
<value>Blogs:</value>
@@ -1653,4 +1653,7 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
16531653
<data name="SourceControl_NoActiveProject" xml:space="preserve">
16541654
<value>No active VBProject</value>
16551655
</data>
1656+
<data name="ParserState_ResolvingReferences" xml:space="preserve">
1657+
<value>Resolving references...</value>
1658+
</data>
16561659
</root>

Rubberduck.Parsing/IParseResultProvider.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ public class ParseProgressEventArgs : EventArgs
3535
{
3636
private readonly VBComponent _component;
3737
private readonly ParserState _state;
38+
private readonly ParserState _oldState;
3839

39-
public ParseProgressEventArgs(VBComponent component, ParserState state)
40+
public ParseProgressEventArgs(VBComponent component, ParserState state, ParserState oldState)
4041
{
4142
_component = component;
4243
_state = state;
44+
_oldState = oldState;
4345
}
4446

4547
public VBComponent Component { get { return _component; } }
4648
public ParserState State { get { return _state; } }
49+
public ParserState OldState { get { return _oldState; } }
4750
}
4851
}

Rubberduck.Parsing/VBA/ParserState.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ public enum ParserState
2020
/// </summary>
2121
Parsed,
2222
/// <summary>
23-
/// Resolving identifier references.
23+
/// Resolving declarations.
2424
/// </summary>
25-
Resolving,
25+
ResolvingDeclarations,
2626
/// <summary>
27-
/// Resolving identifier references.
27+
/// Resolved declarations.
2828
/// </summary>
2929
ResolvedDeclarations,
3030
/// <summary>
31+
/// Resolving identifier references.
32+
/// </summary>
33+
ResolvingReferences,
34+
/// <summary>
3135
/// Parser state is in sync with the actual code in the VBE.
3236
/// </summary>
3337
Ready,

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void ReparseRequested(object sender, ParseRequestEventArgs e)
8686
Logger.Debug("Module '{0}' {1}", qualifiedName.ComponentName,
8787
_state.IsNewOrModified(qualifiedName) ? "was modified" : "was NOT modified");
8888

89-
_state.SetModuleState(e.Component, ParserState.Resolving);
89+
_state.SetModuleState(e.Component, ParserState.ResolvedDeclarations);
9090
ResolveDeclarations(qualifiedName.Component,
9191
_state.ParseTrees.Find(s => s.Key == qualifiedName).Value);
9292

@@ -165,7 +165,7 @@ public void Parse()
165165
Logger.Debug("Module '{0}' {1}", qualifiedName.ComponentName,
166166
_state.IsNewOrModified(qualifiedName) ? "was modified" : "was NOT modified");
167167

168-
_state.SetModuleState(components[index], ParserState.Resolving);
168+
_state.SetModuleState(components[index], ParserState.ResolvingDeclarations);
169169
ResolveDeclarations(qualifiedName.Component,
170170
_state.ParseTrees.Find(s => s.Key == qualifiedName).Value);
171171
});
@@ -272,7 +272,7 @@ private void ParseAll()
272272
Logger.Debug("Module '{0}' {1}", qualifiedName.ComponentName,
273273
_state.IsNewOrModified(qualifiedName) ? "was modified" : "was NOT modified");
274274

275-
_state.SetModuleState(toParse[index], ParserState.Resolving);
275+
_state.SetModuleState(toParse[index], ParserState.ResolvingDeclarations);
276276
ResolveDeclarations(qualifiedName.Component,
277277
_state.ParseTrees.Find(s => s.Key == qualifiedName).Value);
278278
});
@@ -311,7 +311,11 @@ private Task[] ResolveReferencesAsync()
311311
return new Task[0];
312312
}
313313

314-
tasks[index] = Task.Run(() => ResolveReferences(finder, kvp.Key.Component, kvp.Value));
314+
tasks[index] = Task.Run(() =>
315+
{
316+
_state.SetModuleState(kvp.Key.Component, ParserState.ResolvingReferences);
317+
ResolveReferences(finder, kvp.Key.Component, kvp.Value);
318+
});
315319
}
316320

317321
return tasks;
@@ -613,7 +617,7 @@ private Declaration CreateProjectDeclaration(QualifiedModuleName projectQualifie
613617

614618
private void ResolveReferences(DeclarationFinder finder, VBComponent component, IParseTree tree)
615619
{
616-
Debug.Assert(State.Status == ParserState.ResolvedDeclarations);
620+
Debug.Assert(State.Status == ParserState.ResolvingReferences);
617621

618622
var qualifiedName = new QualifiedModuleName(component);
619623
Logger.Debug("Resolving identifier references in '{0}'... (thread {1})", qualifiedName.Name, Thread.CurrentThread.ManagedThreadId);

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ private void OnStateChanged(ParserState state = ParserState.Pending)
207207
}
208208
public event EventHandler<ParseProgressEventArgs> ModuleStateChanged;
209209

210-
private void OnModuleStateChanged(VBComponent component, ParserState state)
210+
private void OnModuleStateChanged(VBComponent component, ParserState state, ParserState oldState)
211211
{
212212
var handler = ModuleStateChanged;
213213
if (handler != null)
214214
{
215-
var args = new ParseProgressEventArgs(component, state);
215+
var args = new ParseProgressEventArgs(component, state, oldState);
216216
handler.Invoke(this, args);
217217
}
218218
}
@@ -242,10 +242,12 @@ public void SetModuleState(VBComponent component, ParserState state, SyntaxError
242242
}
243243
var key = new QualifiedModuleName(component);
244244

245+
var oldState = GetModuleState(component);
246+
245247
_moduleStates.AddOrUpdate(key, new ModuleState(state), (c, e) => e.SetState(state));
246248
_moduleStates.AddOrUpdate(key, new ModuleState(parserError), (c, e) => e.SetModuleException(parserError));
247249
Logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", key.ComponentName, state, Thread.CurrentThread.ManagedThreadId);
248-
OnModuleStateChanged(component, state);
250+
OnModuleStateChanged(component, state, oldState);
249251
Status = EvaluateParserState();
250252
}
251253

@@ -323,9 +325,13 @@ private ParserState EvaluateParserState()
323325
{
324326
result = ParserState.Parsing;
325327
}
326-
if (stateCounts[(int)ParserState.Resolving] > 0)
328+
if (stateCounts[(int)ParserState.ResolvingDeclarations] > 0)
329+
{
330+
result = ParserState.ResolvingDeclarations;
331+
}
332+
if (stateCounts[(int)ParserState.ResolvingReferences] > 0)
327333
{
328-
result = ParserState.Resolving;
334+
result = ParserState.ResolvingReferences;
329335
}
330336

331337
if (result == ParserState.Ready)

0 commit comments

Comments
 (0)