From 4cc849f24584e17874679c92bcafe97a1397c061 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 10 Apr 2022 18:06:00 +0200 Subject: [PATCH] Move DiagnosticsExtensions to shared generation project --- .../Diagnostics/DiagnosticsExtensions.cs | 91 ------------------- .../HlslSourceRewriter.Diagnostics.cs | 2 +- .../ComputeSharp.SourceGeneration.projitems | 1 + .../Extensions}/DiagnosticsExtensions.cs | 2 +- ...haderGenerator.CreateLoadBytecodeMethod.cs | 2 +- .../HlslSourceRewriter.Diagnostics.cs | 2 +- 6 files changed, 5 insertions(+), 95 deletions(-) delete mode 100644 src/ComputeSharp.D2D1Interop.SourceGenerators/Diagnostics/DiagnosticsExtensions.cs rename src/{ComputeSharp.SourceGenerators/Diagnostics => ComputeSharp.SourceGeneration/Extensions}/DiagnosticsExtensions.cs (98%) diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/Diagnostics/DiagnosticsExtensions.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/Diagnostics/DiagnosticsExtensions.cs deleted file mode 100644 index ce4a709c..00000000 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/Diagnostics/DiagnosticsExtensions.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System.Collections.Immutable; -using System.Linq; -using Microsoft.CodeAnalysis; - -namespace ComputeSharp.D2D1Interop.SourceGenerators.Diagnostics; - -/// -/// Extension methods for , specifically for reporting diagnostics. -/// -internal static class DiagnosticsExtensions -{ - /// - /// Adds a new diagnostics to the current compilation. - /// - /// The instance currently in use. - /// The input for the diagnostics to create. - /// The source to attach the diagnostics to. - /// The optional arguments for the formatted message to include. - public static void ReportDiagnostic( - this GeneratorExecutionContext context, - DiagnosticDescriptor descriptor, - ISymbol symbol, - params object[] args) - { - context.ReportDiagnostic(Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args)); - } - - /// - /// Adds a new diagnostics to the current compilation. - /// - /// The instance currently in use. - /// The input for the diagnostics to create. - /// The source to attach the diagnostics to. - /// The optional arguments for the formatted message to include. - public static void ReportDiagnostic( - this GeneratorExecutionContext context, - DiagnosticDescriptor descriptor, - SyntaxNode node, - params object[] args) - { - context.ReportDiagnostic(Diagnostic.Create(descriptor, node.GetLocation(), args)); - } - - /// - /// Adds a new diagnostics to the target builder. - /// - /// The collection of produced instances. - /// The input for the diagnostics to create. - /// The source to attach the diagnostics to. - /// The optional arguments for the formatted message to include. - public static void Add( - this ImmutableArray.Builder diagnostics, - DiagnosticDescriptor descriptor, - ISymbol symbol, - params object[] args) - { - diagnostics.Add(Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args)); - } - - /// - /// Adds a new diagnostics to the target builder. - /// - /// The collection of produced instances. - /// The input for the diagnostics to create. - /// The source to attach the diagnostics to. - /// The optional arguments for the formatted message to include. - public static void Add( - this ImmutableArray.Builder diagnostics, - DiagnosticDescriptor descriptor, - SyntaxNode node, - params object[] args) - { - diagnostics.Add(Diagnostic.Create(descriptor, node.GetLocation(), args)); - } - - /// - /// Registers an output node into an to output diagnostics. - /// - /// The input instance. - /// The input sequence of diagnostics. - public static void ReportDiagnostics(this IncrementalGeneratorInitializationContext context, IncrementalValuesProvider> diagnostics) - { - context.RegisterSourceOutput(diagnostics, static (context, diagnostics) => - { - foreach (Diagnostic diagnostic in diagnostics) - { - context.ReportDiagnostic(diagnostic); - } - }); - } -} diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs index e031383f..5fbba895 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs @@ -1,4 +1,4 @@ -using ComputeSharp.D2D1Interop.SourceGenerators.Diagnostics; +using ComputeSharp.SourceGeneration.Extensions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/ComputeSharp.SourceGeneration/ComputeSharp.SourceGeneration.projitems b/src/ComputeSharp.SourceGeneration/ComputeSharp.SourceGeneration.projitems index d1a90597..03e74b2a 100644 --- a/src/ComputeSharp.SourceGeneration/ComputeSharp.SourceGeneration.projitems +++ b/src/ComputeSharp.SourceGeneration/ComputeSharp.SourceGeneration.projitems @@ -9,6 +9,7 @@ ComputeSharp.SourceGeneration + diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticsExtensions.cs b/src/ComputeSharp.SourceGeneration/Extensions/DiagnosticsExtensions.cs similarity index 98% rename from src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticsExtensions.cs rename to src/ComputeSharp.SourceGeneration/Extensions/DiagnosticsExtensions.cs index 8584bee1..448c347d 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticsExtensions.cs +++ b/src/ComputeSharp.SourceGeneration/Extensions/DiagnosticsExtensions.cs @@ -2,7 +2,7 @@ using System.Linq; using Microsoft.CodeAnalysis; -namespace ComputeSharp.SourceGenerators.Diagnostics; +namespace ComputeSharp.SourceGeneration.Extensions; /// /// Extension methods for , specifically for reporting diagnostics. diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs index bd1c883d..0fdadf16 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; using System.Threading; using ComputeSharp.Exceptions; using ComputeSharp.Shaders.Translation; -using ComputeSharp.SourceGenerators.Diagnostics; +using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGenerators.Models; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs index ca805ce7..a22fb426 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.Diagnostics.cs @@ -1,4 +1,4 @@ -using ComputeSharp.SourceGenerators.Diagnostics; +using ComputeSharp.SourceGeneration.Extensions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax;