Enable assembly defaults, update analyzer
このコミットが含まれているのは:
1 親
dd8f221905
コミット
e5daf558ec
10ファイル変更
+217
-71
検索条件に一致するファイルはありません
-62
@@ -1,62 +0,0 @@
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A diagnostic analyzer that generates an error whenever [D2DEffectName] is used with an invalid value.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class InvalidEffectDisplayNameValueAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(InvalidD2DEffectDisplayNameAttributeValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterCompilationStartAction(static context =>
|
||||
{
|
||||
// Get the [D2DEffectDisplayName] symbol
|
||||
if (context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DEffectDisplayNameAttribute") is not { } d2DEffectIdAttributeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.RegisterSymbolAction(context =>
|
||||
{
|
||||
// Only struct types are possible targets
|
||||
if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AttributeData attributeData in typeSymbol.GetAttributes())
|
||||
{
|
||||
// Look for the [D2DEffectDisplayName] use
|
||||
if (!SymbolEqualityComparer.Default.Equals(attributeData.AttributeClass, d2DEffectIdAttributeSymbol))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validate the effect display name
|
||||
if (!D2D1EffectMetadataParser.IsValidEffectMetadataName(attributeData))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
InvalidD2DEffectDisplayNameAttributeValue,
|
||||
attributeData.GetLocation()));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}, SymbolKind.NamedType);
|
||||
});
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A diagnostic analyzer that generates an error whenever any shader metadata value attributes are used with an invalid value.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class InvalidEffectMetadataValueAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <summary>
|
||||
/// The set of type names for all metadata attributes.
|
||||
/// </summary>
|
||||
private static readonly ImmutableArray<string> MetadataAttributeTypeNames = ImmutableArray.Create(
|
||||
"ComputeSharp.D2D1.D2DEffectDisplayNameAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectDescriptionAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectCategoryAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectAuthorAttribute");
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of diagnostics to their attribute type names.
|
||||
/// </summary>
|
||||
private static readonly ImmutableDictionary<string, DiagnosticDescriptor> AttributeTypeNameToDiagnosticMapping = ImmutableDictionary.CreateRange(new[]
|
||||
{
|
||||
new KeyValuePair<string, DiagnosticDescriptor>("D2DEffectDisplayNameAttribute", InvalidD2DEffectDisplayNameAttributeValue),
|
||||
new KeyValuePair<string, DiagnosticDescriptor>("D2DEffectDescriptionAttribute", InvalidD2DEffectDescriptionAttributeValue),
|
||||
new KeyValuePair<string, DiagnosticDescriptor>("D2DEffectCategoryAttribute", InvalidD2DEffectCategoryAttributeValue),
|
||||
new KeyValuePair<string, DiagnosticDescriptor>("D2DEffectAuthorAttribute", InvalidD2DEffectAuthorAttributeValue)
|
||||
});
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
|
||||
InvalidD2DEffectDisplayNameAttributeValue,
|
||||
InvalidD2DEffectDescriptionAttributeValue,
|
||||
InvalidD2DEffectCategoryAttributeValue,
|
||||
InvalidD2DEffectAuthorAttributeValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterCompilationStartAction(static context =>
|
||||
{
|
||||
// Get the metadata attribute symbols
|
||||
if (!context.Compilation.TryBuildNamedTypeSymbolSet(MetadataAttributeTypeNames, out ImmutableHashSet<INamedTypeSymbol>? typeSymbols))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.RegisterSymbolAction(context =>
|
||||
{
|
||||
// Only struct types and assemblies are possible targets
|
||||
if (context.Symbol is not (INamedTypeSymbol { TypeKind: TypeKind.Struct } or IAssemblySymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AttributeData attributeData in context.Symbol.GetAttributes())
|
||||
{
|
||||
// Only check attributes we care about
|
||||
if (attributeData.AttributeClass is not INamedTypeSymbol attributeSymbol ||
|
||||
!typeSymbols.Contains(attributeSymbol))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validate the effect display name
|
||||
if (!D2D1EffectMetadataParser.IsValidEffectMetadataName(attributeData))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
AttributeTypeNameToDiagnosticMapping[attributeSymbol.MetadataName],
|
||||
attributeData.GetLocation()));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}, SymbolKind.NamedType | SymbolKind.Assembly);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -877,7 +877,7 @@ partial class DiagnosticDescriptors
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DEffectDisplayName]</c> attribute is being used with an invalid value.
|
||||
/// <para>
|
||||
/// Format: <c>"The [D2DEffectDisplayName] attribute is being used with an invalid value (the input text must be a valid GUID)"</c>.
|
||||
/// Format: <c>"The [D2DEffectDisplayName] attribute is being used with an invalid value"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidD2DEffectDisplayNameAttributeValue = new DiagnosticDescriptor(
|
||||
@@ -889,4 +889,52 @@ partial class DiagnosticDescriptors
|
||||
isEnabledByDefault: true,
|
||||
description: "The [D2DEffectDisplayName] attribute must contain valid text.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DEffectDescription]</c> attribute is being used with an invalid value.
|
||||
/// <para>
|
||||
/// Format: <c>"The [D2DEffectDescription] attribute is being used with an invalid value"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidD2DEffectDescriptionAttributeValue = new DiagnosticDescriptor(
|
||||
id: "CMPSD2D0061",
|
||||
title: "Invalid [D2DEffectDescription] attribute value",
|
||||
messageFormat: "The [D2DEffectDescription] attribute is being used with an invalid value",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The [D2DEffectDescription] attribute must contain valid text.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DEffectCategory]</c> attribute is being used with an invalid value.
|
||||
/// <para>
|
||||
/// Format: <c>"The [D2DEffectDescription] attribute is being used with an invalid value"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidD2DEffectCategoryAttributeValue = new DiagnosticDescriptor(
|
||||
id: "CMPSD2D0062",
|
||||
title: "Invalid [D2DEffectCategory] attribute value",
|
||||
messageFormat: "The [D2DEffectCategory] attribute is being used with an invalid value",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The [D2DEffectCategory] attribute must contain valid text.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DEffectAuthor]</c> attribute is being used with an invalid value.
|
||||
/// <para>
|
||||
/// Format: <c>"The [D2DEffectAuthor] attribute is being used with an invalid value"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidD2DEffectAuthorAttributeValue = new DiagnosticDescriptor(
|
||||
id: "CMPSD2D0063",
|
||||
title: "Invalid [D2DEffectAuthor] attribute value",
|
||||
messageFormat: "The [D2DEffectAuthor] attribute is being used with an invalid value",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The [D2DEffectAuthor] attribute must contain valid text.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする