From 09b22885a933de228596c4857b0deef9df24ff80 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 7 Jan 2024 00:44:08 +0100 Subject: [PATCH] Fix analyzers triggering on unrelated partial methods --- .../InvalidD2DPixelShaderSourceMethodReturnTypeAnalyzer.cs | 7 +++++++ ...2DCompileOptionsOnD2DPixelShaderSourceMethodAnalyzer.cs | 6 ++++++ ...D2DShaderProfileOnD2DPixelShaderSourceMethodAnalyzer.cs | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DPixelShaderSourceMethodReturnTypeAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DPixelShaderSourceMethodReturnTypeAnalyzer.cs index f14c29496..e30cd1190 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DPixelShaderSourceMethodReturnTypeAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DPixelShaderSourceMethodReturnTypeAnalyzer.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using System.Linq; +using ComputeSharp.SourceGeneration.Extensions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; @@ -42,6 +43,12 @@ public override void Initialize(AnalysisContext context) return; } + // Ignore methods without [D2DPixelShaderSource] + if (!methodSymbol.HasAttributeWithType(d2DPixelShaderSourceAttributeSymbol)) + { + return; + } + // Emit a diagnostic if the return type is not ReadOnlySpan if (!SymbolEqualityComparer.Default.Equals(methodSymbol.ReturnType, readOnlySpanOfByteSymbol)) { diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DCompileOptionsOnD2DPixelShaderSourceMethodAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DCompileOptionsOnD2DPixelShaderSourceMethodAnalyzer.cs index a6f588d92..654ed07dd 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DCompileOptionsOnD2DPixelShaderSourceMethodAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DCompileOptionsOnD2DPixelShaderSourceMethodAnalyzer.cs @@ -39,6 +39,12 @@ public override void Initialize(AnalysisContext context) return; } + // Ignore methods without [D2DPixelShaderSource] + if (!methodSymbol.HasAttributeWithType(d2DPixelShaderSourceAttributeSymbol)) + { + return; + } + // Emit a diagnostic if there is no compile options available at any level if (!methodSymbol.HasAttributeWithType(d2DCompileOptionsAttributeSymbol) && !methodSymbol.ContainingAssembly.HasAttributeWithType(d2DCompileOptionsAttributeSymbol)) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DShaderProfileOnD2DPixelShaderSourceMethodAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DShaderProfileOnD2DPixelShaderSourceMethodAnalyzer.cs index 411c7afcb..6eb10b60a 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DShaderProfileOnD2DPixelShaderSourceMethodAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/MissingD2DShaderProfileOnD2DPixelShaderSourceMethodAnalyzer.cs @@ -39,6 +39,12 @@ public override void Initialize(AnalysisContext context) return; } + // Ignore methods without [D2DPixelShaderSource] + if (!methodSymbol.HasAttributeWithType(d2DPixelShaderSourceAttributeSymbol)) + { + return; + } + // Emit a diagnostic if there is no shader profile available at any level if (!methodSymbol.HasAttributeWithType(d2DShaderProfileAttributeSymbol) && !methodSymbol.ContainingAssembly.HasAttributeWithType(d2DShaderProfileAttributeSymbol))