Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Roslyn 4, .NET SDK 6.0.100 #3416

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions StyleCop.Analyzers/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<PropertyGroup>
<LangVersion>9</LangVersion>
<WarningLevel>5</WarningLevel>
<LangVersion>10</LangVersion>
<WarningLevel>99</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
Expand Down Expand Up @@ -47,12 +47,12 @@
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.304" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

<!-- C# Compiler -->
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

<!-- Public API -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -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<MemberDeclarationSyntax>();

Expand Down Expand Up @@ -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<InterfaceData> wrapperTypes)
private void GenerateOperationWrapperHelper(in SourceProductionContext context, ImmutableArray<InterfaceData> wrapperTypes)
{
// private static readonly ImmutableDictionary<Type, Type> WrappedTypes;
var wrappedTypes = SyntaxFactory.FieldDeclaration(
Expand Down Expand Up @@ -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<InterfaceData> wrapperTypes)
private void GenerateOperationKindEx(in SourceProductionContext context, ImmutableArray<InterfaceData> wrapperTypes)
{
var operationKinds = wrapperTypes
.SelectMany(type => type.OperationKinds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[3.1.0]" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -28,33 +28,37 @@ 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)
{
this.GenerateSyntaxWrapper(in context, syntaxData, node);
}
}

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)
{
Expand Down Expand Up @@ -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<NodeData> wrapperTypes)
private void GenerateSyntaxWrapperHelper(in SourceProductionContext context, ImmutableArray<NodeData> wrapperTypes)
{
// private static readonly ImmutableDictionary<Type, Type> WrappedTypes;
var wrappedTypes = SyntaxFactory.FieldDeclaration(
Expand Down Expand Up @@ -1138,12 +1142,12 @@ private sealed class SyntaxData
{
private readonly Dictionary<string, NodeData> nameToNode;

public SyntaxData(in GeneratorExecutionContext context, XDocument document)
public SyntaxData(Compilation compilation, XDocument document)
{
var nodesBuilder = ImmutableArray.CreateBuilder<NodeData>();
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();
Expand Down Expand Up @@ -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
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion StyleCopAnalyzers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.31907.60
MinimumVisualStudioVersion = 10.0.40219.1
MinimumVisualStudioVersion = 17.0.31903.59
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StyleCop.Analyzers", "StyleCop.Analyzers\StyleCop.Analyzers\StyleCop.Analyzers.csproj", "{3B052737-06CE-4182-AE0F-08EB82DFA73E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{E359E48C-93DA-4C17-AA0E-94D4831BE5AB}"
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.401",
"version": "6.0.100",
"rollForward": "feature"
}
}