Skip to content

Commit 08588cd

Browse files
authored
Merge pull request #3416 from sharwell/update-compiler
Update to Roslyn 4, .NET SDK 6.0.100
2 parents 6751a39 + 483b3a9 commit 08588cd

File tree

6 files changed

+34
-29
lines changed

6 files changed

+34
-29
lines changed

StyleCop.Analyzers/Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</PropertyGroup>
1111

1212
<PropertyGroup>
13-
<LangVersion>9</LangVersion>
14-
<WarningLevel>5</WarningLevel>
13+
<LangVersion>10</LangVersion>
14+
<WarningLevel>99</WarningLevel>
1515
</PropertyGroup>
1616

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

5353
<!-- C# Compiler -->
5454
<ItemGroup>
55-
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.8.0" PrivateAssets="all" />
55+
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.1" PrivateAssets="all" />
5656
</ItemGroup>
5757

5858
<!-- Public API -->

StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ namespace StyleCop.Analyzers.CodeGeneration
1919
using Microsoft.CodeAnalysis.Text;
2020

2121
[Generator]
22-
internal sealed class OperationLightupGenerator : ISourceGenerator
22+
internal sealed class OperationLightupGenerator : IIncrementalGenerator
2323
{
24-
public void Initialize(GeneratorInitializationContext context)
24+
public void Initialize(IncrementalGeneratorInitializationContext context)
2525
{
26+
var operationInterfacesFiles = context.AdditionalTextsProvider.Where(static x => Path.GetFileName(x.Path) == "OperationInterfaces.xml");
27+
context.RegisterSourceOutput(operationInterfacesFiles, this.Execute);
2628
}
2729

28-
public void Execute(GeneratorExecutionContext context)
30+
private void Execute(SourceProductionContext context, AdditionalText operationInterfacesFile)
2931
{
30-
var operationInterfacesFile = context.AdditionalFiles.Single(x => Path.GetFileName(x.Path) == "OperationInterfaces.xml");
3132
var operationInterfacesText = operationInterfacesFile.GetText(context.CancellationToken);
3233
if (operationInterfacesText is null)
3334
{
@@ -38,7 +39,7 @@ public void Execute(GeneratorExecutionContext context)
3839
this.GenerateOperationInterfaces(in context, operationInterfaces);
3940
}
4041

41-
private void GenerateOperationInterfaces(in GeneratorExecutionContext context, XDocument operationInterfaces)
42+
private void GenerateOperationInterfaces(in SourceProductionContext context, XDocument operationInterfaces)
4243
{
4344
var tree = operationInterfaces.XPathSelectElement("/Tree");
4445
if (tree is null)
@@ -56,7 +57,7 @@ private void GenerateOperationInterfaces(in GeneratorExecutionContext context, X
5657
this.GenerateOperationKindEx(in context, documentData.Interfaces.Values.ToImmutableArray());
5758
}
5859

59-
private void GenerateOperationInterface(in GeneratorExecutionContext context, InterfaceData node)
60+
private void GenerateOperationInterface(in SourceProductionContext context, InterfaceData node)
6061
{
6162
var members = SyntaxFactory.List<MemberDeclarationSyntax>();
6263

@@ -581,7 +582,7 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In
581582
context.AddSource(node.WrapperName + ".g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8));
582583
}
583584

584-
private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context, ImmutableArray<InterfaceData> wrapperTypes)
585+
private void GenerateOperationWrapperHelper(in SourceProductionContext context, ImmutableArray<InterfaceData> wrapperTypes)
585586
{
586587
// private static readonly ImmutableDictionary<Type, Type> WrappedTypes;
587588
var wrappedTypes = SyntaxFactory.FieldDeclaration(
@@ -789,7 +790,7 @@ private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context
789790
context.AddSource("OperationWrapperHelper.g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8));
790791
}
791792

792-
private void GenerateOperationKindEx(in GeneratorExecutionContext context, ImmutableArray<InterfaceData> wrapperTypes)
793+
private void GenerateOperationKindEx(in SourceProductionContext context, ImmutableArray<InterfaceData> wrapperTypes)
793794
{
794795
var operationKinds = wrapperTypes
795796
.SelectMany(type => type.OperationKinds)

StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
19+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
2020
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
2121
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[3.1.0]" />
2222
</ItemGroup>

StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace StyleCop.Analyzers.CodeGeneration
1919
using Microsoft.CodeAnalysis.Text;
2020

2121
[Generator]
22-
internal sealed class SyntaxLightupGenerator : ISourceGenerator
22+
internal sealed class SyntaxLightupGenerator : IIncrementalGenerator
2323
{
2424
private enum NodeKind
2525
{
@@ -28,33 +28,37 @@ private enum NodeKind
2828
Concrete,
2929
}
3030

31-
public void Initialize(GeneratorInitializationContext context)
31+
public void Initialize(IncrementalGeneratorInitializationContext context)
3232
{
33+
var compilation = context.CompilationProvider;
34+
var syntaxFiles = context.AdditionalTextsProvider.Where(static x => Path.GetFileName(x.Path) == "Syntax.xml");
35+
context.RegisterSourceOutput(
36+
syntaxFiles.Combine(compilation),
37+
(context, value) => this.Execute(in context, value.Right, value.Left));
3338
}
3439

35-
public void Execute(GeneratorExecutionContext context)
40+
private void Execute(in SourceProductionContext context, Compilation compilation, AdditionalText syntaxFile)
3641
{
37-
var syntaxFile = context.AdditionalFiles.Single(x => Path.GetFileName(x.Path) == "Syntax.xml");
3842
var syntaxText = syntaxFile.GetText(context.CancellationToken);
3943
if (syntaxText is null)
4044
{
4145
throw new InvalidOperationException("Failed to read Syntax.xml");
4246
}
4347

44-
var syntaxData = new SyntaxData(in context, XDocument.Parse(syntaxText.ToString()));
48+
var syntaxData = new SyntaxData(compilation, XDocument.Parse(syntaxText.ToString()));
4549
this.GenerateSyntaxWrappers(in context, syntaxData);
4650
this.GenerateSyntaxWrapperHelper(in context, syntaxData.Nodes);
4751
}
4852

49-
private void GenerateSyntaxWrappers(in GeneratorExecutionContext context, SyntaxData syntaxData)
53+
private void GenerateSyntaxWrappers(in SourceProductionContext context, SyntaxData syntaxData)
5054
{
5155
foreach (var node in syntaxData.Nodes)
5256
{
5357
this.GenerateSyntaxWrapper(in context, syntaxData, node);
5458
}
5559
}
5660

57-
private void GenerateSyntaxWrapper(in GeneratorExecutionContext context, SyntaxData syntaxData, NodeData nodeData)
61+
private void GenerateSyntaxWrapper(in SourceProductionContext context, SyntaxData syntaxData, NodeData nodeData)
5862
{
5963
if (nodeData.WrapperName is null)
6064
{
@@ -806,7 +810,7 @@ private void GenerateSyntaxWrapper(in GeneratorExecutionContext context, SyntaxD
806810
context.AddSource(nodeData.WrapperName + ".g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8));
807811
}
808812

809-
private void GenerateSyntaxWrapperHelper(in GeneratorExecutionContext context, ImmutableArray<NodeData> wrapperTypes)
813+
private void GenerateSyntaxWrapperHelper(in SourceProductionContext context, ImmutableArray<NodeData> wrapperTypes)
810814
{
811815
// private static readonly ImmutableDictionary<Type, Type> WrappedTypes;
812816
var wrappedTypes = SyntaxFactory.FieldDeclaration(
@@ -1138,12 +1142,12 @@ private sealed class SyntaxData
11381142
{
11391143
private readonly Dictionary<string, NodeData> nameToNode;
11401144

1141-
public SyntaxData(in GeneratorExecutionContext context, XDocument document)
1145+
public SyntaxData(Compilation compilation, XDocument document)
11421146
{
11431147
var nodesBuilder = ImmutableArray.CreateBuilder<NodeData>();
11441148
foreach (var element in document.XPathSelectElement("/Tree[@Root='SyntaxNode']").XPathSelectElements("PredefinedNode|AbstractNode|Node"))
11451149
{
1146-
nodesBuilder.Add(new NodeData(in context, element));
1150+
nodesBuilder.Add(new NodeData(compilation, element));
11471151
}
11481152

11491153
this.Nodes = nodesBuilder.ToImmutable();
@@ -1180,7 +1184,7 @@ public SyntaxData(in GeneratorExecutionContext context, XDocument document)
11801184

11811185
private sealed class NodeData
11821186
{
1183-
public NodeData(in GeneratorExecutionContext context, XElement element)
1187+
public NodeData(Compilation compilation, XElement element)
11841188
{
11851189
this.Kind = element.Name.LocalName switch
11861190
{
@@ -1192,9 +1196,9 @@ public NodeData(in GeneratorExecutionContext context, XElement element)
11921196

11931197
this.Name = element.Attribute("Name").Value;
11941198

1195-
this.ExistingType = context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.Syntax.{this.Name}")
1196-
?? context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.{this.Name}")
1197-
?? context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.{this.Name}");
1199+
this.ExistingType = compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.Syntax.{this.Name}")
1200+
?? compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.{this.Name}")
1201+
?? compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.{this.Name}");
11981202
if (this.ExistingType?.DeclaredAccessibility == Accessibility.Public)
11991203
{
12001204
this.WrapperName = null;

StyleCopAnalyzers.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.1.31907.60
5-
MinimumVisualStudioVersion = 10.0.40219.1
5+
MinimumVisualStudioVersion = 17.0.31903.59
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StyleCop.Analyzers", "StyleCop.Analyzers\StyleCop.Analyzers\StyleCop.Analyzers.csproj", "{3B052737-06CE-4182-AE0F-08EB82DFA73E}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{E359E48C-93DA-4C17-AA0E-94D4831BE5AB}"

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "3.1.401",
3+
"version": "6.0.100",
44
"rollForward": "feature"
55
}
66
}

0 commit comments

Comments
 (0)