@@ -64,7 +64,7 @@ public sealed class RubberduckParserState : IDisposable
64
64
public event EventHandler < ParseRequestEventArgs > ParseRequest ;
65
65
public event EventHandler < RubberduckStatusMessageEventArgs > StatusMessageUpdate ;
66
66
67
- private static readonly Logger _logger = LogManager . GetCurrentClassLogger ( ) ;
67
+ private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
68
68
69
69
public void OnStatusMessageUpdate ( string message )
70
70
{
@@ -129,7 +129,7 @@ public IReadOnlyList<Tuple<VBComponent, SyntaxErrorException>> ModuleExceptions
129
129
return _moduleStates . Select ( kvp => Tuple . Create ( kvp . Key . Component , kvp . Value . ModuleException ) )
130
130
. Where ( item => item . Item2 != null )
131
131
. ToList ( ) ;
132
- }
132
+ }
133
133
}
134
134
135
135
public event EventHandler < ParserStateEventArgs > StateChanged ;
@@ -154,26 +154,12 @@ private void OnModuleStateChanged(VBComponent component, ParserState state)
154
154
}
155
155
}
156
156
157
- public void SetModuleState ( ParserState state )
158
- {
159
- var projects = Projects
160
- . Where ( project => project . Protection == vbext_ProjectProtection . vbext_pp_none )
161
- . ToList ( ) ;
162
-
163
- var components = projects . SelectMany ( p => p . VBComponents . Cast < VBComponent > ( ) ) . ToList ( ) ;
164
- foreach ( var component in components )
165
- {
166
- SetModuleState ( component , state ) ;
167
- }
168
- }
169
-
170
157
public void SetModuleState ( VBComponent component , ParserState state , SyntaxErrorException parserError = null )
171
158
{
172
159
if ( AllUserDeclarations . Any ( ) )
173
160
{
174
161
var projectId = component . Collection . Parent . HelpFile ;
175
- var project = AllUserDeclarations . SingleOrDefault ( item =>
176
- item . DeclarationType == DeclarationType . Project && item . ProjectId == projectId ) ;
162
+ var project = _projects . SingleOrDefault ( item => item . Value ( ) . HelpFile == projectId ) . Value ( ) ;
177
163
178
164
if ( project == null )
179
165
{
@@ -187,7 +173,7 @@ public void SetModuleState(VBComponent component, ParserState state, SyntaxError
187
173
188
174
_moduleStates . AddOrUpdate ( key , new ModuleState ( state ) , ( c , e ) => e . SetState ( state ) ) ;
189
175
_moduleStates . AddOrUpdate ( key , new ModuleState ( parserError ) , ( c , e ) => e . SetModuleException ( parserError ) ) ;
190
- _logger . Debug ( "Module '{0}' state is changing to '{1}' (thread {2})" , key . ComponentName , state , Thread . CurrentThread . ManagedThreadId ) ;
176
+ Logger . Debug ( "Module '{0}' state is changing to '{1}' (thread {2})" , key . ComponentName , state , Thread . CurrentThread . ManagedThreadId ) ;
191
177
OnModuleStateChanged ( component , state ) ;
192
178
Status = EvaluateParserState ( ) ;
193
179
}
@@ -214,20 +200,20 @@ private ParserState EvaluateParserState()
214
200
if ( state != default ( ParserState ) )
215
201
{
216
202
// if all modules are in the same state, we have our result.
217
- _logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , state , Thread . CurrentThread . ManagedThreadId ) ;
203
+ Logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , state , Thread . CurrentThread . ManagedThreadId ) ;
218
204
return state ;
219
205
}
220
206
221
207
// error state takes precedence over every other state
222
208
if ( moduleStates . Any ( ms => ms == ParserState . Error ) )
223
209
{
224
- _logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , ParserState . Error ,
210
+ Logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , ParserState . Error ,
225
211
Thread . CurrentThread . ManagedThreadId ) ;
226
212
return ParserState . Error ;
227
213
}
228
214
if ( moduleStates . Any ( ms => ms == ParserState . ResolverError ) )
229
215
{
230
- _logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , ParserState . ResolverError ,
216
+ Logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , ParserState . ResolverError ,
231
217
Thread . CurrentThread . ManagedThreadId ) ;
232
218
return ParserState . ResolverError ;
233
219
}
@@ -250,7 +236,7 @@ private ParserState EvaluateParserState()
250
236
251
237
Debug . Assert ( result != ParserState . Ready || moduleStates . All ( item => item == ParserState . Ready || item == ParserState . None ) ) ;
252
238
253
- _logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , result ,
239
+ Logger . Debug ( "ParserState evaluates to '{0}' (thread {1})" , result ,
254
240
Thread . CurrentThread . ManagedThreadId ) ;
255
241
return result ;
256
242
}
@@ -283,12 +269,12 @@ public ParserState GetModuleState(VBComponent component)
283
269
public ParserState Status
284
270
{
285
271
get { return _status ; }
286
- internal set
272
+ private set
287
273
{
288
274
if ( _status != value )
289
275
{
290
276
_status = value ;
291
- _logger . Debug ( "ParserState changed to '{0}', raising OnStateChanged" , value ) ;
277
+ Logger . Debug ( "ParserState changed to '{0}', raising OnStateChanged" , value ) ;
292
278
OnStateChanged ( _status ) ;
293
279
}
294
280
}
@@ -401,12 +387,12 @@ public void AddDeclaration(Declaration declaration)
401
387
byte _ ;
402
388
while ( ! declarations . TryRemove ( declaration , out _ ) )
403
389
{
404
- _logger . Debug ( "Could not remove existing declaration for '{0}' ({1}). Retrying." , declaration . IdentifierName , declaration . DeclarationType ) ;
390
+ Logger . Debug ( "Could not remove existing declaration for '{0}' ({1}). Retrying." , declaration . IdentifierName , declaration . DeclarationType ) ;
405
391
}
406
392
}
407
393
while ( ! declarations . TryAdd ( declaration , 0 ) && ! declarations . ContainsKey ( declaration ) )
408
394
{
409
- _logger . Debug ( "Could not add declaration '{0}' ({1}). Retrying." , declaration . IdentifierName , declaration . DeclarationType ) ;
395
+ Logger . Debug ( "Could not add declaration '{0}' ({1}). Retrying." , declaration . IdentifierName , declaration . DeclarationType ) ;
410
396
}
411
397
}
412
398
@@ -465,7 +451,7 @@ public bool ClearStateCache(VBComponent component, bool notifyStateChanged = fal
465
451
}
466
452
467
453
_projects . Remove ( projectId ) ;
468
- _logger . Debug ( "Removed Project declaration for project Id {0}" , projectId ) ;
454
+ Logger . Debug ( "Removed Project declaration for project Id {0}" , projectId ) ;
469
455
}
470
456
471
457
if ( notifyStateChanged )
@@ -610,7 +596,7 @@ public bool IsNewOrModified(QualifiedModuleName key)
610
596
611
597
private QualifiedSelection _lastSelection ;
612
598
private Declaration _selectedDeclaration ;
613
- private List < Tuple < Declaration , Selection , QualifiedModuleName > > _declarationSelections = new List < Tuple < Declaration , Selection , QualifiedModuleName > > ( ) ;
599
+ private readonly List < Tuple < Declaration , Selection , QualifiedModuleName > > _declarationSelections = new List < Tuple < Declaration , Selection , QualifiedModuleName > > ( ) ;
614
600
615
601
public void RebuildSelectionCache ( )
616
602
{
@@ -625,7 +611,6 @@ public void RebuildSelectionCache()
625
611
626
612
public Declaration FindSelectedDeclaration ( CodePane activeCodePane , bool procedureLevelOnly = false )
627
613
{
628
-
629
614
var selection = activeCodePane . GetQualifiedSelection ( ) ;
630
615
if ( selection . Equals ( _lastSelection ) )
631
616
{
@@ -642,7 +627,7 @@ public Declaration FindSelectedDeclaration(CodePane activeCodePane, bool procedu
642
627
643
628
if ( ! selection . Equals ( default ( QualifiedSelection ) ) )
644
629
{
645
- List < Tuple < Declaration , Selection , QualifiedModuleName > > matches = new List < Tuple < Declaration , Selection , QualifiedModuleName > > ( ) ;
630
+ List < Tuple < Declaration , Selection , QualifiedModuleName > > matches ;
646
631
lock ( _declarationSelections )
647
632
{
648
633
matches = _declarationSelections . Where ( t =>
@@ -694,30 +679,18 @@ public Declaration FindSelectedDeclaration(CodePane activeCodePane, bool procedu
694
679
}
695
680
catch ( InvalidOperationException exception )
696
681
{
697
- _logger . Error ( exception ) ;
682
+ Logger . Error ( exception ) ;
698
683
}
699
684
}
700
685
701
686
if ( _selectedDeclaration != null )
702
687
{
703
- _logger . Debug ( "Current selection ({0}) is '{1}' ({2})" , selection , _selectedDeclaration . IdentifierName , _selectedDeclaration . DeclarationType ) ;
688
+ Logger . Debug ( "Current selection ({0}) is '{1}' ({2})" , selection , _selectedDeclaration . IdentifierName , _selectedDeclaration . DeclarationType ) ;
704
689
}
705
690
706
691
return _selectedDeclaration ;
707
692
}
708
693
709
- private static bool IsSelectedDeclaration ( QualifiedSelection selection , Declaration declaration )
710
- {
711
- return declaration . QualifiedSelection . QualifiedName . Equals ( selection . QualifiedName )
712
- && ( declaration . QualifiedSelection . Selection . ContainsFirstCharacter ( selection . Selection ) ) ;
713
- }
714
-
715
- private static bool IsSelectedReference ( QualifiedSelection selection , IdentifierReference reference )
716
- {
717
- return reference . QualifiedModuleName . Equals ( selection . QualifiedName )
718
- && reference . Selection . ContainsFirstCharacter ( selection . Selection ) ;
719
- }
720
-
721
694
public void RemoveBuiltInDeclarations ( Reference reference )
722
695
{
723
696
var projectName = reference . Name ;
@@ -730,7 +703,7 @@ public void RemoveBuiltInDeclarations(Reference reference)
730
703
moduleState . Dispose ( ) ;
731
704
}
732
705
733
- _logger . Warn ( "Could not remove declarations for removed reference '{0}' ({1})." , reference . Name , QualifiedModuleName . GetProjectId ( reference ) ) ;
706
+ Logger . Warn ( "Could not remove declarations for removed reference '{0}' ({1})." , reference . Name , QualifiedModuleName . GetProjectId ( reference ) ) ;
734
707
}
735
708
}
736
709
0 commit comments