summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs100
1 files changed, 74 insertions, 26 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs
index 72614dd7e0..147ef852b3 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs
@@ -5,8 +5,10 @@ using Microsoft.CodeAnalysis.Diagnostics;
namespace Godot.SourceGenerators
{
- public static class Common
+ public static partial class Common
{
+ private static readonly string _helpLinkFormat = $"{VersionDocsUrl}/tutorials/scripting/c_sharp/diagnostics/{{0}}.html";
+
public static void ReportNonPartialGodotScriptClass(
GeneratorExecutionContext context,
ClassDeclarationSyntax cds, INamedTypeSymbol symbol
@@ -14,9 +16,9 @@ namespace Godot.SourceGenerators
{
string message =
"Missing partial modifier on declaration of type '" +
- $"{symbol.FullQualifiedNameOmitGlobal()}' which is a subclass of '{GodotClasses.GodotObject}'";
+ $"{symbol.FullQualifiedNameOmitGlobal()}' that derives from '{GodotClasses.GodotObject}'";
- string description = $"{message}. Subclasses of '{GodotClasses.GodotObject}' " +
+ string description = $"{message}. Classes that derive from '{GodotClasses.GodotObject}' " +
"must be declared with the partial modifier.";
context.ReportDiagnostic(Diagnostic.Create(
@@ -26,7 +28,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0001")),
cds.GetLocation(),
cds.SyntaxTree.FilePath));
}
@@ -46,9 +49,9 @@ namespace Godot.SourceGenerators
string message =
$"Missing partial modifier on declaration of type '{fullQualifiedName}', " +
- $"which contains one or more subclasses of '{GodotClasses.GodotObject}'";
+ $"which contains nested classes that derive from '{GodotClasses.GodotObject}'";
- string description = $"{message}. Subclasses of '{GodotClasses.GodotObject}' and their " +
+ string description = $"{message}. Classes that derive from '{GodotClasses.GodotObject}' and their " +
"containing types must be declared with the partial modifier.";
context.ReportDiagnostic(Diagnostic.Create(
@@ -58,7 +61,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0002")),
outerTypeDeclSyntax.GetLocation(),
outerTypeDeclSyntax.SyntaxTree.FilePath));
}
@@ -85,7 +89,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0101")),
location,
location?.SourceTree?.FilePath));
}
@@ -111,7 +116,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0102")),
location,
location?.SourceTree?.FilePath));
}
@@ -139,7 +145,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD1003")),
location,
location?.SourceTree?.FilePath));
}
@@ -163,7 +170,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0104")),
location,
location?.SourceTree?.FilePath));
}
@@ -189,7 +197,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0105")),
location,
location?.SourceTree?.FilePath));
}
@@ -215,6 +224,32 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0106")),
+ location,
+ 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));
@@ -240,7 +275,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0201")),
location,
location?.SourceTree?.FilePath));
}
@@ -264,7 +300,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0202")),
location,
location?.SourceTree?.FilePath));
}
@@ -288,7 +325,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0203")),
location,
location?.SourceTree?.FilePath));
}
@@ -300,7 +338,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- "The generic type argument must be a Variant compatible type. Use a Variant compatible type as the generic type argument.");
+ "The generic type argument must be a Variant compatible type. Use a Variant compatible type as the generic type argument.",
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0301"));
public static void ReportGenericTypeArgumentMustBeVariant(
SyntaxNodeAnalysisContext context,
@@ -319,7 +358,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0301")),
typeArgumentSyntax.GetLocation(),
typeArgumentSyntax.SyntaxTree.FilePath));
}
@@ -331,7 +371,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- "The generic type argument must be a Variant type. Use a Variant type as the generic type argument.");
+ "The generic type argument must be a Variant type. Use a Variant type as the generic type argument.",
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0302"));
public static void ReportGenericTypeParameterMustBeVariantAnnotated(
SyntaxNodeAnalysisContext context,
@@ -349,7 +390,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0302")),
typeArgumentSyntax.GetLocation(),
typeArgumentSyntax.SyntaxTree.FilePath));
}
@@ -361,7 +403,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- "The generic type argument must be a Variant type. Use a Variant type as the generic type argument.");
+ "The generic type argument must be a Variant type. Use a Variant type as the generic type argument.",
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0303"));
public static void ReportTypeArgumentParentSymbolUnhandled(
SyntaxNodeAnalysisContext context,
@@ -380,7 +423,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0303")),
typeArgumentSyntax.GetLocation(),
typeArgumentSyntax.SyntaxTree.FilePath));
}
@@ -388,11 +432,12 @@ namespace Godot.SourceGenerators
public static readonly DiagnosticDescriptor GlobalClassMustDeriveFromGodotObjectRule =
new DiagnosticDescriptor(id: "GD0401",
title: "The class must derive from GodotObject or a derived class",
- messageFormat: "The class '{0}' must derive from GodotObject or a derived class.",
+ messageFormat: "The class '{0}' must derive from GodotObject or a derived class",
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- "The class must derive from GodotObject or a derived class. Change the base class or remove the '[GlobalClass]' attribute.");
+ "The class must derive from GodotObject or a derived class. Change the base class or remove the '[GlobalClass]' attribute.",
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0401"));
public static void ReportGlobalClassMustDeriveFromGodotObject(
SyntaxNodeAnalysisContext context,
@@ -410,7 +455,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0401")),
classSyntax.GetLocation(),
classSyntax.SyntaxTree.FilePath));
}
@@ -422,7 +468,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- "The class must be a non-generic type. Remove the generic arguments or the '[GlobalClass]' attribute.");
+ "The class must be a non-generic type. Remove the generic arguments or the '[GlobalClass]' attribute.",
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0401"));
public static void ReportGlobalClassMustNotBeGeneric(
SyntaxNodeAnalysisContext context,
@@ -440,7 +487,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0402")),
classSyntax.GetLocation(),
classSyntax.SyntaxTree.FilePath));
}