Common.cs 14 KB

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