diff options
| author | Ivan Shakhov <ivan.shakhov@jetbrains.com> | 2024-01-16 15:30:45 +0100 |
|---|---|---|
| committer | Ivan Shakhov <ivan.shakhov@jetbrains.com> | 2024-02-21 12:35:28 +0300 |
| commit | 00dc19585b9136644db850f372c0c8ad0daed189 (patch) | |
| tree | ae9571fcdc0c3142f66cc06ce77227030b2dfab3 /modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs | |
| parent | 0246230e2b7c542f003c3c53cffc22dedc0c9c50 (diff) | |
| download | redot-engine-00dc19585b9136644db850f372c0c8ad0daed189.tar.gz | |
provide analyser corresponding to the GD0001 and GD0002, add ClassPartialModifierAnalyzerFix, and tests
Co-authored-by: Raul Santos <raulsntos@gmail.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
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.cs | 76 |
1 files changed, 19 insertions, 57 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 6cd5ddb42f..ad7962e7df 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs @@ -7,63 +7,25 @@ namespace Godot.SourceGenerators { private static readonly string _helpLinkFormat = $"{VersionDocsUrl}/tutorials/scripting/c_sharp/diagnostics/{{0}}.html"; - public static void ReportNonPartialGodotScriptClass( - GeneratorExecutionContext context, - ClassDeclarationSyntax cds, INamedTypeSymbol symbol - ) - { - string message = - "Missing partial modifier on declaration of type '" + - $"{symbol.FullQualifiedNameOmitGlobal()}' that derives from '{GodotClasses.GodotObject}'"; - - string description = $"{message}. Classes that derive from '{GodotClasses.GodotObject}' " + - "must be declared with the partial modifier."; - - context.ReportDiagnostic(Diagnostic.Create( - new DiagnosticDescriptor(id: "GD0001", - title: message, - messageFormat: message, - category: "Usage", - DiagnosticSeverity.Error, - isEnabledByDefault: true, - description, - helpLinkUri: string.Format(_helpLinkFormat, "GD0001")), - 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.FullQualifiedNameOmitGlobal() : - "type not found"; - - string message = - $"Missing partial modifier on declaration of type '{fullQualifiedName}', " + - $"which contains nested classes that derive from '{GodotClasses.GodotObject}'"; - - string description = $"{message}. Classes that derive from '{GodotClasses.GodotObject}' and their " + - "containing types must be declared with the partial modifier."; - - context.ReportDiagnostic(Diagnostic.Create( - new DiagnosticDescriptor(id: "GD0002", - title: message, - messageFormat: message, - category: "Usage", - DiagnosticSeverity.Error, - isEnabledByDefault: true, - description, - helpLinkUri: string.Format(_helpLinkFormat, "GD0002")), - outerTypeDeclSyntax.GetLocation(), - outerTypeDeclSyntax.SyntaxTree.FilePath)); - } + internal static readonly DiagnosticDescriptor ClassPartialModifierRule = + new DiagnosticDescriptor(id: "GD0001", + title: $"Missing partial modifier on declaration of type that derives from '{GodotClasses.GodotObject}'", + messageFormat: $"Missing partial modifier on declaration of type '{{0}}' that derives from '{GodotClasses.GodotObject}'", + category: "Usage", + DiagnosticSeverity.Error, + isEnabledByDefault: true, + $"Classes that derive from '{GodotClasses.GodotObject}' must be declared with the partial modifier.", + helpLinkUri: string.Format(_helpLinkFormat, "GD0001")); + + internal static readonly DiagnosticDescriptor OuterClassPartialModifierRule = + new DiagnosticDescriptor(id: "GD0002", + title: $"Missing partial modifier on declaration of type which contains nested classes that derive from '{GodotClasses.GodotObject}'", + messageFormat: $"Missing partial modifier on declaration of type '{{0}}' which contains nested classes that derive from '{GodotClasses.GodotObject}'", + category: "Usage", + DiagnosticSeverity.Error, + isEnabledByDefault: true, + $"Classes that derive from '{GodotClasses.GodotObject}' and their containing types must be declared with the partial modifier.", + helpLinkUri: string.Format(_helpLinkFormat, "GD0002")); public static readonly DiagnosticDescriptor MultipleClassesInGodotScriptRule = new DiagnosticDescriptor(id: "GD0003", |
