Skip to content

Commit

Permalink
Make cli, web and extension compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Jun 13, 2024
1 parent 216df86 commit 3aac21b
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 49 deletions.
4 changes: 3 additions & 1 deletion packages/generator-langium/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ export class LangiumGenerator extends Generator {
this.sourceRoot(path.join(__dirname, `${BASE_DIR}/${PACKAGE_WEB}`));
const webFiles = [
'package.json',
'langium-config.json',
'language-configuration.json',
'tsconfig.json',
'index.html',
'vite.config.ts',
'src',
'static'
Expand All @@ -253,6 +253,7 @@ export class LangiumGenerator extends Generator {
templateCopyOptions
);
}
mainPackageJson.workspaces.push('packages/web');
}

if (this.answers.includeVSCode) {
Expand All @@ -272,6 +273,7 @@ export class LangiumGenerator extends Generator {
templateCopyOptions
);
}
mainPackageJson.workspaces.push('packages/extension');
}

this.fs.writeJSON(this._extensionPath('.package.json'), mainPackageJson, undefined, 4);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../language/generated/ast.js';
import type { Model } from '<%= language-id %>-language';
import { expandToNode, joinToNode, toString } from 'langium/generate';
import * as fs from 'node:fs';
import * as path from 'node:path';
Expand Down
5 changes: 2 additions & 3 deletions packages/generator-langium/templates/packages/cli/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Model } from '../language/generated/ast.js';
import type { Model } from '<%= language-id %>-language';
import { create<%= LanguageName %>Services, <%= LanguageName %>LanguageMetaData } from '<%= language-id %>-language';
import chalk from 'chalk';
import { Command } from 'commander';
import { <%= LanguageName %>LanguageMetaData } from '../language/generated/module.js';
import { create<%= LanguageName %>Services } from '../language/<%= language-id %>-module.js';
import { extractAstNode } from './cli-util.js';
import { generateJavaScript } from './generator.js';
import { NodeFileSystem } from 'langium/node';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { startLanguageServer } from 'langium/lsp';
import { NodeFileSystem } from 'langium/node';
import { createConnection, ProposedFeatures } from 'vscode-languageserver/node.js';
import { create<%= LanguageName %>Services } from './<%= language-id %>-module.js';
import { create<%= LanguageName %>Services } from '<%= language-id %>-language';

// Create a connection to the client
const connection = createConnection(ProposedFeatures.all);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"fileExtensions": <%= file-extension %>,
"textMate": {
"out": "syntaxes/<%= language-id %>.tmLanguage.json"
},
"monarch": {
"out": "src/syntaxes/<%= language-id %>.monarch.ts"
}
}],
"out": "src/generated"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
"out",
"src"
],
"main": "./out/index.js",
"module": "./out/index.js",
"exports": {
".": {
"types": "./out/index.d.ts",
"default": "./out/index.js"
}
},
"typesVersions": {
"*": {
".": [
"out/index"
]
}
},
"scripts": {
"build": "echo 'No build step'",
"langium:generate": "langium generate",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './<%= language-id %>-module.js';
export * from './<%= language-id %>-validator.js';
export * from './generated/ast.js';
export * from './generated/grammar.js';
export * from './generated/module.js';
export { default as monarchSyntax } from './syntaxes/<%= language-id %>.monarch.js';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { afterEach, beforeAll, describe, expect, test } from "vitest";
import { EmptyFileSystem, type LangiumDocument } from "langium";
import { expandToString as s } from "langium/generate";
import { clearDocuments, parseHelper } from "langium/test";
import { create<%= LanguageName %>Services } from "../../src/language/<%= language-id %>-module.js";
import { Model, isModel } from "../../src/language/generated/ast.js";
import { create<%= LanguageName %>Services, isModel, Model } from "<%= language-id %>-language";

let services: ReturnType<typeof create<%= LanguageName %>Services>;
let parse: ReturnType<typeof parseHelper<Model>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { beforeAll, describe, expect, test } from "vitest";
import { EmptyFileSystem, type LangiumDocument } from "langium";
import { expandToString as s } from "langium/generate";
import { parseHelper } from "langium/test";
import { create<%= LanguageName %>Services } from "../../src/language/<%= language-id %>-module.js";
import { Model, isModel } from "../../src/language/generated/ast.js";
import { create<%= LanguageName %>Services, isModel, Model } from "<%= language-id %>-language";

let services: ReturnType<typeof create<%= LanguageName %>Services>;
let parse: ReturnType<typeof parseHelper<Model>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { EmptyFileSystem, type LangiumDocument } from "langium";
import { expandToString as s } from "langium/generate";
import { parseHelper } from "langium/test";
import type { Diagnostic } from "vscode-languageserver-types";
import { create<%= LanguageName %>Services } from "../../src/language/<%= language-id %>-module.js";
import { Model, isModel } from "../../src/language/generated/ast.js";
import { create<%= LanguageName %>Services, isModel, Model } from "<%= language-id %>-language";

let services: ReturnType<typeof create<%= LanguageName %>Services>;
let parse: ReturnType<typeof parseHelper<Model>>;
Expand Down

This file was deleted.

15 changes: 7 additions & 8 deletions packages/generator-langium/templates/packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
"src"
],
"scripts": {
"build": "npm run build",
"bundle": "vite build",
"build": "vite build",
"bundle:serve": "http-server ./dist --port 5175",
"dev": "vite",
"dev:debug": "vite --debug --force",
"serve": "npm run dev"
},
"dependencies": {
"@codingame/monaco-vscode-editor-service-override": "~3.2.3",
"@codingame/monaco-vscode-keybindings-service-override": "~3.2.3",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~3.2.3",
"monaco-editor-wrapper": "~4.0.2",
"monaco-languageclient": "~8.1.1",
"vscode": "npm:@codingame/monaco-vscode-api@~3.2.3"
"@codingame/monaco-vscode-editor-service-override": "~5.2.0",
"@codingame/monaco-vscode-keybindings-service-override": "~5.2.0",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~5.2.0",
"monaco-editor-wrapper": "~5.2.0",
"monaco-languageclient": "~8.5.0",
"vscode": "npm:@codingame/monaco-vscode-api@~5.2.0"
},
"devDependencies": {
"@codingame/esbuild-import-meta-url-plugin": "~1.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// <reference lib="WebWorker" />

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';
import { create<%= LanguageName %>Services } from '<%= language-id %>-language';

declare const self: DedicatedWorkerGlobalScope;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
import { configureWorker, defineUserServices } from './setupCommon.js';
import monarchSyntax from "./syntaxes/<%= language-id %>.monarch.js";
import { monarchSyntax } from '<%= language-id %>-language';

export const setupConfigClassic = (): UserConfig => {
return {
wrapperConfig: {
serviceConfig: defineUserServices(),
editorAppConfig: {
$type: 'classic',
languageId: '<%= language-id %>',
code: `// <%= RawLanguageName %> is running in the web!`,
useDiffEditor: false,
languageExtensionConfig: { id: 'langium' },
languageDef: monarchSyntax,
codeResources: {
main: {
text: '// <%= RawLanguageName %> is running in the web!',
uri: '/workspace/hello-world.<%= file-extension %>',
}
},
languageDef: {
languageExtensionConfig: { id: '<%= language-id %>' },
monarchLanguage: monarchSyntax
},
editorOptions: {
'semanticHighlighting.enabled': true,
theme: 'vs-dark'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export const configureMonacoWorkers = () => {

export const configureWorker = (): LanguageClientConfig => {
// vite does not extract the worker properly if it is URL is a variable
const lsWorker = new Worker(new URL('./language/main-browser', import.meta.url), {
const lsWorker = new Worker(new URL('./main-browser', import.meta.url), {
type: 'module',
name: '<%= LanguageName %> Language Server'
});

return {
languageId: '<%= language-id %>',
options: {
$type: 'WorkerDirect',
worker: lsWorker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { configureWorker, defineUserServices } from './setupCommon.js';
export const setupConfigExtended = (): UserConfig => {
const extensionFilesOrContents = new Map();
extensionFilesOrContents.set('/language-configuration.json', new URL('../language-configuration.json', import.meta.url));
extensionFilesOrContents.set('/<%= language-id %>-grammar.json', new URL('../syntaxes/<%= language-id %>.tmLanguage.json', import.meta.url));
extensionFilesOrContents.set('/<%= language-id %>-grammar.json', new URL('../../language/syntaxes/<%= language-id %>.tmLanguage.json', import.meta.url));

return {
wrapperConfig: {
serviceConfig: defineUserServices(),
editorAppConfig: {
$type: 'extended',
languageId: '<%= language-id %>',
code: `// <%= RawLanguageName %> is running in the web!`,
useDiffEditor: false,
codeResources: {
main: {
text: '// <%= RawLanguageName %> is running in the web!',
uri: '/workspace/hello-world.<%= file-extension %>',
}
},
extensions: [{
config: {
name: '<%= language-id %>-web',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"rootDir": "src",
"outDir": "out",
"declarationDir": "out",
"lib": ["ES2022", "dom"]
},
"references": [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/generator-langium/templates/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"module": "ES2022",
"moduleResolution": "Bundler",
"lib": ["ES2020"],
"lib": ["ES2022"],
"sourceMap": true,
"strict": true,
"noUnusedLocals": true,
Expand Down

0 comments on commit 3aac21b

Please sign in to comment.