diff --git a/packages/generator-langium/templates/.vscode/launch.json b/packages/generator-langium/templates/.vscode/launch.json index e44e9fbc0..454b7dc95 100644 --- a/packages/generator-langium/templates/.vscode/launch.json +++ b/packages/generator-langium/templates/.vscode/launch.json @@ -10,11 +10,12 @@ "type": "extensionHost", "request": "launch", "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" + "--extensionDevelopmentPath=${workspaceFolder}/packages/extension" ], "sourceMaps": true, "outFiles": [ - "${workspaceFolder}/out/**/*.js" + "${workspaceFolder}/packages/language/out/**/*.js", + "${workspaceFolder}/packages/extension/out/**/*.js" ] }, { @@ -27,7 +28,8 @@ ], "sourceMaps": true, "outFiles": [ - "${workspaceFolder}/out/**/*.js", + "${workspaceFolder}/packages/language/out/**/*.js", + "${workspaceFolder}/packages/extension/out/**/*.js", "${workspaceFolder}/node_modules/langium" ] } diff --git a/packages/generator-langium/templates/gitignore.txt b/packages/generator-langium/templates/gitignore.txt index 4c9df9f0b..32c0c06f5 100644 --- a/packages/generator-langium/templates/gitignore.txt +++ b/packages/generator-langium/templates/gitignore.txt @@ -4,5 +4,5 @@ !.vscode/tasks.json node_modules/ out/ -src/language/generated/ +src/generated/ syntaxes/ diff --git a/packages/generator-langium/templates/package.json b/packages/generator-langium/templates/package.json index 6048bac53..3e85776f3 100644 --- a/packages/generator-langium/templates/package.json +++ b/packages/generator-langium/templates/package.json @@ -1,17 +1,12 @@ { - "name": "<%= extension-name %>-base", + "name": "<%= extension-name %>-workspace", "description": "Base workspace package", "version": "0.0.1", "type": "module", "private": true, - "files": [ - "out", - "src" - ], "scripts": { - "compile": "tsc -b tsconfig.build.json", "watch": "tsc -b tsconfig.build.json --watch", - "build": "npm run compile && npm run build --workspaces", + "build": "tsc -b tsconfig.build.json && npm run build --workspaces", "lint": "eslint src --ext ts", "langium:generate": "npm run --workspace packages/language langium:generate", "langium:watch": "npm run --workspace packages/language langium:watch" diff --git a/packages/generator-langium/templates/packages/cli/src/generator.ts b/packages/generator-langium/templates/packages/cli/src/generator.ts index fe6c8f973..0866085ef 100644 --- a/packages/generator-langium/templates/packages/cli/src/generator.ts +++ b/packages/generator-langium/templates/packages/cli/src/generator.ts @@ -2,7 +2,7 @@ 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'; -import { extractDestinationAndName } from './cli-util.js'; +import { extractDestinationAndName } from './util.js'; export function generateJavaScript(model: Model, filePath: string, destination: string | undefined): string { const data = extractDestinationAndName(filePath, destination); diff --git a/packages/generator-langium/templates/packages/cli/src/main.ts b/packages/generator-langium/templates/packages/cli/src/main.ts index 4dbd61697..41ab16def 100644 --- a/packages/generator-langium/templates/packages/cli/src/main.ts +++ b/packages/generator-langium/templates/packages/cli/src/main.ts @@ -2,7 +2,7 @@ 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 { extractAstNode } from './cli-util.js'; +import { extractAstNode } from './util.js'; import { generateJavaScript } from './generator.js'; import { NodeFileSystem } from 'langium/node'; import * as url from 'node:url'; diff --git a/packages/generator-langium/templates/packages/cli/src/cli-util.ts b/packages/generator-langium/templates/packages/cli/src/util.ts similarity index 100% rename from packages/generator-langium/templates/packages/cli/src/cli-util.ts rename to packages/generator-langium/templates/packages/cli/src/util.ts diff --git a/packages/generator-langium/templates/packages/extension/.vscodeignore b/packages/generator-langium/templates/packages/extension/.vscodeignore index 4f97a2668..dceac54db 100644 --- a/packages/generator-langium/templates/packages/extension/.vscodeignore +++ b/packages/generator-langium/templates/packages/extension/.vscodeignore @@ -1,4 +1,2 @@ .vscode/** .vscode-test/** -.gitignore -langium-quickstart.md diff --git a/packages/generator-langium/templates/packages/language/langium-quickstart.md b/packages/generator-langium/templates/packages/language/langium-quickstart.md index 0c3fdb472..746d3ceb8 100644 --- a/packages/generator-langium/templates/packages/language/langium-quickstart.md +++ b/packages/generator-langium/templates/packages/language/langium-quickstart.md @@ -3,32 +3,33 @@ ## What's in the folder This folder contains all necessary files for your language extension. - * `package.json` - the manifest file in which you declare your language support. - * `language-configuration.json` - the language configuration used in the VS Code editor, defining the tokens that are used for comments and brackets. - * `src/extension/main.ts` - the main code of the extension, which is responsible for launching a language server and client. - * `src/language/<%= language-id %>.langium` - the grammar definition of your language. - * `src/language/main.ts` - the entry point of the language server process. - * `src/language/<%= language-id %>-module.ts` - the dependency injection module of your language implementation. Use this to register overridden and added services. - * `src/language/<%= language-id %>-validator.ts` - an example validator. You should change it to reflect the semantics of your language. - * `src/cli/main.ts` - the entry point of the command line interface (CLI) of your language. - * `src/cli/generator.ts` - the code generator used by the CLI to write output files from DSL documents. - * `src/cli/cli-util.ts` - utility code for the CLI. + +* `package.json` - the manifest file in which you declare your language support. +* `language-configuration.json` - the language configuration used in the VS Code editor, defining the tokens that are used for comments and brackets. +* `src/extension/main.ts` - the main code of the extension, which is responsible for launching a language server and client. +* `src/language/<%= language-id %>.langium` - the grammar definition of your language. +* `src/language/main.ts` - the entry point of the language server process. +* `src/language/<%= language-id %>-module.ts` - the dependency injection module of your language implementation. Use this to register overridden and added services. +* `src/language/<%= language-id %>-validator.ts` - an example validator. You should change it to reflect the semantics of your language. +* `src/cli/main.ts` - the entry point of the command line interface (CLI) of your language. +* `src/cli/generator.ts` - the code generator used by the CLI to write output files from DSL documents. +* `src/cli/util.ts` - utility code for the CLI. ## Get up and running straight away - * Run `npm run langium:generate` to generate TypeScript code from the grammar definition. - * Run `npm run build` to compile all TypeScript code. - * Press `F5` to open a new window with your extension loaded. - * Create a new file with a file name suffix matching your language. - * Verify that syntax highlighting, validation, completion etc. are working as expected. - * Run `node ./bin/cli` to see options for the CLI; `node ./bin/cli generate ` generates code for a given DSL file. +* Run `npm run langium:generate` to generate TypeScript code from the grammar definition. +* Run `npm run build` to compile all TypeScript code. +* Press `F5` to open a new window with your extension loaded. +* Create a new file with a file name suffix matching your language. +* Verify that syntax highlighting, validation, completion etc. are working as expected. +* Run `node ./bin/cli` to see options for the CLI; `node ./bin/cli generate ` generates code for a given DSL file. ## Make changes - * Run `npm run watch` to have the TypeScript compiler run automatically after every change of the source files. - * Run `npm run langium:watch` to have the Langium generator run automatically after every change of the grammar declaration. - * You can relaunch the extension from the debug toolbar after making changes to the files listed above. - * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. +* Run `npm run watch` to have the TypeScript compiler run automatically after every change of the source files. +* Run `npm run langium:watch` to have the Langium generator run automatically after every change of the grammar declaration. +* You can relaunch the extension from the debug toolbar after making changes to the files listed above. +* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. ## Install your extension diff --git a/packages/generator-langium/templates/packages/language/test/linking/linking.test.ts b/packages/generator-langium/templates/packages/language/test/linking.test.ts similarity index 100% rename from packages/generator-langium/templates/packages/language/test/linking/linking.test.ts rename to packages/generator-langium/templates/packages/language/test/linking.test.ts diff --git a/packages/generator-langium/templates/packages/language/test/parsing/parsing.test.ts b/packages/generator-langium/templates/packages/language/test/parsing.test.ts similarity index 91% rename from packages/generator-langium/templates/packages/language/test/parsing/parsing.test.ts rename to packages/generator-langium/templates/packages/language/test/parsing.test.ts index f27815ed5..0d6e54354 100644 --- a/packages/generator-langium/templates/packages/language/test/parsing/parsing.test.ts +++ b/packages/generator-langium/templates/packages/language/test/parsing.test.ts @@ -2,7 +2,8 @@ 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, isModel, Model } from "<%= language-id %>-language"; +import type { Model } from "<%= language-id %>-language"; +import { create<%= LanguageName %>Services, isModel } from "<%= language-id %>-language"; let services: ReturnTypeServices>; let parse: ReturnType>; @@ -54,6 +55,6 @@ function checkDocumentValid(document: LangiumDocument): string | undefined { ${document.parseResult.parserErrors.map(e => e.message).join('\n ')} ` || document.parseResult.value === undefined && `ParseResult is 'undefined'.` - || !isModel(document.parseResult.value) && `Root AST object is a ${document.parseResult.value.$type}, expected a '${Model}'.` + || !isModel(document.parseResult.value) && `Root AST object is a ${document.parseResult.value.$type}, expected a Model'.` || undefined; } diff --git a/packages/generator-langium/templates/packages/language/test/validating/validating.test.ts b/packages/generator-langium/templates/packages/language/test/validating.test.ts similarity index 92% rename from packages/generator-langium/templates/packages/language/test/validating/validating.test.ts rename to packages/generator-langium/templates/packages/language/test/validating.test.ts index fe8ac1c22..bd6432790 100644 --- a/packages/generator-langium/templates/packages/language/test/validating/validating.test.ts +++ b/packages/generator-langium/templates/packages/language/test/validating.test.ts @@ -3,7 +3,8 @@ 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, isModel, Model } from "<%= language-id %>-language"; +import type { Model } from "<%= language-id %>-language"; +import { create<%= LanguageName %>Services, isModel } from "<%= language-id %>-language"; let services: ReturnTypeServices>; let parse: ReturnType>; @@ -19,7 +20,7 @@ beforeAll(async () => { }); describe('Validating', () => { - + test('check no errors', async () => { document = await parse(` person Langium @@ -56,7 +57,7 @@ function checkDocumentValid(document: LangiumDocument): string | undefined { ${document.parseResult.parserErrors.map(e => e.message).join('\n ')} ` || document.parseResult.value === undefined && `ParseResult is 'undefined'.` - || !isModel(document.parseResult.value) && `Root AST object is a ${document.parseResult.value.$type}, expected a '${Model}'.` + || !isModel(document.parseResult.value) && `Root AST object is a ${document.parseResult.value.$type}, expected a 'Model'.` || undefined; } diff --git a/packages/generator-langium/templates/packages/language/tsconfig.src.json b/packages/generator-langium/templates/packages/language/tsconfig.src.json index 87e2fcdc6..b95fbed91 100644 --- a/packages/generator-langium/templates/packages/language/tsconfig.src.json +++ b/packages/generator-langium/templates/packages/language/tsconfig.src.json @@ -2,11 +2,9 @@ "extends": "../../tsconfig.json", "compilerOptions": { "rootDir": "src", - "outDir": "out", - "declarationDir": "out", + "outDir": "out" }, "include": [ "src/**/*.ts", ] } - \ No newline at end of file diff --git a/packages/generator-langium/test/yeoman-generator.test.ts b/packages/generator-langium/test/yeoman-generator.test.ts index 147408df9..f651ccaa2 100644 --- a/packages/generator-langium/test/yeoman-generator.test.ts +++ b/packages/generator-langium/test/yeoman-generator.test.ts @@ -47,14 +47,14 @@ describe('Check yeoman generator works', () => { const filesTest = (targetRoot: string) => [ targetRoot + '/packages/language/tsconfig.test.json', - targetRoot + '/packages/language/test/linking/linking.test.ts', - targetRoot + '/packages/language/test/parsing/parsing.test.ts', - targetRoot + '/packages/language/test/validating/validating.test.ts', + targetRoot + '/packages/language/test/linking.test.ts', + targetRoot + '/packages/language/test/parsing.test.ts', + targetRoot + '/packages/language/test/validating.test.ts', ]; const filesCli = (targetRoot: string) => [ targetRoot + '/packages/cli/bin/cli.js', - targetRoot + '/packages/cli/src/cli-util.ts', + targetRoot + '/packages/cli/src/util.ts', targetRoot + '/packages/cli/src/generator.ts', targetRoot + '/packages/cli/src/main.ts', targetRoot + '/packages/cli/package.json', @@ -232,16 +232,15 @@ describe('Check yeoman generator works', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const PACKAGE_JSON_EXPECTATION: Record = { - name: 'hello-world-base', + name: 'hello-world-workspace', description: 'Base workspace package', version: '0.0.1', type: 'module', private: true, files: ['out', 'src'], scripts: { - 'compile': 'tsc -b tsconfig.build.json', 'watch': 'tsc -b tsconfig.build.json --watch', - 'build': 'npm run compile && npm run build --workspaces', + 'build': 'tsc -b tsconfig.build.json && npm run build --workspaces', 'lint': 'eslint src --ext ts', 'langium:generate': 'npm run --workspace packages/language langium:generate', 'langium:watch': 'npm run --workspace packages/language langium:watch'