langium icon indicating copy to clipboard operation
langium copied to clipboard

Generate more const in ast.ts

Open cdietrich opened this issue 3 months ago • 1 comments

it would be nice to have consts to be generated for additional stuff in the grammar.

  1. keywords

we currently generate

export namespace <grammar> {
    export type KeywordNames =
        | "x"
        | "y"
        | "z";
}

it would be nice to have access to the keywords list at runtime too

export const KeywordNames = ["x", "y", "z"] as const
export type KeywordNames = (typeof KeywordNames)[number]
  1. types (am not sure about this)

grammar:

type MyFakeEnum = 'A' | 'B' | 'C';

interface MyIf {
    name: MyFakeEnum;
}

generates

export type MyFakeEnum = 'A' | 'B' | 'C';

export interface MyIf extends langium.AstNode {
    readonly $type: 'MyIf';
    name: MyFakeEnum;
}

having a way to have the possible values of MyFakeEnum available at runtime would be nice too.

cdietrich avatar Sep 25 '25 15:09 cdietrich

originally reported here https://github.com/eclipse-langium/langium/pull/1979#issuecomment-3228415983

cc @JohannesMeierSE @joao-silveira

cdietrich avatar Sep 25 '25 15:09 cdietrich