@@ -50,23 +50,23 @@ public sealed class RubberduckParserState
50
50
private readonly ConcurrentDictionary < QualifiedModuleName , ConcurrentDictionary < Declaration , byte > > _declarations =
51
51
new ConcurrentDictionary < QualifiedModuleName , ConcurrentDictionary < Declaration , byte > > ( ) ;
52
52
53
- private readonly ConcurrentDictionary < VBComponent , ITokenStream > _tokenStreams =
54
- new ConcurrentDictionary < VBComponent , ITokenStream > ( ) ;
53
+ private readonly ConcurrentDictionary < QualifiedModuleName , ITokenStream > _tokenStreams =
54
+ new ConcurrentDictionary < QualifiedModuleName , ITokenStream > ( ) ;
55
55
56
- private readonly ConcurrentDictionary < VBComponent , IParseTree > _parseTrees =
57
- new ConcurrentDictionary < VBComponent , IParseTree > ( ) ;
56
+ private readonly ConcurrentDictionary < QualifiedModuleName , IParseTree > _parseTrees =
57
+ new ConcurrentDictionary < QualifiedModuleName , IParseTree > ( ) ;
58
58
59
- private readonly ConcurrentDictionary < VBComponent , ParserState > _moduleStates =
60
- new ConcurrentDictionary < VBComponent , ParserState > ( ) ;
59
+ private readonly ConcurrentDictionary < QualifiedModuleName , ParserState > _moduleStates =
60
+ new ConcurrentDictionary < QualifiedModuleName , ParserState > ( ) ;
61
61
62
- private readonly ConcurrentDictionary < VBComponent , IList < CommentNode > > _comments =
63
- new ConcurrentDictionary < VBComponent , IList < CommentNode > > ( ) ;
62
+ private readonly ConcurrentDictionary < QualifiedModuleName , IList < CommentNode > > _comments =
63
+ new ConcurrentDictionary < QualifiedModuleName , IList < CommentNode > > ( ) ;
64
64
65
- private readonly ConcurrentDictionary < VBComponent , SyntaxErrorException > _moduleExceptions =
66
- new ConcurrentDictionary < VBComponent , SyntaxErrorException > ( ) ;
65
+ private readonly ConcurrentDictionary < QualifiedModuleName , SyntaxErrorException > _moduleExceptions =
66
+ new ConcurrentDictionary < QualifiedModuleName , SyntaxErrorException > ( ) ;
67
67
68
- private readonly ConcurrentDictionary < VBComponent , IDictionary < Tuple < string , DeclarationType > , Attributes > > _moduleAttributes =
69
- new ConcurrentDictionary < VBComponent , IDictionary < Tuple < string , DeclarationType > , Attributes > > ( ) ;
68
+ private readonly ConcurrentDictionary < QualifiedModuleName , IDictionary < Tuple < string , DeclarationType > , Attributes > > _moduleAttributes =
69
+ new ConcurrentDictionary < QualifiedModuleName , IDictionary < Tuple < string , DeclarationType > , Attributes > > ( ) ;
70
70
71
71
public void AddProject ( VBProject project )
72
72
{
@@ -90,7 +90,7 @@ public void RemoveProject(VBProject project)
90
90
91
91
public IReadOnlyList < Tuple < VBComponent , SyntaxErrorException > > ModuleExceptions
92
92
{
93
- get { return _moduleExceptions . Select ( kvp => Tuple . Create ( kvp . Key , kvp . Value ) ) . Where ( item => item . Item2 != null ) . ToList ( ) ; }
93
+ get { return _moduleExceptions . Select ( kvp => Tuple . Create ( kvp . Key . Component , kvp . Value ) ) . Where ( item => item . Item2 != null ) . ToList ( ) ; }
94
94
}
95
95
96
96
public event EventHandler < ParserStateEventArgs > StateChanged ;
@@ -117,70 +117,45 @@ private void OnModuleStateChanged(VBComponent component, ParserState state)
117
117
118
118
public void SetModuleState ( VBComponent component , ParserState state , SyntaxErrorException parserError = null )
119
119
{
120
- _moduleStates . AddOrUpdate ( component , state , ( c , s ) => state ) ;
121
- _moduleExceptions . AddOrUpdate ( component , parserError , ( c , e ) => parserError ) ;
120
+ if ( AllUserDeclarations . Any ( ) )
121
+ {
122
+ var projectName = component . ProjectName ( ) ;
123
+ var project = AllUserDeclarations . SingleOrDefault ( item =>
124
+ item . DeclarationType == DeclarationType . Project && item . ProjectName == projectName ) ;
125
+
126
+ if ( project == null )
127
+ {
128
+ // ghost component shouldn't even exist
129
+ ClearDeclarations ( component ) ;
130
+ return ;
131
+ }
132
+ }
133
+ var key = new QualifiedModuleName ( component ) ;
134
+ _moduleStates . AddOrUpdate ( key , state , ( c , s ) => state ) ;
135
+ _moduleExceptions . AddOrUpdate ( key , parserError , ( c , e ) => parserError ) ;
122
136
123
- Debug . WriteLine ( "Module '{0}' state is changing to '{1}' (thread {2})" , component . Name , state , Thread . CurrentThread . ManagedThreadId ) ;
137
+ Debug . WriteLine ( "Module '{0}' state is changing to '{1}' (thread {2})" , key . ComponentName , state , Thread . CurrentThread . ManagedThreadId ) ;
124
138
OnModuleStateChanged ( component , state ) ;
125
139
126
140
Status = EvaluateParserState ( ) ;
127
141
}
128
142
129
- private static readonly ParserState [ ] States = Enum . GetValues ( typeof ( ParserState ) ) . Cast < ParserState > ( ) . ToArray ( ) ;
143
+ // private static readonly ParserState[] States = Enum.GetValues(typeof(ParserState)).Cast<ParserState>().ToArray();
130
144
private ParserState EvaluateParserState ( )
131
145
{
132
146
var moduleStates = _moduleStates . Values . ToList ( ) ;
133
147
134
148
var prelim = moduleStates . Max ( ) ;
135
149
if ( prelim == ParserState . Parsed && moduleStates . Any ( s => s != ParserState . Parsed ) )
136
150
{
137
- prelim = moduleStates . Where ( s => s < ParserState . Parsed ) . Max ( ) ;
151
+ prelim = moduleStates . Where ( s => s != ParserState . Parsed ) . Max ( ) ;
138
152
}
139
153
return prelim ;
140
- //var moduleStates = _moduleStates.Values.ToList();
141
-
142
- //var state = States.SingleOrDefault(value => moduleStates.All(ps => ps == value));
143
- //if (state != default(ParserState))
144
- //{
145
- // // if all modules are in the same state, we have our result.
146
- // Debug.WriteLine("ParserState evaluates to '{0}' (thread {1})", state, Thread.CurrentThread.ManagedThreadId);
147
- // return state;
148
- //}
149
-
150
- //// error state takes precedence over every other state
151
- //if (moduleStates.Any(ms => ms == ParserState.Error))
152
- //{
153
- // Debug.WriteLine("ParserState evaluates to '{0}' (thread {1})", ParserState.Error, Thread.CurrentThread.ManagedThreadId);
154
- // return ParserState.Error;
155
- //}
156
- //if (moduleStates.Any(ms => ms == ParserState.ResolverError))
157
- //{
158
- // Debug.WriteLine("ParserState evaluates to '{0}' (thread {1})", ParserState.ResolverError, Thread.CurrentThread.ManagedThreadId);
159
- // return ParserState.ResolverError;
160
- //}
161
-
162
- //// "working" states are toggled when *any* module has them.
163
- //var result = moduleStates.Min();
164
- //if (moduleStates.Any(ms => ms == ParserState.LoadingReference))
165
- //{
166
- // result = ParserState.LoadingReference;
167
- //}
168
- //if (moduleStates.Any(ms => ms == ParserState.Parsing))
169
- //{
170
- // result = ParserState.Parsing;
171
- //}
172
- //if (moduleStates.Any(ms => ms == ParserState.Resolving))
173
- //{
174
- // result = ParserState.Resolving;
175
- //}
176
-
177
- //// otherwise, return the
178
- //Debug.WriteLine("ParserState evaluates to '{0}' (thread {1})", result, Thread.CurrentThread.ManagedThreadId);
179
- //return result;
180
154
}
155
+
181
156
public ParserState GetModuleState ( VBComponent component )
182
157
{
183
- return _moduleStates . GetOrAdd ( component , ParserState . Pending ) ;
158
+ return _moduleStates . GetOrAdd ( new QualifiedModuleName ( component ) , ParserState . Pending ) ;
184
159
}
185
160
186
161
private ParserState _status ;
@@ -222,7 +197,7 @@ public IEnumerable<QualifiedContext> ObsoleteLetContexts
222
197
223
198
internal void SetModuleAttributes ( VBComponent component , IDictionary < Tuple < string , DeclarationType > , Attributes > attributes )
224
199
{
225
- _moduleAttributes . AddOrUpdate ( component , attributes , ( c , s ) => attributes ) ;
200
+ _moduleAttributes . AddOrUpdate ( new QualifiedModuleName ( component ) , attributes , ( c , s ) => attributes ) ;
226
201
}
227
202
228
203
private IEnumerable < QualifiedContext > _emptyStringLiterals = new List < QualifiedContext > ( ) ;
@@ -254,7 +229,7 @@ public IEnumerable<CommentNode> AllComments
254
229
public IEnumerable < CommentNode > GetModuleComments ( VBComponent component )
255
230
{
256
231
IList < CommentNode > result ;
257
- if ( _comments . TryGetValue ( component , out result ) )
232
+ if ( _comments . TryGetValue ( new QualifiedModuleName ( component ) , out result ) )
258
233
{
259
234
return result ;
260
235
}
@@ -264,7 +239,7 @@ public IEnumerable<CommentNode> GetModuleComments(VBComponent component)
264
239
265
240
public void SetModuleComments ( VBComponent component , IEnumerable < CommentNode > comments )
266
241
{
267
- _comments [ component ] = comments . ToList ( ) ;
242
+ _comments [ new QualifiedModuleName ( component ) ] = comments . ToList ( ) ;
268
243
}
269
244
270
245
/// <summary>
@@ -294,7 +269,7 @@ public IReadOnlyList<Declaration> AllUserDeclarations
294
269
295
270
internal IDictionary < Tuple < string , DeclarationType > , Attributes > getModuleAttributes ( VBComponent vbComponent )
296
271
{
297
- return _moduleAttributes [ vbComponent ] ;
272
+ return _moduleAttributes [ new QualifiedModuleName ( vbComponent ) ] ;
298
273
}
299
274
300
275
/// <summary>
@@ -359,19 +334,19 @@ public bool ClearDeclarations(VBComponent component)
359
334
declarationsRemoved = declarations == null ? 0 : declarations . Count ;
360
335
361
336
IParseTree tree ;
362
- success = success && ( ! _parseTrees . ContainsKey ( key . Component ) || _parseTrees . TryRemove ( key . Component , out tree ) ) ;
337
+ success = success && ( ! _parseTrees . ContainsKey ( key ) || _parseTrees . TryRemove ( key , out tree ) ) ;
363
338
364
339
ITokenStream stream ;
365
- success = success && ( ! _tokenStreams . ContainsKey ( key . Component ) || _tokenStreams . TryRemove ( key . Component , out stream ) ) ;
340
+ success = success && ( ! _tokenStreams . ContainsKey ( key ) || _tokenStreams . TryRemove ( key , out stream ) ) ;
366
341
367
342
ParserState state ;
368
- success = success && ( ! _moduleStates . ContainsKey ( key . Component ) || _moduleStates . TryRemove ( key . Component , out state ) ) ;
343
+ success = success && ( ! _moduleStates . ContainsKey ( key ) || _moduleStates . TryRemove ( key , out state ) ) ;
369
344
370
345
SyntaxErrorException exception ;
371
- success = success && ( ! _moduleExceptions . ContainsKey ( key . Component ) || _moduleExceptions . TryRemove ( key . Component , out exception ) ) ;
346
+ success = success && ( ! _moduleExceptions . ContainsKey ( key ) || _moduleExceptions . TryRemove ( key , out exception ) ) ;
372
347
373
348
IList < CommentNode > nodes ;
374
- success = success && ( ! _comments . ContainsKey ( key . Component ) || _comments . TryRemove ( key . Component , out nodes ) ) ;
349
+ success = success && ( ! _comments . ContainsKey ( key ) || _comments . TryRemove ( key , out nodes ) ) ;
375
350
}
376
351
377
352
Debug . WriteLine ( "ClearDeclarations({0}): {1} - {2} declarations removed" , component . Name , success ? "succeeded" : "failed" , declarationsRemoved ) ;
@@ -380,24 +355,24 @@ public bool ClearDeclarations(VBComponent component)
380
355
381
356
public void AddTokenStream ( VBComponent component , ITokenStream stream )
382
357
{
383
- _tokenStreams [ component ] = stream ;
358
+ _tokenStreams [ new QualifiedModuleName ( component ) ] = stream ;
384
359
}
385
360
386
361
public void AddParseTree ( VBComponent component , IParseTree parseTree )
387
362
{
388
- _parseTrees [ component ] = parseTree ;
363
+ _parseTrees [ new QualifiedModuleName ( component ) ] = parseTree ;
389
364
}
390
365
391
366
public IParseTree GetParseTree ( VBComponent component )
392
367
{
393
- return _parseTrees [ component ] ;
368
+ return _parseTrees [ new QualifiedModuleName ( component ) ] ;
394
369
}
395
370
396
- public IEnumerable < KeyValuePair < VBComponent , IParseTree > > ParseTrees { get { return _parseTrees ; } }
371
+ public IEnumerable < KeyValuePair < QualifiedModuleName , IParseTree > > ParseTrees { get { return _parseTrees ; } }
397
372
398
373
public TokenStreamRewriter GetRewriter ( VBComponent component )
399
374
{
400
- return new TokenStreamRewriter ( _tokenStreams [ component ] ) ;
375
+ return new TokenStreamRewriter ( _tokenStreams [ new QualifiedModuleName ( component ) ] ) ;
401
376
}
402
377
403
378
/// <summary>
0 commit comments