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

Mark ISourceGenerator as obsolete for implementation #75223

Merged
merged 6 commits into from
Oct 5, 2024
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/features/incremental-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>5535e31a712343a63f5d7d796cd874e563e5ac14</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
<Sha>22ea6422f85b05ca0793cc3b76375487be407f5d</Sha>
<Sha>f2384e61845314d0e8ad74cc0fe67d1bd4e9f102</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.AnalyzerUtilities" Version="3.3.0">
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<SystemThreadingTasksDataflowVersion>8.0.0</SystemThreadingTasksDataflowVersion>
<SystemWindowsExtensionsVersion>8.0.0</SystemWindowsExtensionsVersion>
<MicrosoftBclAsyncInterfacesVersion>8.0.0</MicrosoftBclAsyncInterfacesVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>3.3.4</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>3.11.0</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisAnalyzerUtilitiesVersion>3.3.0</MicrosoftCodeAnalysisAnalyzerUtilitiesVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>8.0.0-preview.23468.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftDiaSymReaderVersion>2.0.0</MicrosoftDiaSymReaderVersion>
Expand Down
2 changes: 2 additions & 0 deletions eng/targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

<!-- https://github.com/dotnet/msbuild/issues/10306 -->
<CoreCompileDependsOn>$(CoreCompileDependsOn);ResolveKeySource</CoreCompileDependsOn>

<NoWarn Condition="'$(DefineConstants.Contains(`CODE_STYLE`))' == 'false'">$(NoWarn);RS1041;RS1038</NoWarn>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)TargetFrameworks.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,13 +20,15 @@ namespace Microsoft.CodeAnalysis
/// is no guarantee that the same instance will be used on a
/// subsequent generation pass.
/// </remarks>
[ImplementationIsObsolete(url: "https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md")]
public interface ISourceGenerator
{
/// <summary>
/// Called before generation occurs. A generator can use the <paramref name="context"/>
/// to register callbacks required to perform generation.
/// </summary>
/// <param name="context">The <see cref="GeneratorInitializationContext"/> to register callbacks on</param>
[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);

/// <summary>
Expand All @@ -42,6 +45,7 @@ public interface ISourceGenerator
/// discover information about the users compilation and make decisions on what source to
/// provide.
/// </remarks>
[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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -801,13 +803,15 @@ End Class
_initialized = True
End Sub

#Disable Warning BC40000
Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize
_sourceInitialized = True
End Sub

Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute
_sourceExecuted = True
End Sub
#Enable Warning BC40000

End Class

Expand Down
2 changes: 2 additions & 0 deletions src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ public override Task<ImmutableArray<Diagnostic>> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }

Expand Down
2 changes: 2 additions & 0 deletions src/Workspaces/TestAnalyzerReference/HelloWorldGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading