未验证 提交 345ee8ef 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #35483 from sharwell/analyzer-patterns

Update analyzers to follow recommended patterns
......@@ -32,6 +32,12 @@
<!-- DiagnosticId must be unique across analyzers - suppress for non-shipping/test projects -->
<Rule Id="RS1019" Action="None" />
<!-- Configure generated code analysis - suppress for non-shipping/test projects -->
<Rule Id="RS1025" Action="None" />
<!-- Enable concurrent execution - suppress for non-shipping/test projects -->
<Rule Id="RS1026" Action="None" />
<!-- Do not use generic CodeAction.Create to create CodeAction - not useful for tests -->
<Rule Id="RS0005" Action="None" />
</Rules>
......
......@@ -35,6 +35,9 @@ public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
public sealed override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(c =>
{
var analyzer = new CompilationAnalyzer(c.Compilation);
......
......@@ -26,8 +26,14 @@ public DiagnosticAnalyzerCategory GetAnalyzerCategory()
public bool OpenFileOnly(Workspace workspace)
=> true;
#pragma warning disable RS1026 // Enable concurrent execution
public override void Initialize(AnalysisContext context)
=> context.RegisterSyntaxTreeAction(AnalyzeSyntaxTree);
#pragma warning restore RS1026 // Enable concurrent execution
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterSyntaxTreeAction(AnalyzeSyntaxTree);
}
private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
{
......
......@@ -20,7 +20,11 @@ internal abstract class DocumentDiagnosticAnalyzer : DiagnosticAnalyzer
/// <summary>
/// it is not allowed one to implement both DocumentDiagnosticAnalzyer and DiagnosticAnalyzer
/// </summary>
#pragma warning disable RS1026 // Enable concurrent execution
#pragma warning disable RS1025 // Configure generated code analysis
public sealed override void Initialize(AnalysisContext context)
#pragma warning restore RS1025 // Configure generated code analysis
#pragma warning restore RS1026 // Enable concurrent execution
{
}
......
......@@ -18,7 +18,11 @@ internal abstract class ProjectDiagnosticAnalyzer : DiagnosticAnalyzer
/// <summary>
/// it is not allowed one to implement both ProjectDiagnosticAnalzyer and DiagnosticAnalyzer
/// </summary>
#pragma warning disable RS1026 // Enable concurrent execution
#pragma warning disable RS1025 // Configure generated code analysis
public sealed override void Initialize(AnalysisContext context)
#pragma warning restore RS1025 // Configure generated code analysis
#pragma warning restore RS1026 // Enable concurrent execution
{
}
......
......@@ -26,6 +26,7 @@ internal abstract class UnboundIdentifiersDiagnosticAnalyzerBase<TLanguageKindEn
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterSyntaxNodeAction(AnalyzeNode, this.SyntaxKindsOfInterest.ToArray());
}
......
......@@ -53,6 +53,9 @@ public bool OpenFileOnly(Workspace workspace)
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
foreach (var analyzer in _analyzers)
{
analyzer.Initialize(context);
......
......@@ -73,6 +73,7 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterSemanticModelAction(this.AnalyzeSemanticModel);
}
......
......@@ -65,6 +65,7 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(startContext =>
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册