| 1 | using Microsoft.CodeAnalysis; |
| 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| 3 | |
| 4 | namespace Godot.SourceGenerators |
| 5 | { |
| 6 | public static partial class Common |
| 7 | { |
| 8 | private static readonly string _helpLinkFormat = $"{VersionDocsUrl}/tutorials/scripting/c_sharp/diagnostics/{{0}}.html"; |
| 9 | |
| 10 | internal static readonly DiagnosticDescriptor ClassPartialModifierRule = |
| 11 | new DiagnosticDescriptor(id: "GD0001", |
| 12 | title: $"Missing partial modifier on declaration of type that derives from '{GodotClasses.GodotObject}'", |
| 13 | messageFormat: $"Missing partial modifier on declaration of type '{{0}}' that derives from '{GodotClasses.GodotObject}'", |
| 14 | category: "Usage", |
| 15 | DiagnosticSeverity.Error, |
| 16 | isEnabledByDefault: true, |
| 17 | $"Classes that derive from '{GodotClasses.GodotObject}' must be declared with the partial modifier.", |
| 18 | helpLinkUri: string.Format(_helpLinkFormat, "GD0001")); |
| 19 | |
| 20 | internal static readonly DiagnosticDescriptor OuterClassPartialModifierRule = |
| 21 | new DiagnosticDescriptor(id: "GD0002", |
| 22 | title: $"Missing partial modifier on declaration of type which contains nested classes that derive from '{GodotClasses.GodotObject}'", |
| 23 | messageFormat: $"Missing partial modifier on declaration of type '{{0}}' which contains nested classes that derive from '{GodotClasses.GodotObject}'", |
| 24 | category: "Usage", |
| 25 | DiagnosticSeverity.Error, |
| 26 | isEnabledByDefault: true, |
| 27 | $"Classes that derive from '{GodotClasses.GodotObject}' and their containing types must be declared with the partial modifier.", |
| 28 | helpLinkUri: string.Format(_helpLinkFormat, "GD0002")); |
| 29 | |
| 30 | public static readonly DiagnosticDescriptor MultipleClassesInGodotScriptRule = |
| 31 | new DiagnosticDescriptor(id: "GD0003", |
| 32 | title: "Found multiple classes with the same name in the same script file", |
| 33 | messageFormat: "Found multiple classes with the name '{0}' in the same script file", |
| 34 | category: "Usage", |
| 35 | DiagnosticSeverity.Error, |
| 36 | isEnabledByDefault: true, |
| 37 | "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.", |
| 38 | helpLinkUri: string.Format(_helpLinkFormat, "GD0003")); |
| 39 | |
| 40 | public static readonly DiagnosticDescriptor ExportedMemberIsStaticRule = |
| 41 | new DiagnosticDescriptor(id: "GD0101", |
| 42 | title: "The exported member is static", |
| 43 | messageFormat: "The exported member '{0}' is static", |
| 44 | category: "Usage", |
| 45 | DiagnosticSeverity.Error, |
| 46 | isEnabledByDefault: true, |
| 47 | "The exported member is static. Only instance fields and properties can be exported. Remove the 'static' modifier, or the '[Export]' attribute.", |
| 48 | helpLinkUri: string.Format(_helpLinkFormat, "GD0101")); |
| 49 | |
| 50 | public static readonly DiagnosticDescriptor ExportedMemberTypeIsNotSupportedRule = |
| 51 | new DiagnosticDescriptor(id: "GD0102", |
| 52 | title: "The type of the exported member is not supported", |
| 53 | messageFormat: "The type of the exported member '{0}' is not supported", |
| 54 | category: "Usage", |
| 55 | DiagnosticSeverity.Error, |
| 56 | isEnabledByDefault: true, |
| 57 | "The type of the exported member is not supported. Use a supported type, or remove the '[Export]' attribute.", |
| 58 | helpLinkUri: string.Format(_helpLinkFormat, "GD0102")); |
| 59 | |
| 60 | public static readonly DiagnosticDescriptor ExportedMemberIsReadOnlyRule = |
| 61 | new DiagnosticDescriptor(id: "GD0103", |
| 62 | title: "The exported member is read-only", |
| 63 | messageFormat: "The exported member '{0}' is read-only", |
| 64 | category: "Usage", |
| 65 | DiagnosticSeverity.Error, |
| 66 | isEnabledByDefault: true, |
| 67 | "The exported member is read-only. Exported member must be writable.", |
| 68 | helpLinkUri: string.Format(_helpLinkFormat, "GD0103")); |
| 69 | |
| 70 | public static readonly DiagnosticDescriptor ExportedPropertyIsWriteOnlyRule = |
| 71 | new DiagnosticDescriptor(id: "GD0104", |
| 72 | title: "The exported property is write-only", |
| 73 | messageFormat: "The exported property '{0}' is write-only", |
| 74 | category: "Usage", |
| 75 | DiagnosticSeverity.Error, |
| 76 | isEnabledByDefault: true, |
| 77 | "The exported property is write-only. Exported properties must be readable.", |
| 78 | helpLinkUri: string.Format(_helpLinkFormat, "GD0104")); |
| 79 | |
| 80 | public static readonly DiagnosticDescriptor ExportedMemberIsIndexerRule = |
| 81 | new DiagnosticDescriptor(id: "GD0105", |
| 82 | title: "The exported property is an indexer", |
| 83 | messageFormat: "The exported property '{0}' is an indexer", |
| 84 | category: "Usage", |
| 85 | DiagnosticSeverity.Error, |
| 86 | isEnabledByDefault: true, |
| 87 | "The exported property is an indexer. Remove the '[Export]' attribute.", |
| 88 | helpLinkUri: string.Format(_helpLinkFormat, "GD0105")); |
| 89 | |
| 90 | public static readonly DiagnosticDescriptor ExportedMemberIsExplicitInterfaceImplementationRule = |
| 91 | new DiagnosticDescriptor(id: "GD0106", |
| 92 | title: "The exported property is an explicit interface implementation", |
| 93 | messageFormat: "The exported property '{0}' is an explicit interface implementation", |
| 94 | category: "Usage", |
| 95 | DiagnosticSeverity.Error, |
| 96 | isEnabledByDefault: true, |
| 97 | "The exported property is an explicit interface implementation. Remove the '[Export]' attribute.", |
| 98 | helpLinkUri: string.Format(_helpLinkFormat, "GD0106")); |
| 99 | |
| 100 | public static readonly DiagnosticDescriptor OnlyNodesShouldExportNodesRule = |
| 101 | new DiagnosticDescriptor(id: "GD0107", |
| 102 | title: "Types not derived from Node should not export Node members", |
| 103 | messageFormat: "Types not derived from Node should not export Node members", |
| 104 | category: "Usage", |
| 105 | DiagnosticSeverity.Error, |
| 106 | isEnabledByDefault: true, |
| 107 | "Types not derived from Node should not export Node members. Node export is only supported in Node-derived classes.", |
| 108 | helpLinkUri: string.Format(_helpLinkFormat, "GD0107")); |
| 109 | |
| 110 | public static readonly DiagnosticDescriptor OnlyToolClassesShouldUseExportToolButtonRule = |
| 111 | new DiagnosticDescriptor(id: "GD0108", |
| 112 | title: "The exported tool button is not in a tool class", |
| 113 | messageFormat: "The exported tool button '{0}' is not in a tool class", |
| 114 | category: "Usage", |
| 115 | DiagnosticSeverity.Error, |
| 116 | isEnabledByDefault: true, |
| 117 | "The exported tool button is not in a tool class. Annotate the class with the '[Tool]' attribute, or remove the '[ExportToolButton]' attribute.", |
| 118 | helpLinkUri: string.Format(_helpLinkFormat, "GD0108")); |
| 119 | |
| 120 | public static readonly DiagnosticDescriptor ExportToolButtonShouldNotBeUsedWithExportRule = |
| 121 | new DiagnosticDescriptor(id: "GD0109", |
| 122 | title: "The '[ExportToolButton]' attribute cannot be used with another '[Export]' attribute", |
| 123 | messageFormat: "The '[ExportToolButton]' attribute cannot be used with another '[Export]' attribute on '{0}'", |
| 124 | category: "Usage", |
| 125 | DiagnosticSeverity.Error, |
| 126 | isEnabledByDefault: true, |
| 127 | "The '[ExportToolButton]' attribute cannot be used with the '[Export]' attribute. Remove one of the attributes.", |
| 128 | helpLinkUri: string.Format(_helpLinkFormat, "GD0109")); |
| 129 | |
| 130 | public static readonly DiagnosticDescriptor ExportToolButtonIsNotCallableRule = |
| 131 | new DiagnosticDescriptor(id: "GD0110", |
| 132 | title: "The exported tool button is not a Callable", |
| 133 | messageFormat: "The exported tool button '{0}' is not a Callable", |
| 134 | category: "Usage", |
| 135 | DiagnosticSeverity.Error, |
| 136 | isEnabledByDefault: true, |
| 137 | "The exported tool button is not a Callable. The '[ExportToolButton]' attribute is only supported on members of type Callable.", |
| 138 | helpLinkUri: string.Format(_helpLinkFormat, "GD0110")); |
| 139 | |
| 140 | public static readonly DiagnosticDescriptor ExportToolButtonMustBeExpressionBodiedProperty = |
| 141 | new DiagnosticDescriptor(id: "GD0111", |
| 142 | title: "The exported tool button must be an expression-bodied property", |
| 143 | messageFormat: "The exported tool button '{0}' must be an expression-bodied property", |
| 144 | category: "Usage", |
| 145 | DiagnosticSeverity.Error, |
| 146 | isEnabledByDefault: true, |
| 147 | "The exported tool button must be an expression-bodied property. The '[ExportToolButton]' attribute is only supported on expression-bodied properties with a 'new Callable(...)' or 'Callable.From(...)' expression.", |
| 148 | helpLinkUri: string.Format(_helpLinkFormat, "GD0111")); |
| 149 | |
| 150 | public static readonly DiagnosticDescriptor SignalDelegateMissingSuffixRule = |
| 151 | new DiagnosticDescriptor(id: "GD0201", |
| 152 | title: "The name of the delegate must end with 'EventHandler'", |
| 153 | messageFormat: "The name of the delegate '{0}' must end with 'EventHandler'", |
| 154 | category: "Usage", |
| 155 | DiagnosticSeverity.Error, |
| 156 | isEnabledByDefault: true, |
| 157 | "The name of the delegate must end with 'EventHandler'. Rename the delegate accordingly, or remove the '[Signal]' attribute.", |
| 158 | helpLinkUri: string.Format(_helpLinkFormat, "GD0201")); |
| 159 | |
| 160 | public static readonly DiagnosticDescriptor SignalParameterTypeNotSupportedRule = |
| 161 | new DiagnosticDescriptor(id: "GD0202", |
| 162 | title: "The parameter of the delegate signature of the signal is not supported", |
| 163 | messageFormat: "The parameter of the delegate signature of the signal '{0}' is not supported", |
| 164 | category: "Usage", |
| 165 | DiagnosticSeverity.Error, |
| 166 | isEnabledByDefault: true, |
| 167 | "The parameter of the delegate signature of the signal is not supported. Use supported types only, or remove the '[Signal]' attribute.", |
| 168 | helpLinkUri: string.Format(_helpLinkFormat, "GD0202")); |
| 169 | |
| 170 | public static readonly DiagnosticDescriptor SignalDelegateSignatureMustReturnVoidRule = |
| 171 | new DiagnosticDescriptor(id: "GD0203", |
| 172 | title: "The delegate signature of the signal must return void", |
| 173 | messageFormat: "The delegate signature of the signal '{0}' must return void", |
| 174 | category: "Usage", |
| 175 | DiagnosticSeverity.Error, |
| 176 | isEnabledByDefault: true, |
| 177 | "The delegate signature of the signal must return void. Return void, or remove the '[Signal]' attribute.", |
| 178 | helpLinkUri: string.Format(_helpLinkFormat, "GD0203")); |
| 179 | |
| 180 | public static readonly DiagnosticDescriptor GenericTypeArgumentMustBeVariantRule = |
| 181 | new DiagnosticDescriptor(id: "GD0301", |
| 182 | title: "The generic type argument must be a Variant compatible type", |
| 183 | messageFormat: "The generic type argument '{0}' must be a Variant compatible type", |
| 184 | category: "Usage", |
| 185 | DiagnosticSeverity.Error, |
| 186 | isEnabledByDefault: true, |
| 187 | "The generic type argument must be a Variant compatible type. Use a Variant compatible type as the generic type argument.", |
| 188 | helpLinkUri: string.Format(_helpLinkFormat, "GD0301")); |
| 189 | |
| 190 | public static readonly DiagnosticDescriptor GenericTypeParameterMustBeVariantAnnotatedRule = |
| 191 | new DiagnosticDescriptor(id: "GD0302", |
| 192 | title: "The generic type parameter must be annotated with the '[MustBeVariant]' attribute", |
| 193 | messageFormat: "The generic type parameter '{0}' must be annotated with the '[MustBeVariant]' attribute", |
| 194 | category: "Usage", |
| 195 | DiagnosticSeverity.Error, |
| 196 | isEnabledByDefault: true, |
| 197 | "The generic type parameter must be annotated with the '[MustBeVariant]' attribute. Add the '[MustBeVariant]' attribute to the generic type parameter.", |
| 198 | helpLinkUri: string.Format(_helpLinkFormat, "GD0302")); |
| 199 | |
| 200 | public static readonly DiagnosticDescriptor TypeArgumentParentSymbolUnhandledRule = |
| 201 | new DiagnosticDescriptor(id: "GD0303", |
| 202 | title: "The parent symbol of a type argument that must be Variant compatible was not handled", |
| 203 | messageFormat: "The parent symbol '{0}' of a type argument that must be Variant compatible was not handled", |
| 204 | category: "Usage", |
| 205 | DiagnosticSeverity.Error, |
| 206 | isEnabledByDefault: true, |
| 207 | "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.", |
| 208 | helpLinkUri: string.Format(_helpLinkFormat, "GD0303")); |
| 209 | |
| 210 | public static readonly DiagnosticDescriptor GlobalClassMustDeriveFromGodotObjectRule = |
| 211 | new DiagnosticDescriptor(id: "GD0401", |
| 212 | title: $"The class must derive from {GodotClasses.GodotObject} or a derived class", |
| 213 | messageFormat: $"The class '{{0}}' must derive from {GodotClasses.GodotObject} or a derived class", |
| 214 | category: "Usage", |
| 215 | DiagnosticSeverity.Error, |
| 216 | isEnabledByDefault: true, |
| 217 | $"The class must derive from {GodotClasses.GodotObject} or a derived class. Change the base type, or remove the '[GlobalClass]' attribute.", |
| 218 | helpLinkUri: string.Format(_helpLinkFormat, "GD0401")); |
| 219 | |
| 220 | public static readonly DiagnosticDescriptor GlobalClassMustNotBeGenericRule = |
| 221 | new DiagnosticDescriptor(id: "GD0402", |
| 222 | title: "The class must not be generic", |
| 223 | messageFormat: "The class '{0}' must not be generic", |
| 224 | category: "Usage", |
| 225 | DiagnosticSeverity.Error, |
| 226 | isEnabledByDefault: true, |
| 227 | "The class must not be generic. Make the class non-generic, or remove the '[GlobalClass]' attribute.", |
| 228 | helpLinkUri: string.Format(_helpLinkFormat, "GD0402")); |
| 229 | } |
| 230 | } |