You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
230 lines
11 KiB
230 lines
11 KiB
using Microsoft.CodeAnalysis; |
|
|
|
|
|
namespace gaemstone.SourceGen; |
|
|
|
public static class Descriptors |
|
{ |
|
public const string DiagnosticCategory = "gaemstone.SourceGen"; |
|
|
|
// TODO: Replace this counter with proper hardcoded IDs. |
|
private static int _idCounter = 1; |
|
|
|
|
|
// Diagnostics relating to where the symbol occurs. |
|
|
|
public static readonly DiagnosticDescriptor ModuleMustNotBeNested = new( |
|
$"gSG{_idCounter++:00}", "Module must not be a nested class", |
|
"A [Module] must be defined as a top-level class.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor EntityMustBeInModule = new( |
|
$"gSG{_idCounter++:00}", "Entity must be part of a Module", |
|
"Entity type must be defined within a [Module].", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor InstanceMethodOnlyValidInSingleton = new( |
|
$"gSG{_idCounter++:00}", "Non-static method is only valid in Singleton Module", |
|
"Non-static [System] or [Observer] is only valid in a [Module] which is also marked as a [Singleton].", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamMustBeInMethod = new( |
|
$"gSG{_idCounter++:00}", "Parameter must be part of a System or Observer", |
|
"This parameter must be part of a method marked as [System] or [Observer].", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
// Diagnostics relating to the combined usage of attributes. |
|
|
|
public static readonly DiagnosticDescriptor AttributesRequireTypeOrPath = new( |
|
$"gSG{_idCounter++:00}", "Entity attributes require type or path", |
|
"Entity attributes require a type (such as [Entity]) or [Path].", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
public static readonly DiagnosticDescriptor InvalidAttributeCombination = new( |
|
$"gSG{_idCounter++:00}", "Invalid combination of entity attributes", |
|
"The combination of entity attributes {0} is not valid.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ValidModuleAttributesHint = new( |
|
$"gSG{_idCounter++:00}", "Module may be a Singleton", |
|
"A [Module] may be marked as a [Singleton].", |
|
DiagnosticCategory, DiagnosticSeverity.Info, true); |
|
|
|
public static readonly DiagnosticDescriptor ValidRelationAttributesHint = new( |
|
$"gSG{_idCounter++:00}", "Relation may be a Tag or Component", |
|
"A [Relation] may be marked as a [Tag] or [Component].", |
|
DiagnosticCategory, DiagnosticSeverity.Info, true); |
|
|
|
public static readonly DiagnosticDescriptor SingletonImpliesComponentHint = new( |
|
$"gSG{_idCounter++:00}", "Singleton implies Component", |
|
"A [Singleton] is already implied to be a [Component].", |
|
DiagnosticCategory, DiagnosticSeverity.Info, true); |
|
|
|
public static readonly DiagnosticDescriptor BuiltInModuleMustHavePath = new( |
|
$"gSG{_idCounter++:00}", "BuiltIn Module must have Path", |
|
"A [BuiltIn, Module] must also have a [Path] set.", |
|
DiagnosticCategory, DiagnosticSeverity.Info, true); |
|
|
|
public static readonly DiagnosticDescriptor BuiltInModuleMustNotHaveMethods = new( |
|
$"gSG{_idCounter++:00}", "BuiltIn Module must not have System / Observer", |
|
"A [BuiltIn, Module] must not have [System] or [Observer] methods.", |
|
DiagnosticCategory, DiagnosticSeverity.Info, true); |
|
|
|
|
|
// Diagnostics relating to keywords / modifiers used with the symbol. |
|
|
|
public static readonly DiagnosticDescriptor ModuleMustBePartial = new( |
|
$"gSG{_idCounter++:00}", "ModuleMustBePartial", |
|
"A [Module] type must be marked as partial.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor TypeMustNotBeStatic = new( |
|
$"gSG{_idCounter++:00}", "Entity type must not be static", |
|
"Entity type must not be static.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor TypeMustNotBeAbstract = new( |
|
$"gSG{_idCounter++:00}", "Entity type must not be abstract", |
|
"Entity type must not be abstract.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
public static readonly DiagnosticDescriptor MethodMustNotBeAbstract = new( |
|
$"gSG{_idCounter++:00}", "System / Observer must not be abstract", |
|
"A [System] or [Observer] method must not be marked as abstract.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor MethodMustNotBeAsync = new( |
|
$"gSG{_idCounter++:00}", "System / Observer must not be async", |
|
"A [System] or [Observer] method must not be marked as async.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
// TODO: Check for any other weird modifiers we don't want. |
|
|
|
|
|
// Diagnostics relating to (generic) parameters on the attributes themselves. |
|
|
|
// TODO: Be more specific? |
|
public static readonly DiagnosticDescriptor InvalidTypeArgument = new( |
|
$"gSG{_idCounter++:00}", "Invalid type argument", |
|
"The specified type argument is not valid here.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
// Diagnostics relating to system / observer generic parameters. |
|
|
|
public static readonly DiagnosticDescriptor MethodMustNotBeExtension = new( |
|
$"gSG{_idCounter++:00}", "System / Observer must not be extension method", |
|
"A [System] or [Observer] method must not be an extension method.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor MethodMustHaveParameters = new( |
|
$"gSG{_idCounter++:00}", "System / Observer must have parameters", |
|
"A [System] or [Observer] must have parameters.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor MethodMustHaveExpression = new( |
|
$"gSG{_idCounter++:00}", "Iterator-only System / Observer must have expression", |
|
"An Iterator-only [System] or [Observer] must have an [Expression] set.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
public static readonly DiagnosticDescriptor MethodGenericParamAtMostOne = new( |
|
$"gSG{_idCounter++:00}", "System / Observer must have at most one generic parameter", |
|
"A [System] or [Observer] must at most one generic parameter.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
// TODO: See if we can change this wording, but try to use the correct one. (Does "open generic" work?) |
|
public static readonly DiagnosticDescriptor MethodGenericParamMustNotBeSubstutited = new( |
|
$"gSG{_idCounter++:00}", "System / Observer generic parameter must not be substituted", |
|
"The generic parameter of a [System] or [Observer] must not be substituted.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor MethodGenericParamMustNotBeConstrained = new( |
|
$"gSG{_idCounter++:00}", "System / Observer generic parameter must not be substituted", |
|
"The generic parameter of a [System] or [Observer] must not be constrained.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
// Diagnostics relating to system / observer parameters. |
|
|
|
public static readonly DiagnosticDescriptor ParamMustNotBeArray = new( |
|
$"gSG{_idCounter++:00}", "Parameter must not be array", |
|
"Parameter must not be an array type.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamMustNotBePointer = new( |
|
$"gSG{_idCounter++:00}", "Parameter must not be pointer", |
|
"Parameter must not be a pointer type.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamMustNotBeGenericType = new( |
|
$"gSG{_idCounter++:00}", "Parameter must not be generic type", |
|
"Parameter must not be a generic type parameter.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamMustNotBePrimitive = new( |
|
$"gSG{_idCounter++:00}", "Parameter must not be primitive", |
|
"Parameter must not be a primitive type.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamMustNotBeGeneric = new( |
|
$"gSG{_idCounter++:00}", "Parameter must not be geric", |
|
"Parameter must not be generic (except Iterator, World, Entity, Nullable, Has, Not and Or).", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamDoesNotSupportOptional = new( |
|
$"gSG{_idCounter++:00}", "Parameter does not support optional", |
|
"Parameter does not support optional value syntax.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamByRefMustBeValueType = new( |
|
$"gSG{_idCounter++:00}", "ByRef parameter must be a value type", |
|
"ByRef (in/out/ref) parameter must be a value type (struct).", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor ParamByRefMustNotBeNullable = new( |
|
$"gSG{_idCounter++:00}", "ByRef parameter must not be nullable", |
|
"ByRef (in/out/ref) parameter must not be nullable.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
// TODO: Make this more descriptive. (Special = Has<>, Not<> and [Tag]?) |
|
public static readonly DiagnosticDescriptor SpecialMustNotBeByRef = new( |
|
$"gSG{_idCounter++:00}", "Special parameter must not be ByRef", |
|
"Special parameter must not be ByRef (in/out/ref).", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor SpecialArgMustNotBeNullable = new( |
|
$"gSG{_idCounter++:00}", "Special type argument must not be nullable", |
|
"Special type argument must not be nullable.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor SpecialArgMustNotBeGeneric = new( |
|
$"gSG{_idCounter++:00}", "Special type argument must not be generic", |
|
"Special type argument must not be generic.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
|
|
public static readonly DiagnosticDescriptor UniqueParamMustNotBeByRef = new( |
|
$"gSG{_idCounter++:00}", "Unique parameter must not be ByRef", |
|
"Unique parameter must not be ByRef (in/out/ref).", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor UniqueParamMustNotBeNullable = new( |
|
$"gSG{_idCounter++:00}", "Unique parameter must not be nullable", |
|
"Unique parameter must not be nullable.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor UniqueParamGenericMustMatch = new( |
|
$"gSG{_idCounter++:00}", "Unique parameter generic type parameter must match method", |
|
"Unique parameter's generic type parameter must match the method's type parameter.", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
|
|
public static readonly DiagnosticDescriptor UniqueParamNotSupported = new( |
|
$"gSG{_idCounter++:00}", "Unique parameter does not support this attribute", |
|
"Unique parameter does not support {0}", |
|
DiagnosticCategory, DiagnosticSeverity.Error, true); |
|
}
|
|
|