88e367a406
This base implementation is still very barebones but it defines the path for how exporting will work (at least when embedding the .NET runtime). Many manual steps are still needed, which should be automatized in the future. For example, in addition to the API assemblies, now you also need to copy the GodotPlugins assembly to each game project.
64 lines
2.5 KiB
C#
64 lines
2.5 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace Godot.SourceGenerators
|
|
{
|
|
public static class Common
|
|
{
|
|
public static void ReportNonPartialGodotScriptClass(
|
|
GeneratorExecutionContext context,
|
|
ClassDeclarationSyntax cds, INamedTypeSymbol symbol
|
|
)
|
|
{
|
|
string message =
|
|
"Missing partial modifier on declaration of type '" +
|
|
$"{symbol.FullQualifiedName()}' which is a subclass of '{GodotClasses.Object}'";
|
|
|
|
string description = $"{message}. Subclasses of '{GodotClasses.Object}' " +
|
|
"must be declared with the partial modifier.";
|
|
|
|
context.ReportDiagnostic(Diagnostic.Create(
|
|
new DiagnosticDescriptor(id: "GODOT-G0001",
|
|
title: message,
|
|
messageFormat: message,
|
|
category: "Usage",
|
|
DiagnosticSeverity.Error,
|
|
isEnabledByDefault: true,
|
|
description),
|
|
cds.GetLocation(),
|
|
cds.SyntaxTree.FilePath));
|
|
}
|
|
|
|
public static void ReportNonPartialGodotScriptOuterClass(
|
|
GeneratorExecutionContext context,
|
|
TypeDeclarationSyntax outerTypeDeclSyntax
|
|
)
|
|
{
|
|
var outerSymbol = context.Compilation
|
|
.GetSemanticModel(outerTypeDeclSyntax.SyntaxTree)
|
|
.GetDeclaredSymbol(outerTypeDeclSyntax);
|
|
|
|
string fullQualifiedName = outerSymbol is INamedTypeSymbol namedTypeSymbol ?
|
|
namedTypeSymbol.FullQualifiedName() :
|
|
"type not found";
|
|
|
|
string message =
|
|
$"Missing partial modifier on declaration of type '{fullQualifiedName}', " +
|
|
$"which contains one or more subclasses of '{GodotClasses.Object}'";
|
|
|
|
string description = $"{message}. Subclasses of '{GodotClasses.Object}' and their " +
|
|
"containing types must be declared with the partial modifier.";
|
|
|
|
context.ReportDiagnostic(Diagnostic.Create(
|
|
new DiagnosticDescriptor(id: "GODOT-G0002",
|
|
title: message,
|
|
messageFormat: message,
|
|
category: "Usage",
|
|
DiagnosticSeverity.Error,
|
|
isEnabledByDefault: true,
|
|
description),
|
|
outerTypeDeclSyntax.GetLocation(),
|
|
outerTypeDeclSyntax.SyntaxTree.FilePath));
|
|
}
|
|
}
|
|
}
|