-
Notifications
You must be signed in to change notification settings - Fork 84
Description
So far, the generated AST reflection code is intended to be used only by the Langium framework itself. Therefore it contains only those information which are required for the current Langium-internal use cases:
- The parsing needs to know the default value for a properties
- The linking needs the target type of a reference properties to query the correct candidates of the scope
All other information are skipped for reduced memory consumption and smaller bundle sizes. Therefore the AST reflection is considered as "internal API".
In order to make this reflection more generic to be used for (meta-)modeling in general or to be programmatically exploited for other tools outside of Langium, @spoenemann and @JohannesMeierSE discussed some ideas. If there is a need for them, we might implement them in upcoming (major) versions.
Related are: #1942, #1954, branch jm/1184-property-types
with some WIP experiments (unpolished code!)
Provide types for all properties
At the moment, PropertyMetaData
contains only type information for properties which are references (referenceType?: string
), since this is enough for the current use cases. To provide type information for all properties, type: string, kind: TypePropertyKind
(with type TypePropertyKind = 'Reference' | 'Containment' | 'Primitive'
) could be used.
Make the multiplicities explicit
At the moment, multiplicities are visible only by []
as defaultValue
. Multiplicities could be made explicit by providing properties like lowerBound: number, upperBound: number
or mandatory: boolean, many: boolean
.
Provide information about properties of union types
At the moment, no properties are specified for type C = A | B
, even if A
and B
have the property c: boolean
in common:
type C = A | B
type A = {
a: string
c: boolean
}
type B = {
b: string
c: boolean
}
If these joint properties are reference properties, they might be used in scope providers, but the constant C.c
does not exist. In the reflection
, the properties
are missing as well.
Integration
An approach to integrate these additional information into the reflection meta data without breaking changes could be to introduce a new configuration in langium-config.json
like "extendedMetaData": true
. In that case, the ast-generator.ts
generates more/other meta data.
To handle other/updated properties (e.g. type
instead of referenceType
, see above), another base reflection class (export class XXXAstReflection extends langium.AbstractAstReflection
) could be generated, e.g. langium.ExtendedAstReflection
.