summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs77
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs10
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs10
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs10
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs10
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs10
6 files changed, 85 insertions, 42 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..df35091596 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,7 +224,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0106")),
location,
location?.SourceTree?.FilePath));
}
@@ -240,7 +250,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0201")),
location,
location?.SourceTree?.FilePath));
}
@@ -264,7 +275,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0202")),
location,
location?.SourceTree?.FilePath));
}
@@ -288,7 +300,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0203")),
location,
location?.SourceTree?.FilePath));
}
@@ -300,7 +313,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 +333,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0301")),
typeArgumentSyntax.GetLocation(),
typeArgumentSyntax.SyntaxTree.FilePath));
}
@@ -331,7 +346,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 +365,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0302")),
typeArgumentSyntax.GetLocation(),
typeArgumentSyntax.SyntaxTree.FilePath));
}
@@ -361,7 +378,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 +398,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0303")),
typeArgumentSyntax.GetLocation(),
typeArgumentSyntax.SyntaxTree.FilePath));
}
@@ -388,11 +407,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 +430,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0401")),
classSyntax.GetLocation(),
classSyntax.SyntaxTree.FilePath));
}
@@ -422,7 +443,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 +462,8 @@ namespace Godot.SourceGenerators
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description),
+ description,
+ helpLinkUri: string.Format(_helpLinkFormat, "GD0402")),
classSyntax.GetLocation(),
classSyntax.SyntaxTree.FilePath));
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
index 7b643914bb..7232e4d7d7 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
@@ -105,16 +105,20 @@ namespace Godot.SourceGenerators
if (isInnerClass)
{
var containingType = symbol.ContainingType;
+ AppendPartialContainingTypeDeclarations(containingType);
- while (containingType != null)
+ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
+ if (containingType == null)
+ return;
+
+ AppendPartialContainingTypeDeclarations(containingType.ContainingType);
+
source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");
-
- containingType = containingType.ContainingType;
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
index 219ab7aa44..de44ada6de 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
@@ -91,16 +91,20 @@ namespace Godot.SourceGenerators
if (isInnerClass)
{
var containingType = symbol.ContainingType;
+ AppendPartialContainingTypeDeclarations(containingType);
- while (containingType != null)
+ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
+ if (containingType == null)
+ return;
+
+ AppendPartialContainingTypeDeclarations(containingType.ContainingType);
+
source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");
-
- containingType = containingType.ContainingType;
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
index 4df16d05f0..fc0bfbf084 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
@@ -88,16 +88,20 @@ namespace Godot.SourceGenerators
if (isInnerClass)
{
var containingType = symbol.ContainingType;
+ AppendPartialContainingTypeDeclarations(containingType);
- while (containingType != null)
+ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
+ if (containingType == null)
+ return;
+
+ AppendPartialContainingTypeDeclarations(containingType.ContainingType);
+
source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");
-
- containingType = containingType.ContainingType;
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
index 9de99414b6..0bc58c2b47 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
@@ -91,16 +91,20 @@ namespace Godot.SourceGenerators
if (isInnerClass)
{
var containingType = symbol.ContainingType;
+ AppendPartialContainingTypeDeclarations(containingType);
- while (containingType != null)
+ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
+ if (containingType == null)
+ return;
+
+ AppendPartialContainingTypeDeclarations(containingType.ContainingType);
+
source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");
-
- containingType = containingType.ContainingType;
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs
index 8f2774d5ae..5409d1a961 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs
@@ -100,16 +100,20 @@ namespace Godot.SourceGenerators
if (isInnerClass)
{
var containingType = symbol.ContainingType;
+ AppendPartialContainingTypeDeclarations(containingType);
- while (containingType != null)
+ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
+ if (containingType == null)
+ return;
+
+ AppendPartialContainingTypeDeclarations(containingType.ContainingType);
+
source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");
-
- containingType = containingType.ContainingType;
}
}