diff --git a/StyleCop.Analyzers/Directory.Build.props b/StyleCop.Analyzers/Directory.Build.props
index d3406bd7b..61392099b 100644
--- a/StyleCop.Analyzers/Directory.Build.props
+++ b/StyleCop.Analyzers/Directory.Build.props
@@ -10,8 +10,8 @@
- 9
- 5
+ 10
+ 99
@@ -47,12 +47,12 @@
-
+
-
+
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs
index 2c287c21f..d7f28eeba 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs
@@ -19,15 +19,16 @@ namespace StyleCop.Analyzers.CodeGeneration
using Microsoft.CodeAnalysis.Text;
[Generator]
- internal sealed class OperationLightupGenerator : ISourceGenerator
+ internal sealed class OperationLightupGenerator : IIncrementalGenerator
{
- public void Initialize(GeneratorInitializationContext context)
+ public void Initialize(IncrementalGeneratorInitializationContext context)
{
+ var operationInterfacesFiles = context.AdditionalTextsProvider.Where(static x => Path.GetFileName(x.Path) == "OperationInterfaces.xml");
+ context.RegisterSourceOutput(operationInterfacesFiles, this.Execute);
}
- public void Execute(GeneratorExecutionContext context)
+ private void Execute(SourceProductionContext context, AdditionalText operationInterfacesFile)
{
- var operationInterfacesFile = context.AdditionalFiles.Single(x => Path.GetFileName(x.Path) == "OperationInterfaces.xml");
var operationInterfacesText = operationInterfacesFile.GetText(context.CancellationToken);
if (operationInterfacesText is null)
{
@@ -38,7 +39,7 @@ public void Execute(GeneratorExecutionContext context)
this.GenerateOperationInterfaces(in context, operationInterfaces);
}
- private void GenerateOperationInterfaces(in GeneratorExecutionContext context, XDocument operationInterfaces)
+ private void GenerateOperationInterfaces(in SourceProductionContext context, XDocument operationInterfaces)
{
var tree = operationInterfaces.XPathSelectElement("/Tree");
if (tree is null)
@@ -56,7 +57,7 @@ private void GenerateOperationInterfaces(in GeneratorExecutionContext context, X
this.GenerateOperationKindEx(in context, documentData.Interfaces.Values.ToImmutableArray());
}
- private void GenerateOperationInterface(in GeneratorExecutionContext context, InterfaceData node)
+ private void GenerateOperationInterface(in SourceProductionContext context, InterfaceData node)
{
var members = SyntaxFactory.List();
@@ -581,7 +582,7 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In
context.AddSource(node.WrapperName + ".g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8));
}
- private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context, ImmutableArray wrapperTypes)
+ private void GenerateOperationWrapperHelper(in SourceProductionContext context, ImmutableArray wrapperTypes)
{
// private static readonly ImmutableDictionary WrappedTypes;
var wrappedTypes = SyntaxFactory.FieldDeclaration(
@@ -789,7 +790,7 @@ private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context
context.AddSource("OperationWrapperHelper.g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8));
}
- private void GenerateOperationKindEx(in GeneratorExecutionContext context, ImmutableArray wrapperTypes)
+ private void GenerateOperationKindEx(in SourceProductionContext context, ImmutableArray wrapperTypes)
{
var operationKinds = wrapperTypes
.SelectMany(type => type.OperationKinds)
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj
index 07775f8ca..b36db0eca 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj
@@ -16,7 +16,7 @@
-
+
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs
index dd721d046..abd06fbd5 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs
@@ -19,7 +19,7 @@ namespace StyleCop.Analyzers.CodeGeneration
using Microsoft.CodeAnalysis.Text;
[Generator]
- internal sealed class SyntaxLightupGenerator : ISourceGenerator
+ internal sealed class SyntaxLightupGenerator : IIncrementalGenerator
{
private enum NodeKind
{
@@ -28,25 +28,29 @@ private enum NodeKind
Concrete,
}
- public void Initialize(GeneratorInitializationContext context)
+ public void Initialize(IncrementalGeneratorInitializationContext context)
{
+ var compilation = context.CompilationProvider;
+ var syntaxFiles = context.AdditionalTextsProvider.Where(static x => Path.GetFileName(x.Path) == "Syntax.xml");
+ context.RegisterSourceOutput(
+ syntaxFiles.Combine(compilation),
+ (context, value) => this.Execute(in context, value.Right, value.Left));
}
- public void Execute(GeneratorExecutionContext context)
+ private void Execute(in SourceProductionContext context, Compilation compilation, AdditionalText syntaxFile)
{
- var syntaxFile = context.AdditionalFiles.Single(x => Path.GetFileName(x.Path) == "Syntax.xml");
var syntaxText = syntaxFile.GetText(context.CancellationToken);
if (syntaxText is null)
{
throw new InvalidOperationException("Failed to read Syntax.xml");
}
- var syntaxData = new SyntaxData(in context, XDocument.Parse(syntaxText.ToString()));
+ var syntaxData = new SyntaxData(compilation, XDocument.Parse(syntaxText.ToString()));
this.GenerateSyntaxWrappers(in context, syntaxData);
this.GenerateSyntaxWrapperHelper(in context, syntaxData.Nodes);
}
- private void GenerateSyntaxWrappers(in GeneratorExecutionContext context, SyntaxData syntaxData)
+ private void GenerateSyntaxWrappers(in SourceProductionContext context, SyntaxData syntaxData)
{
foreach (var node in syntaxData.Nodes)
{
@@ -54,7 +58,7 @@ private void GenerateSyntaxWrappers(in GeneratorExecutionContext context, Syntax
}
}
- private void GenerateSyntaxWrapper(in GeneratorExecutionContext context, SyntaxData syntaxData, NodeData nodeData)
+ private void GenerateSyntaxWrapper(in SourceProductionContext context, SyntaxData syntaxData, NodeData nodeData)
{
if (nodeData.WrapperName is null)
{
@@ -806,7 +810,7 @@ private void GenerateSyntaxWrapper(in GeneratorExecutionContext context, SyntaxD
context.AddSource(nodeData.WrapperName + ".g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8));
}
- private void GenerateSyntaxWrapperHelper(in GeneratorExecutionContext context, ImmutableArray wrapperTypes)
+ private void GenerateSyntaxWrapperHelper(in SourceProductionContext context, ImmutableArray wrapperTypes)
{
// private static readonly ImmutableDictionary WrappedTypes;
var wrappedTypes = SyntaxFactory.FieldDeclaration(
@@ -1138,12 +1142,12 @@ private sealed class SyntaxData
{
private readonly Dictionary nameToNode;
- public SyntaxData(in GeneratorExecutionContext context, XDocument document)
+ public SyntaxData(Compilation compilation, XDocument document)
{
var nodesBuilder = ImmutableArray.CreateBuilder();
foreach (var element in document.XPathSelectElement("/Tree[@Root='SyntaxNode']").XPathSelectElements("PredefinedNode|AbstractNode|Node"))
{
- nodesBuilder.Add(new NodeData(in context, element));
+ nodesBuilder.Add(new NodeData(compilation, element));
}
this.Nodes = nodesBuilder.ToImmutable();
@@ -1180,7 +1184,7 @@ public SyntaxData(in GeneratorExecutionContext context, XDocument document)
private sealed class NodeData
{
- public NodeData(in GeneratorExecutionContext context, XElement element)
+ public NodeData(Compilation compilation, XElement element)
{
this.Kind = element.Name.LocalName switch
{
@@ -1192,9 +1196,9 @@ public NodeData(in GeneratorExecutionContext context, XElement element)
this.Name = element.Attribute("Name").Value;
- this.ExistingType = context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.Syntax.{this.Name}")
- ?? context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.{this.Name}")
- ?? context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.{this.Name}");
+ this.ExistingType = compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.Syntax.{this.Name}")
+ ?? compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.{this.Name}")
+ ?? compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.{this.Name}");
if (this.ExistingType?.DeclaredAccessibility == Accessibility.Public)
{
this.WrapperName = null;
diff --git a/global.json b/global.json
index f5bbc7c5d..7bdadf68e 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "3.1.401",
+ "version": "6.0.100",
"rollForward": "feature"
}
}