2021-03-06 00:12:42 +01:00
using Microsoft.CodeAnalysis ;
using Microsoft.CodeAnalysis.CSharp.Syntax ;
namespace Godot.SourceGenerators
{
2023-08-10 17:08:09 +02:00
public static partial class Common
2021-03-06 00:12:42 +01:00
{
2023-08-10 17:08:09 +02:00
private static readonly string _helpLinkFormat = $"{VersionDocsUrl}/tutorials/scripting/c_sharp/diagnostics/{{0}}.html" ;
2021-03-06 00:12:42 +01:00
public static void ReportNonPartialGodotScriptClass (
GeneratorExecutionContext context ,
ClassDeclarationSyntax cds , INamedTypeSymbol symbol
)
{
string message =
"Missing partial modifier on declaration of type '" +
2023-08-10 17:08:09 +02:00
$"{symbol.FullQualifiedNameOmitGlobal()}' that derives from '{GodotClasses.GodotObject}'" ;
2021-03-06 00:12:42 +01:00
2023-08-10 17:08:09 +02:00
string description = $"{message}. Classes that derive from '{GodotClasses.GodotObject}' " +
2021-12-28 23:25:16 +01:00
"must be declared with the partial modifier." ;
2021-03-06 00:12:42 +01:00
context . ReportDiagnostic ( Diagnostic . Create (
2022-08-15 05:57:52 +02:00
new DiagnosticDescriptor ( id : "GD0001" ,
2021-03-06 00:12:42 +01:00
title : message ,
messageFormat : message ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
2023-08-10 17:08:09 +02:00
description ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0001" ) ) ,
2021-03-06 00:12:42 +01:00
cds . GetLocation ( ) ,
cds . SyntaxTree . FilePath ) ) ;
}
2021-12-28 23:25:16 +01:00
public static void ReportNonPartialGodotScriptOuterClass (
GeneratorExecutionContext context ,
TypeDeclarationSyntax outerTypeDeclSyntax
)
{
var outerSymbol = context . Compilation
. GetSemanticModel ( outerTypeDeclSyntax . SyntaxTree )
. GetDeclaredSymbol ( outerTypeDeclSyntax ) ;
string fullQualifiedName = outerSymbol is INamedTypeSymbol namedTypeSymbol ?
2022-11-24 01:04:15 +01:00
namedTypeSymbol . FullQualifiedNameOmitGlobal ( ) :
2021-12-28 23:25:16 +01:00
"type not found" ;
string message =
$"Missing partial modifier on declaration of type '{fullQualifiedName}', " +
2023-08-10 17:08:09 +02:00
$"which contains nested classes that derive from '{GodotClasses.GodotObject}'" ;
2021-12-28 23:25:16 +01:00
2023-08-10 17:08:09 +02:00
string description = $"{message}. Classes that derive from '{GodotClasses.GodotObject}' and their " +
2021-12-28 23:25:16 +01:00
"containing types must be declared with the partial modifier." ;
context . ReportDiagnostic ( Diagnostic . Create (
2022-08-15 05:57:52 +02:00
new DiagnosticDescriptor ( id : "GD0002" ,
2021-12-28 23:25:16 +01:00
title : message ,
messageFormat : message ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
2023-08-10 17:08:09 +02:00
description ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0002" ) ) ,
2021-12-28 23:25:16 +01:00
outerTypeDeclSyntax . GetLocation ( ) ,
outerTypeDeclSyntax . SyntaxTree . FilePath ) ) ;
}
2022-02-27 21:57:30 +01:00
2024-02-15 18:18:33 +01:00
public static readonly DiagnosticDescriptor MultipleClassesInGodotScriptRule =
new DiagnosticDescriptor ( id : "GD0003" ,
title : "Found multiple classes with the same name in the same script file" ,
messageFormat : "Found multiple classes with the name '{0}' in the same script file" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"Found multiple classes with the same name in the same script file. A script file must only contain one class with a name that matches the file name." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0003" ) ) ;
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor ExportedMemberIsStaticRule =
new DiagnosticDescriptor ( id : "GD0101" ,
title : "The exported member is static" ,
messageFormat : "The exported member '{0}' is static" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The exported member is static. Only instance fields and properties can be exported. Remove the 'static' modifier, or the '[Export]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0101" ) ) ;
2022-07-28 17:41:47 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor ExportedMemberTypeIsNotSupportedRule =
new DiagnosticDescriptor ( id : "GD0102" ,
title : "The type of the exported member is not supported" ,
messageFormat : "The type of the exported member '{0}' is not supported" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The type of the exported member is not supported. Use a supported type, or remove the '[Export]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0102" ) ) ;
2022-07-28 17:41:47 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor ExportedMemberIsReadOnlyRule =
new DiagnosticDescriptor ( id : "GD0103" ,
title : "The exported member is read-only" ,
messageFormat : "The exported member '{0}' is read-only" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The exported member is read-only. Exported member must be writable." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0103" ) ) ;
2022-08-13 06:21:27 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor ExportedPropertyIsWriteOnlyRule =
new DiagnosticDescriptor ( id : "GD0104" ,
title : "The exported property is write-only" ,
messageFormat : "The exported property '{0}' is write-only" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The exported property is write-only. Exported properties must be readable." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0104" ) ) ;
2022-08-13 06:21:27 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor ExportedMemberIsIndexerRule =
new DiagnosticDescriptor ( id : "GD0105" ,
title : "The exported property is an indexer" ,
messageFormat : "The exported property '{0}' is an indexer" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The exported property is an indexer. Remove the '[Export]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0105" ) ) ;
2022-08-13 06:21:27 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor ExportedMemberIsExplicitInterfaceImplementationRule =
new DiagnosticDescriptor ( id : "GD0106" ,
title : "The exported property is an explicit interface implementation" ,
messageFormat : "The exported property '{0}' is an explicit interface implementation" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The exported property is an explicit interface implementation. Remove the '[Export]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0106" ) ) ;
2022-08-13 06:21:27 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor OnlyNodesShouldExportNodesRule =
new DiagnosticDescriptor ( id : "GD0107" ,
title : "Types not derived from Node should not export Node members" ,
messageFormat : "Types not derived from Node should not export Node members" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"Types not derived from Node should not export Node members. Node export is only supported in Node-derived classes." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0107" ) ) ;
2022-07-28 17:41:47 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor SignalDelegateMissingSuffixRule =
new DiagnosticDescriptor ( id : "GD0201" ,
title : "The name of the delegate must end with 'EventHandler'" ,
messageFormat : "The name of the delegate '{0}' must end with 'EventHandler'" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The name of the delegate must end with 'EventHandler'. Rename the delegate accordingly, or remove the '[Signal]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0201" ) ) ;
2022-07-28 17:41:47 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor SignalParameterTypeNotSupportedRule =
new DiagnosticDescriptor ( id : "GD0202" ,
title : "The parameter of the delegate signature of the signal is not supported" ,
messageFormat : "The parameter of the delegate signature of the signal '{0}' is not supported" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The parameter of the delegate signature of the signal is not supported. Use supported types only, or remove the '[Signal]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0202" ) ) ;
2022-07-28 17:41:47 +02:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
public static readonly DiagnosticDescriptor SignalDelegateSignatureMustReturnVoidRule =
new DiagnosticDescriptor ( id : "GD0203" ,
title : "The delegate signature of the signal must return void" ,
messageFormat : "The delegate signature of the signal '{0}' must return void" ,
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
"The delegate signature of the signal must return void. Return void, or remove the '[Signal]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0203" ) ) ;
2022-08-15 05:57:52 +02:00
public static readonly DiagnosticDescriptor GenericTypeArgumentMustBeVariantRule =
new DiagnosticDescriptor ( id : "GD0301" ,
title : "The generic type argument must be a Variant compatible type" ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
messageFormat : "The generic type argument '{0}' must be a Variant compatible type" ,
2022-08-15 05:57:52 +02:00
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
2023-08-10 17:08:09 +02:00
"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" ) ) ;
2022-08-15 05:57:52 +02:00
public static readonly DiagnosticDescriptor GenericTypeParameterMustBeVariantAnnotatedRule =
new DiagnosticDescriptor ( id : "GD0302" ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
title : "The generic type parameter must be annotated with the '[MustBeVariant]' attribute" ,
messageFormat : "The generic type parameter '{0}' must be annotated with the '[MustBeVariant]' attribute" ,
2022-08-15 05:57:52 +02:00
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
"The generic type parameter must be annotated with the '[MustBeVariant]' attribute. Add the '[MustBeVariant]' attribute to the generic type parameter." ,
2023-08-10 17:08:09 +02:00
helpLinkUri : string . Format ( _helpLinkFormat , "GD0302" ) ) ;
2022-08-15 05:57:52 +02:00
public static readonly DiagnosticDescriptor TypeArgumentParentSymbolUnhandledRule =
new DiagnosticDescriptor ( id : "GD0303" ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
title : "The parent symbol of a type argument that must be Variant compatible was not handled" ,
messageFormat : "The parent symbol '{0}' of a type argument that must be Variant compatible was not handled" ,
2022-08-15 05:57:52 +02:00
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
"The parent symbol of a type argument that must be Variant compatible was not handled. This is an issue in the engine, and should be reported." ,
2023-08-10 17:08:09 +02:00
helpLinkUri : string . Format ( _helpLinkFormat , "GD0303" ) ) ;
2022-08-15 05:57:52 +02:00
2023-07-04 04:35:54 +02:00
public static readonly DiagnosticDescriptor GlobalClassMustDeriveFromGodotObjectRule =
new DiagnosticDescriptor ( id : "GD0401" ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
title : $"The class must derive from {GodotClasses.GodotObject} or a derived class" ,
messageFormat : $"The class '{{0}}' must derive from {GodotClasses.GodotObject} or a derived class" ,
2023-07-04 04:35:54 +02:00
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
$"The class must derive from {GodotClasses.GodotObject} or a derived class. Change the base type, or remove the '[GlobalClass]' attribute." ,
2023-08-10 17:08:09 +02:00
helpLinkUri : string . Format ( _helpLinkFormat , "GD0401" ) ) ;
2023-07-04 04:35:54 +02:00
public static readonly DiagnosticDescriptor GlobalClassMustNotBeGenericRule =
new DiagnosticDescriptor ( id : "GD0402" ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
title : "The class must not be generic" ,
messageFormat : "The class '{0}' must not be generic" ,
2023-07-04 04:35:54 +02:00
category : "Usage" ,
DiagnosticSeverity . Error ,
isEnabledByDefault : true ,
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.
To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.
Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-17 21:12:06 +01:00
"The class must not be generic. Make the class non-generic, or remove the '[GlobalClass]' attribute." ,
helpLinkUri : string . Format ( _helpLinkFormat , "GD0402" ) ) ;
2021-03-06 00:12:42 +01:00
}
}