@@ -8,31 +8,42 @@ namespace StyleCop.Analyzers
88 using System ;
99 using System . Collections . Concurrent ;
1010 using System . Collections . Immutable ;
11- using System . Diagnostics . CodeAnalysis ;
1211 using Microsoft . CodeAnalysis ;
1312 using Microsoft . CodeAnalysis . Diagnostics ;
13+ using StyleCop . Analyzers . Helpers ;
1414 using StyleCop . Analyzers . Settings . ObjectModel ;
1515
1616 /// <summary>
1717 /// Provides extension methods to deal for analyzers.
1818 /// </summary>
1919 internal static class AnalyzerExtensions
2020 {
21+ public static void RegisterCompilationStartActionWithSettings ( this AnalysisContext context , Action < CompilationStartAnalysisContextWithSettings > action )
22+ {
23+ context . RegisterCompilationStartAction ( context =>
24+ {
25+ var settingsFile = context . GetStyleCopSettingsFile ( context . CancellationToken ) ;
26+ var settingsObjectCache = context . Compilation . GetOrCreateStyleCopSettingsCache ( ) ;
27+ var contextWithSettings = new CompilationStartAnalysisContextWithSettings ( context , settingsFile , settingsObjectCache ) ;
28+ action ( contextWithSettings ) ;
29+ } ) ;
30+ }
31+
2132 /// <summary>
2233 /// Register an action to be executed at completion of parsing of a code document. A syntax tree action reports
2334 /// diagnostics about the <see cref="SyntaxTree"/> of a document.
2435 /// </summary>
2536 /// <param name="context">The analysis context.</param>
2637 /// <param name="action">Action to be executed at completion of parsing of a document.</param>
27- [ SuppressMessage ( "MicrosoftCodeAnalysisPerformance" , "RS1012:Start action has no registered actions" , Justification = "This is not a start action" ) ]
28- public static void RegisterSyntaxTreeAction ( this CompilationStartAnalysisContext context , Action < SyntaxTreeAnalysisContext , StyleCopSettings > action )
38+ public static void RegisterSyntaxTreeAction ( this CompilationStartAnalysisContextWithSettings context , Action < SyntaxTreeAnalysisContext , StyleCopSettings > action )
2939 {
30- var settingsFile = context . GetStyleCopSettingsFile ( context . CancellationToken ) ;
40+ var settingsFile = context . SettingsFile ;
41+ var settingsObjectCache = context . SettingsObjectCache ;
3142
32- context . RegisterSyntaxTreeAction (
43+ context . InnerContext . RegisterSyntaxTreeAction (
3344 context =>
3445 {
35- StyleCopSettings settings = context . GetStyleCopSettings ( settingsFile ) ;
46+ StyleCopSettings settings = context . GetStyleCopSettings ( settingsFile , settingsObjectCache ) ;
3647 action ( context , settings ) ;
3748 } ) ;
3849 }
@@ -48,7 +59,7 @@ public static void RegisterSyntaxTreeAction(this CompilationStartAnalysisContext
4859 /// <param name="syntaxKind">The kind of syntax that should be analyzed.</param>
4960 /// <typeparam name="TLanguageKindEnum">Enum type giving the syntax node kinds of the source language for which
5061 /// the action applies.</typeparam>
51- public static void RegisterSyntaxNodeAction < TLanguageKindEnum > ( this CompilationStartAnalysisContext context , Action < SyntaxNodeAnalysisContext , StyleCopSettings > action , TLanguageKindEnum syntaxKind )
62+ public static void RegisterSyntaxNodeAction < TLanguageKindEnum > ( this CompilationStartAnalysisContextWithSettings context , Action < SyntaxNodeAnalysisContext , StyleCopSettings > action , TLanguageKindEnum syntaxKind )
5263 where TLanguageKindEnum : struct
5364 {
5465 context . RegisterSyntaxNodeAction ( action , LanguageKindArrays < TLanguageKindEnum > . GetOrCreateArray ( syntaxKind ) ) ;
@@ -65,21 +76,55 @@ public static void RegisterSyntaxNodeAction<TLanguageKindEnum>(this CompilationS
6576 /// <param name="syntaxKinds">The kinds of syntax that should be analyzed.</param>
6677 /// <typeparam name="TLanguageKindEnum">Enum type giving the syntax node kinds of the source language for which
6778 /// the action applies.</typeparam>
68- [ SuppressMessage ( "MicrosoftCodeAnalysisPerformance" , "RS1012:Start action has no registered actions" , Justification = "This is not a start action" ) ]
69- public static void RegisterSyntaxNodeAction < TLanguageKindEnum > ( this CompilationStartAnalysisContext context , Action < SyntaxNodeAnalysisContext , StyleCopSettings > action , ImmutableArray < TLanguageKindEnum > syntaxKinds )
79+ public static void RegisterSyntaxNodeAction < TLanguageKindEnum > ( this CompilationStartAnalysisContextWithSettings context , Action < SyntaxNodeAnalysisContext , StyleCopSettings > action , ImmutableArray < TLanguageKindEnum > syntaxKinds )
7080 where TLanguageKindEnum : struct
7181 {
72- var settingsFile = context . GetStyleCopSettingsFile ( context . CancellationToken ) ;
82+ var settingsFile = context . SettingsFile ;
83+ var settingsObjectCache = context . SettingsObjectCache ;
7384
74- context . RegisterSyntaxNodeAction (
85+ context . InnerContext . RegisterSyntaxNodeAction (
7586 context =>
7687 {
77- StyleCopSettings settings = context . GetStyleCopSettings ( settingsFile ) ;
88+ StyleCopSettings settings = context . GetStyleCopSettings ( settingsFile , settingsObjectCache ) ;
7889 action ( context , settings ) ;
7990 } ,
8091 syntaxKinds ) ;
8192 }
8293
94+ /// <summary>
95+ /// Register an action to be executed at completion of semantic analysis of a <see cref="SyntaxNode"/> with an
96+ /// appropriate kind. A syntax node action can report diagnostics about a <see cref="SyntaxNode"/>, and can also
97+ /// collect state information to be used by other syntax node actions or code block end actions.
98+ /// </summary>
99+ /// <param name="context">The analysis context.</param>
100+ /// <param name="action">Action to be executed at completion of semantic analysis of a
101+ /// <see cref="SyntaxNode"/>.</param>
102+ /// <param name="syntaxKind">The kind of syntax that should be analyzed.</param>
103+ /// <typeparam name="TLanguageKindEnum">Enum type giving the syntax node kinds of the source language for which
104+ /// the action applies.</typeparam>
105+ public static void RegisterSyntaxNodeAction < TLanguageKindEnum > ( this CompilationStartAnalysisContextWithSettings context , Action < SyntaxNodeAnalysisContext > action , TLanguageKindEnum syntaxKind )
106+ where TLanguageKindEnum : struct
107+ {
108+ context . RegisterSyntaxNodeAction ( action , LanguageKindArrays < TLanguageKindEnum > . GetOrCreateArray ( syntaxKind ) ) ;
109+ }
110+
111+ /// <summary>
112+ /// Register an action to be executed at completion of semantic analysis of a <see cref="SyntaxNode"/> with an
113+ /// appropriate kind. A syntax node action can report diagnostics about a <see cref="SyntaxNode"/>, and can also
114+ /// collect state information to be used by other syntax node actions or code block end actions.
115+ /// </summary>
116+ /// <param name="context">The analysis context.</param>
117+ /// <param name="action">Action to be executed at completion of semantic analysis of a
118+ /// <see cref="SyntaxNode"/>.</param>
119+ /// <param name="syntaxKinds">The kinds of syntax that should be analyzed.</param>
120+ /// <typeparam name="TLanguageKindEnum">Enum type giving the syntax node kinds of the source language for which
121+ /// the action applies.</typeparam>
122+ public static void RegisterSyntaxNodeAction < TLanguageKindEnum > ( this CompilationStartAnalysisContextWithSettings context , Action < SyntaxNodeAnalysisContext > action , ImmutableArray < TLanguageKindEnum > syntaxKinds )
123+ where TLanguageKindEnum : struct
124+ {
125+ context . InnerContext . RegisterSyntaxNodeAction ( action , syntaxKinds ) ;
126+ }
127+
83128 private static class LanguageKindArrays < TLanguageKindEnum >
84129 where TLanguageKindEnum : struct
85130 {
0 commit comments