diff --git a/.editorconfig b/.editorconfig index 734314d6db6d7..4c92a8eef97a3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -151,6 +151,9 @@ dotnet_public_api_analyzer.require_api_files = true # Workaround for https://github.com/dotnet/roslyn/issues/70570 dotnet_diagnostic.IDE0055.severity = warning +# https://github.com/dotnet/roslyn-analyzers/issues/7436 - False positives from valid GetDeclaredSymbol calls +dotnet_diagnostic.RS1039.severity = none + # These xUnit analyzers were disabled temporarily to let us move to the # new xUnit and get past several component governance issues. The # following issue tracks enabling them diff --git a/docs/features/incremental-generators.md b/docs/features/incremental-generators.md index 4e312a8f6c1a4..48dc1a9a3eac1 100644 --- a/docs/features/incremental-generators.md +++ b/docs/features/incremental-generators.md @@ -2,8 +2,8 @@ ## Summary -Incremental generators are a new API that exists alongside -[source generators](source-generators.md) to allow users to specify generation +Incremental generators are a new API that replaces +[v1 source generators](source-generators.md) to allow users to specify generation strategies that can be applied in a high performance way by the hosting layer. ### High Level Design Goals diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 7ac36a68f74f8..a225f5b62fca4 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -170,9 +170,9 @@ https://github.com/dotnet/runtime 5535e31a712343a63f5d7d796cd874e563e5ac14 - + https://github.com/dotnet/roslyn-analyzers - 22ea6422f85b05ca0793cc3b76375487be407f5d + f2384e61845314d0e8ad74cc0fe67d1bd4e9f102 https://github.com/dotnet/roslyn-analyzers diff --git a/eng/Versions.props b/eng/Versions.props index 7827ede2a5cf9..373da5382af4f 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 8.0.0 8.0.0 8.0.0 - 3.3.4 + 3.11.0 3.3.0 8.0.0-preview.23468.1 2.0.0 diff --git a/eng/targets/Settings.props b/eng/targets/Settings.props index faafdb4653aa3..f37887bd379ea 100644 --- a/eng/targets/Settings.props +++ b/eng/targets/Settings.props @@ -63,6 +63,8 @@ $(CoreCompileDependsOn);ResolveKeySource + + $(NoWarn);RS1041;RS1038 diff --git a/src/Compilers/Core/Portable/ImplementationIsObsoleteAttribute.cs b/src/Compilers/Core/Portable/ImplementationIsObsoleteAttribute.cs new file mode 100644 index 0000000000000..6c061cbfc7fa3 --- /dev/null +++ b/src/Compilers/Core/Portable/ImplementationIsObsoleteAttribute.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.CompilerServices; + +[AttributeUsage(AttributeTargets.Interface, AllowMultiple = false)] +internal sealed class ImplementationIsObsoleteAttribute(string url) : Attribute +{ + public string Url { get; } = url; +} diff --git a/src/Compilers/Core/Portable/SourceGeneration/GeneratorAdaptor.cs b/src/Compilers/Core/Portable/SourceGeneration/GeneratorAdaptor.cs index 03f390a522bc4..bdc5d8af03308 100644 --- a/src/Compilers/Core/Portable/SourceGeneration/GeneratorAdaptor.cs +++ b/src/Compilers/Core/Portable/SourceGeneration/GeneratorAdaptor.cs @@ -38,7 +38,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) Debug.Assert(_sourceExtension != DummySourceExtension); GeneratorInitializationContext generatorInitContext = new GeneratorInitializationContext(CancellationToken.None); +#pragma warning disable CS0618 // Type or member is obsolete SourceGenerator.Initialize(generatorInitContext); +#pragma warning restore CS0618 // Type or member is obsolete if (generatorInitContext.Callbacks.PostInitCallback is object) { @@ -62,7 +64,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterSourceOutput(contextBuilderSource, (productionContext, contextBuilder) => { var generatorExecutionContext = contextBuilder.ToExecutionContext(_sourceExtension, productionContext.CancellationToken); +#pragma warning disable CS0618 // Type or member is obsolete SourceGenerator.Execute(generatorExecutionContext); +#pragma warning restore CS0618 // Type or member is obsolete // copy the contents of the old context to the new generatorExecutionContext.CopyToProductionContext(productionContext); diff --git a/src/Compilers/Core/Portable/SourceGeneration/ISourceGenerator.cs b/src/Compilers/Core/Portable/SourceGeneration/ISourceGenerator.cs index 574bc4aa234f1..dc4fa4a405fcc 100644 --- a/src/Compilers/Core/Portable/SourceGeneration/ISourceGenerator.cs +++ b/src/Compilers/Core/Portable/SourceGeneration/ISourceGenerator.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Immutable; +using System.Runtime.CompilerServices; using System.Threading; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.PooledObjects; @@ -19,6 +20,7 @@ namespace Microsoft.CodeAnalysis /// is no guarantee that the same instance will be used on a /// subsequent generation pass. /// + [ImplementationIsObsolete(url: "https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md")] public interface ISourceGenerator { /// @@ -26,6 +28,7 @@ public interface ISourceGenerator /// to register callbacks required to perform generation. /// /// The to register callbacks on + [Obsolete("ISourceGenerator is deprecated and should not be implemented. Please implement IIncrementalGenerator instead. See https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md.")] void Initialize(GeneratorInitializationContext context); /// @@ -42,6 +45,7 @@ public interface ISourceGenerator /// discover information about the users compilation and make decisions on what source to /// provide. /// + [Obsolete("ISourceGenerator is deprecated and should not be implemented. Please implement IIncrementalGenerator instead. See https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md.")] void Execute(GeneratorExecutionContext context); } } diff --git a/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb b/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb index fd75ab1e3c6d2..80d12a2bb8338 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb @@ -749,11 +749,13 @@ End Class Public _receiver As Receiver = New Receiver() +#Disable Warning BC40000 Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize context.RegisterForSyntaxNotifications(Function() _receiver) End Sub Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute +#Enable Warning BC40000 context.AddSource("source.vb", " Public Class D End Class @@ -801,6 +803,7 @@ End Class _initialized = True End Sub +#Disable Warning BC40000 Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize _sourceInitialized = True End Sub @@ -808,6 +811,7 @@ End Class Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute _sourceExecuted = True End Sub +#Enable Warning BC40000 End Class diff --git a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs index 9c6350aac0bc6..75005278fd3b5 100644 --- a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs +++ b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs @@ -598,7 +598,9 @@ public override Task> AnalyzeSemanticsAsync(Document } } +#pragma warning disable RS1042 // Do not implement public class MockGenerator : ISourceGenerator +#pragma warning restore RS1042 // Do not implement { private readonly DiagnosticDescriptor s_descriptor = new(MockFixer.Id, "Title", "Message", "Category", DiagnosticSeverity.Warning, isEnabledByDefault: true); diff --git a/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb b/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb index 8ebc28eb5e830..7a5139f94394f 100644 --- a/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb +++ b/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb @@ -75,13 +75,17 @@ public partial class GeneratedClass : IInterface { } End Using End Sub +#Disable Warning RS1042 Private Class GeneratorThatImplementsInterfaceMethod Implements ISourceGenerator +#Enable Warning RS1042 +#Disable Warning BC40000 Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize End Sub Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute +#Enable Warning BC40000 Dim [interface] = context.Compilation.GetTypeByMetadataName("IInterface") Dim memberName = [interface].MemberNames.Single() diff --git a/src/Features/CSharpTest/ConvertToRecord/ConvertToRecordCodeRefactoringTests.cs b/src/Features/CSharpTest/ConvertToRecord/ConvertToRecordCodeRefactoringTests.cs index 816d363193c3f..b49894fab2c4b 100644 --- a/src/Features/CSharpTest/ConvertToRecord/ConvertToRecordCodeRefactoringTests.cs +++ b/src/Features/CSharpTest/ConvertToRecord/ConvertToRecordCodeRefactoringTests.cs @@ -4515,7 +4515,9 @@ public record C(int P, bool B); }.RunAsync(); } +#pragma warning disable RS1042 // Do not implement private sealed class ConvertToRecordTestGenerator : ISourceGenerator +#pragma warning restore RS1042 // Do not implement { public void Initialize(GeneratorInitializationContext context) { } diff --git a/src/Workspaces/TestAnalyzerReference/HelloWorldGenerator.cs b/src/Workspaces/TestAnalyzerReference/HelloWorldGenerator.cs index 8a27eff0aa2e7..181248c79dfa1 100644 --- a/src/Workspaces/TestAnalyzerReference/HelloWorldGenerator.cs +++ b/src/Workspaces/TestAnalyzerReference/HelloWorldGenerator.cs @@ -9,7 +9,9 @@ namespace Microsoft.CodeAnalysis.TestSourceGenerator { [Generator] +#pragma warning disable RS1042 // Do not implement public sealed class HelloWorldGenerator : ISourceGenerator +#pragma warning restore RS1042 // Do not implement { public const string GeneratedEnglishClassName = "HelloWorld"; public const string GeneratedSpanishClassName = "HolaMundo";