Name collision in generated ast.ts
When defining in mydsl.langium file an interface named Reference, the generated ast.ts does not compile.
Langium version: 3.1 Package name: langium
Steps To Reproduce
define an interface named 'Reference' in mydsl.langium
interface Reference {
name:string
}
Build the project
The current behavior
The project fails to build due to a conflict with imported types from langium in src/language/generated/ast.ts:
import type { AstNode, Reference, ReferenceInfo, TypeMetaData } from 'langium';
The expected behavior
Definition of interfaces like AstNode, Reference, ReferenceInfo or TypeMetaData in langium file should not collide with imports.
We have a validation for protecting against name collisions with the JavaScript runtime. See here. We would need a separate list for reserved names of the Langium imports.
Another alternative would be to import types with a specific prefix (e.g. _langium_) and to prohibit rule names in the grammar from starting with this prefix ?
e.g:
import type { AstNode as _langium_AstNode,
Reference as _langium_Reference,
ReferenceInfo as _langium_ReferenceInfo,
TypeMetaData as _langium_TypeMetaData } from 'langium';
I don't know if this concept would be valid for other reserved keywords.
Hey @msujew,
I can try to provide a PR for this issue.
I think that doing a single import like
import * as langium from 'langium';
and adding the 'langium' keyword to reserved names would be more generic.
Sure, that sounds reasonable to me 👍