Skip to content

Commit 427ff25

Browse files
committed
fixed state-reporting (breaks 12 tests that involve identifier references of declarations in another module)
1 parent 9376e0b commit 427ff25

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,30 @@ public void SetModuleState(VBComponent component, ParserState state, SyntaxError
144144
Status = EvaluateParserState();
145145
}
146146

147-
//private static readonly ParserState[] States = Enum.GetValues(typeof(ParserState)).Cast<ParserState>().ToArray();
147+
private static readonly ParserState[] States = Enum.GetValues(typeof(ParserState)).Cast<ParserState>().ToArray();
148148
private ParserState EvaluateParserState()
149149
{
150150
var moduleStates = _moduleStates.Values.ToList();
151+
if (States.Any(state => moduleStates.All(module => module == state)))
152+
{
153+
// all modules have the same state - we're done here:
154+
return moduleStates.First();
155+
}
156+
157+
if (moduleStates.Any(module => module > ParserState.Ready)) // only states beyond "ready" are error states
158+
{
159+
// any error state seals the deal:
160+
return moduleStates.Max();
161+
}
151162

152-
var prelim = moduleStates.Max();
153-
if (prelim == ParserState.Parsed && moduleStates.Any(s => s != ParserState.Parsed))
163+
if (moduleStates.Any(module => module != ParserState.Ready))
154164
{
155-
prelim = moduleStates.Where(s => s != ParserState.Parsed).Max();
165+
// any module not ready means at least one of them has work in progress;
166+
// report the least advanced of them, except if that's 'Pending':
167+
return moduleStates.Except(new[]{ParserState.Pending}).Min();
156168
}
157-
return prelim;
169+
170+
return default(ParserState); // default value is 'Pending'.
158171
}
159172

160173
public ParserState GetModuleState(VBComponent component)

0 commit comments

Comments
 (0)