Skip to content

Commit

Permalink
update generator templates
Browse files Browse the repository at this point in the history
  • Loading branch information
montymxb committed Dec 1, 2023
1 parent 60adb2c commit 9ebcb1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/generator-langium/templates/cli/src/cli/cli-util.ts
Original file line number Diff line number Diff line change
@@ -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<LangiumDocument> {
export async function extractDocument(fileName: string, services: LangiumCoreServices): Promise<LangiumDocument> {
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}.`));
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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()
}
Expand All @@ -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 %>);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit 9ebcb1f

Please sign in to comment.