From 9ebcb1f33f56aa5029ad3c2c95863cd943f2c76f Mon Sep 17 00:00:00 2001 From: Benjamin Friedman Wilson Date: Fri, 1 Dec 2023 15:57:21 +0100 Subject: [PATCH] update generator templates --- .../templates/cli/src/cli/cli-util.ts | 5 +++-- .../core/src/language/language-id-module.ts | 12 ++++++++---- .../templates/web/src/language/main-browser.ts | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/generator-langium/templates/cli/src/cli/cli-util.ts b/packages/generator-langium/templates/cli/src/cli/cli-util.ts index 63d2e6ad3..e0789d167 100644 --- a/packages/generator-langium/templates/cli/src/cli/cli-util.ts +++ b/packages/generator-langium/templates/cli/src/cli/cli-util.ts @@ -1,10 +1,11 @@ -import type { AstNode, LangiumDocument, LangiumServices } from 'langium'; +import type { AstNode, LangiumCoreServices, LangiumDocument } from 'langium'; +import type { LangiumServices } from 'langium/lsp'; import chalk from 'chalk'; import * as path from 'node:path'; import * as fs from 'node:fs'; import { URI } from 'langium'; -export async function extractDocument(fileName: string, services: LangiumServices): Promise { +export async function extractDocument(fileName: string, services: LangiumCoreServices): Promise { const extensions = services.LanguageMetaData.fileExtensions; if (!extensions.includes(path.extname(fileName))) { console.error(chalk.yellow(`Please choose a file with one of these extensions: ${extensions}.`)); diff --git a/packages/generator-langium/templates/core/src/language/language-id-module.ts b/packages/generator-langium/templates/core/src/language/language-id-module.ts index 11bb53e14..5427c6b10 100644 --- a/packages/generator-langium/templates/core/src/language/language-id-module.ts +++ b/packages/generator-langium/templates/core/src/language/language-id-module.ts @@ -1,5 +1,7 @@ -import type { DefaultSharedModuleContext, LangiumServices, LangiumSharedServices, Module, PartialLangiumServices } from 'langium'; +import type { DefaultSharedModuleContext, Module, PartialLangiumCoreServices } from 'langium'; +import type { PartialLangiumLSPServices, LangiumSharedServices, LangiumServices } from 'langium/lsp'; import { createDefaultModule, createDefaultSharedModule, inject } from 'langium'; +import { createSharedLSPModule, createLSPModule } from 'langium/lsp'; import { <%= LanguageName %>GeneratedModule, <%= LanguageName %>GeneratedSharedModule } from './generated/module.js'; import { <%= LanguageName %>Validator, registerValidationChecks } from './<%= language-id %>-validator.js'; @@ -23,7 +25,7 @@ export type <%= LanguageName %>Services = LangiumServices & <%= LanguageName %>A * declared custom services. The Langium defaults can be partially specified to override only * selected services, while the custom services must be fully specified. */ -export const <%= LanguageName %>Module: Module<<%= LanguageName %>Services, PartialLangiumServices & <%= LanguageName %>AddedServices> = { +export const <%= LanguageName %>Module: Module<<%= LanguageName %>Services, PartialLangiumCoreServices & PartialLangiumLSPServices & <%= LanguageName %>AddedServices> = { validation: { <%= LanguageName %>Validator: () => new <%= LanguageName %>Validator() } @@ -50,12 +52,14 @@ export function create<%= LanguageName %>Services(context: DefaultSharedModuleCo } { const shared = inject( createDefaultSharedModule(context), - <%= LanguageName %>GeneratedSharedModule + <%= LanguageName %>GeneratedSharedModule, + createSharedLSPModule(context), ); const <%= LanguageName %> = inject( createDefaultModule({ shared }), <%= LanguageName %>GeneratedModule, - <%= LanguageName %>Module + <%= LanguageName %>Module, + createLSPModule({ shared }) ); shared.ServiceRegistry.register(<%= LanguageName %>); registerValidationChecks(<%= LanguageName %>); diff --git a/packages/generator-langium/templates/web/src/language/main-browser.ts b/packages/generator-langium/templates/web/src/language/main-browser.ts index e81288227..73a3350d4 100644 --- a/packages/generator-langium/templates/web/src/language/main-browser.ts +++ b/packages/generator-langium/templates/web/src/language/main-browser.ts @@ -1,4 +1,5 @@ -import { EmptyFileSystem, startLanguageServer } from 'langium'; +import { EmptyFileSystem } from 'langium'; +import { startLanguageServer } from 'langium/lsp'; import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser.js'; import { create<%= LanguageName %>Services } from './<%= language-id %>-module.js';