using System.Linq; using Microsoft.CodeAnalysis; namespace ComputeSharp.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)); } } }