1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Merge pull request #82918 from raulsntos/dotnet/only-node-can-export-node

C#: Report diagnostic for Node exports in a type that doesn't derive from Node
This commit is contained in:
Rémi Verschelde
2023-10-27 11:36:33 +02:00
3 changed files with 44 additions and 1 deletions

View File

@@ -230,6 +230,31 @@ namespace Godot.SourceGenerators
location?.SourceTree?.FilePath));
}
public static void ReportOnlyNodesShouldExportNodes(
GeneratorExecutionContext context,
ISymbol exportedMemberSymbol
)
{
var locations = exportedMemberSymbol.Locations;
var location = locations.FirstOrDefault(l => l.SourceTree != null) ?? locations.FirstOrDefault();
bool isField = exportedMemberSymbol is IFieldSymbol;
string message = $"Types not derived from Node should not export Node {(isField ? "fields" : "properties")}";
string description = $"{message}. Node export is only supported in Node-derived classes.";
context.ReportDiagnostic(Diagnostic.Create(
new DiagnosticDescriptor(id: "GD0107",
title: message,
messageFormat: message,
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description),
location,
location?.SourceTree?.FilePath));
}
public static void ReportSignalDelegateMissingSuffix(
GeneratorExecutionContext context,
INamedTypeSymbol delegateSymbol)