From 5547dabb1b6951e76c3df5f87a4e7a7680ea6fdc Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Thu, 19 Sep 2024 13:27:41 +0200 Subject: [PATCH] Always generate the `mode` meta data --- .../arithmetics/src/language-server/generated/module.ts | 3 ++- .../domainmodel/src/language-server/generated/module.ts | 3 ++- .../requirements/src/language-server/generated/module.ts | 6 ++++-- .../statemachine/src/language-server/generated/module.ts | 3 ++- packages/langium-cli/src/generator/module-generator.ts | 7 ++++--- packages/langium/src/grammar/generated/module.ts | 3 ++- packages/langium/src/languages/language-meta-data.ts | 6 +++--- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/arithmetics/src/language-server/generated/module.ts b/examples/arithmetics/src/language-server/generated/module.ts index b94eefffa..c3f024fc8 100644 --- a/examples/arithmetics/src/language-server/generated/module.ts +++ b/examples/arithmetics/src/language-server/generated/module.ts @@ -10,7 +10,8 @@ import { ArithmeticsGrammar } from './grammar.js'; export const ArithmeticsLanguageMetaData = { languageId: 'arithmetics', fileExtensions: ['.calc'], - caseInsensitive: true + caseInsensitive: true, + mode: 'development' } as const satisfies LanguageMetaData; export const ArithmeticsGeneratedSharedModule: Module = { diff --git a/examples/domainmodel/src/language-server/generated/module.ts b/examples/domainmodel/src/language-server/generated/module.ts index c432c8821..110b44663 100644 --- a/examples/domainmodel/src/language-server/generated/module.ts +++ b/examples/domainmodel/src/language-server/generated/module.ts @@ -10,7 +10,8 @@ import { DomainModelGrammar } from './grammar.js'; export const DomainModelLanguageMetaData = { languageId: 'domain-model', fileExtensions: ['.dmodel'], - caseInsensitive: false + caseInsensitive: false, + mode: 'development' } as const satisfies LanguageMetaData; export const parserConfig: IParserConfig = { diff --git a/examples/requirements/src/language-server/generated/module.ts b/examples/requirements/src/language-server/generated/module.ts index b502f3f9d..d23da3f71 100644 --- a/examples/requirements/src/language-server/generated/module.ts +++ b/examples/requirements/src/language-server/generated/module.ts @@ -10,13 +10,15 @@ import { RequirementsGrammar, TestsGrammar } from './grammar.js'; export const RequirementsLanguageMetaData = { languageId: 'requirements-lang', fileExtensions: ['.req'], - caseInsensitive: false + caseInsensitive: false, + mode: 'development' } as const satisfies LanguageMetaData; export const TestsLanguageMetaData = { languageId: 'tests-lang', fileExtensions: ['.tst'], - caseInsensitive: false + caseInsensitive: false, + mode: 'development' } as const satisfies LanguageMetaData; export const RequirementsAndTestsGeneratedSharedModule: Module = { diff --git a/examples/statemachine/src/language-server/generated/module.ts b/examples/statemachine/src/language-server/generated/module.ts index b8b3154ea..8fb40db2a 100644 --- a/examples/statemachine/src/language-server/generated/module.ts +++ b/examples/statemachine/src/language-server/generated/module.ts @@ -10,7 +10,8 @@ import { StatemachineGrammar } from './grammar.js'; export const StatemachineLanguageMetaData = { languageId: 'statemachine', fileExtensions: ['.statemachine'], - caseInsensitive: false + caseInsensitive: false, + mode: 'development' } as const satisfies LanguageMetaData; export const StatemachineGeneratedSharedModule: Module = { diff --git a/packages/langium-cli/src/generator/module-generator.ts b/packages/langium-cli/src/generator/module-generator.ts index 89789f6d0..03302677b 100644 --- a/packages/langium-cli/src/generator/module-generator.ts +++ b/packages/langium-cli/src/generator/module-generator.ts @@ -5,7 +5,7 @@ ******************************************************************************/ import type { Grammar, IParserConfig } from 'langium'; -import { EOL, type Generated, expandToNode, joinToNode, toString } from 'langium/generate'; +import { type Generated, expandToNode, joinToNode, toString } from 'langium/generate'; import type { LangiumConfig, LangiumLanguageConfig } from '../package-types.js'; import { generatedHeader } from './node-util.js'; @@ -42,13 +42,14 @@ export function generateModule(grammars: Grammar[], config: LangiumConfig, gramm grammarsWithName, grammar => { const config = grammarConfigMap.get(grammar)!; - const modeValue = mode ? `,${EOL} mode: '${mode}'` : ''; + const modeValue = mode === 'production' ? mode : 'development'; return expandToNode` export const ${ grammar.name }LanguageMetaData = { languageId: '${config.id}', fileExtensions: [${config.fileExtensions && joinToNode(config.fileExtensions, e => appendQuotesAndDot(e), { separator: ', ' })}], - caseInsensitive: ${Boolean(config.caseInsensitive)}${modeValue} + caseInsensitive: ${Boolean(config.caseInsensitive)}, + mode: '${modeValue}' } as const satisfies LanguageMetaData; `; }, diff --git a/packages/langium/src/grammar/generated/module.ts b/packages/langium/src/grammar/generated/module.ts index ad009b1e8..94d62306f 100644 --- a/packages/langium/src/grammar/generated/module.ts +++ b/packages/langium/src/grammar/generated/module.ts @@ -13,7 +13,8 @@ import { LangiumGrammarGrammar } from './grammar.js'; export const LangiumGrammarLanguageMetaData = { languageId: 'langium', fileExtensions: ['.langium'], - caseInsensitive: false + caseInsensitive: false, + mode: 'development' } as const satisfies LanguageMetaData; export const LangiumGrammarParserConfig: IParserConfig = { diff --git a/packages/langium/src/languages/language-meta-data.ts b/packages/langium/src/languages/language-meta-data.ts index 9f6381e3f..9374aee21 100644 --- a/packages/langium/src/languages/language-meta-data.ts +++ b/packages/langium/src/languages/language-meta-data.ts @@ -13,8 +13,8 @@ export interface LanguageMetaData { caseInsensitive: boolean; /** * Mode used to optimize code for development or production environments. - * - * In production mode, all lexer/parser validations are disabled. + * + * In production mode, all Chevrotain lexer/parser validations are disabled. */ - mode?: 'development' | 'production'; + mode: 'development' | 'production'; }