From 1e4704c6635f5521adff5ac199d168b60f40a974 Mon Sep 17 00:00:00 2001 From: Lukas Streckeisen Date: Thu, 17 Apr 2025 13:54:18 +0200 Subject: [PATCH 1/3] cleanup --- esbuild.mjs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/esbuild.mjs b/esbuild.mjs index a5d61e9..6a70ed7 100644 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -4,17 +4,6 @@ import * as esbuild from 'esbuild'; const watch = process.argv.includes('--watch'); const minify = process.argv.includes('--minify'); -const success = watch ? 'Watch build succeeded' : 'Build succeeded'; - -function getTime() { - const date = new Date(); - return `[${`${padZeroes(date.getHours())}:${padZeroes(date.getMinutes())}:${padZeroes(date.getSeconds())}`}] `; -} - -function padZeroes(i) { - return i.toString().padStart(2, '0'); -} - const ctx = await esbuild.context({ // Entry points for the vscode extension and the language server entryPoints: ['src/language/main.ts'], @@ -34,5 +23,5 @@ if (watch) { await ctx.watch(); } else { await ctx.rebuild(); - ctx.dispose(); + await ctx.dispose(); } From 114567e80b4b34c7636221d2c7ac37d16c545017 Mon Sep 17 00:00:00 2001 From: Lukas Streckeisen Date: Thu, 17 Apr 2025 14:01:16 +0200 Subject: [PATCH 2/3] refactor validators --- src/language/ContextMapperDslValidator.ts | 26 ++++++++++--------- .../AbstractContextMapperValidator.ts | 7 ----- .../validation/ContextMapperValidator.ts | 5 ++++ .../ContextMappingModelValidator.ts | 14 +++------- src/language/validation/ValueValidator.ts | 14 +++------- 5 files changed, 27 insertions(+), 39 deletions(-) delete mode 100644 src/language/validation/AbstractContextMapperValidator.ts create mode 100644 src/language/validation/ContextMapperValidator.ts diff --git a/src/language/ContextMapperDslValidator.ts b/src/language/ContextMapperDslValidator.ts index e2c6f83..5bc6efe 100644 --- a/src/language/ContextMapperDslValidator.ts +++ b/src/language/ContextMapperDslValidator.ts @@ -1,26 +1,28 @@ -import { AstNode, type ValidationChecks, ValidationRegistry } from 'langium' +import { ValidationAcceptor, type ValidationChecks, ValidationRegistry } from 'langium' import { ContextMappingModelValidator } from './validation/ContextMappingModelValidator.js' import { ValueValidator } from './validation/ValueValidator.js' -import { AbstractContextMapperValidator } from './validation/AbstractContextMapperValidator.js' -import type { ContextMapperDslAstType } from './generated/ast.js' - -const validators: AbstractContextMapperValidator[] = [ - new ContextMappingModelValidator(), - new ValueValidator() -] +import type { ContextMapperDslAstType, ContextMappingModel, Value } from './generated/ast.js' /** * Register custom validation checks. */ export function registerValidationChecks (registry: ValidationRegistry, validator: ContextMapperDslValidator) { - const validatorChecks: ValidationChecks[] = [] - for (const validator of validators) { - validatorChecks.push(validator.getChecks()) + const checks: ValidationChecks = { + ContextMappingModel: validator.checkContextMappingModel, + Value: validator.checkValue } - const checks: ValidationChecks = Object.assign({}, ...validatorChecks) registry.register(checks, validator) } export class ContextMapperDslValidator { + private contextMappingModelValidator = new ContextMappingModelValidator() + private valueValidator = new ValueValidator() + + checkContextMappingModel (model: ContextMappingModel, acceptor: ValidationAcceptor) { + this.contextMappingModelValidator.validate(model, acceptor) + } + checkValue (value: Value, acceptor: ValidationAcceptor) { + this.valueValidator.validate(value, acceptor) + } } diff --git a/src/language/validation/AbstractContextMapperValidator.ts b/src/language/validation/AbstractContextMapperValidator.ts deleted file mode 100644 index ccc5b5c..0000000 --- a/src/language/validation/AbstractContextMapperValidator.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { AstNode, ValidationAcceptor, type ValidationChecks } from 'langium' -import type { ContextMapperDslAstType } from '../generated/ast.js' - -export interface AbstractContextMapperValidator { - getChecks (): ValidationChecks - validate (node: T, acceptor: ValidationAcceptor): void -} diff --git a/src/language/validation/ContextMapperValidator.ts b/src/language/validation/ContextMapperValidator.ts new file mode 100644 index 0000000..0c2686a --- /dev/null +++ b/src/language/validation/ContextMapperValidator.ts @@ -0,0 +1,5 @@ +import { AstNode, ValidationAcceptor } from 'langium' + +export interface ContextMapperValidator { + validate (node: T, acceptor: ValidationAcceptor): void +} diff --git a/src/language/validation/ContextMappingModelValidator.ts b/src/language/validation/ContextMappingModelValidator.ts index 6416659..07bb62a 100644 --- a/src/language/validation/ContextMappingModelValidator.ts +++ b/src/language/validation/ContextMappingModelValidator.ts @@ -1,14 +1,8 @@ -import type { ValidationAcceptor, ValidationChecks } from 'langium' -import type { ContextMapperDslAstType, ContextMappingModel } from '../generated/ast.js' -import { AbstractContextMapperValidator } from './AbstractContextMapperValidator.js' - -export class ContextMappingModelValidator implements AbstractContextMapperValidator { - getChecks (): ValidationChecks { - return { - ContextMappingModel: this.validate - } - } +import type { ValidationAcceptor } from 'langium' +import type { ContextMappingModel } from '../generated/ast.js' +import { ContextMapperValidator } from './ContextMapperValidator.js' +export class ContextMappingModelValidator implements ContextMapperValidator { validate (model: ContextMappingModel, acceptor: ValidationAcceptor): void { checkForZeroOrOneContextMap(model, acceptor) } diff --git a/src/language/validation/ValueValidator.ts b/src/language/validation/ValueValidator.ts index 7bc36bc..d6de7f1 100644 --- a/src/language/validation/ValueValidator.ts +++ b/src/language/validation/ValueValidator.ts @@ -1,14 +1,8 @@ -import { AbstractContextMapperValidator } from './AbstractContextMapperValidator.js' -import { ContextMapperDslAstType, Value } from '../generated/ast.js' -import { ValidationAcceptor, ValidationChecks } from 'langium' - -export class ValueValidator implements AbstractContextMapperValidator { - getChecks (): ValidationChecks { - return { - Value: this.validate - } - } +import { ContextMapperValidator } from './ContextMapperValidator.js' +import { Value } from '../generated/ast.js' +import { ValidationAcceptor } from 'langium' +export class ValueValidator implements ContextMapperValidator { validate (node: Value, acceptor: ValidationAcceptor): void { if (node.coreValue.length > 1) { acceptor('error', 'There must be zero or one isCore attribute', { From f3796f4487ecbe6acec385b707a7ac6afaf0822f Mon Sep 17 00:00:00 2001 From: Lukas Streckeisen Date: Thu, 17 Apr 2025 14:14:59 +0200 Subject: [PATCH 3/3] add readme --- README.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06a1a14..7ca97db 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ -# context-mapper-language-server \ No newline at end of file +![Context Mapper](https://raw.githubusercontent.com/wiki/ContextMapper/context-mapper-dsl/logo/cm-logo-github-small.png) +# ContextMapper DSL Language Server +[ContextMapper](https://contextmapper.org/) is an open source tool providing a Domain-specific Language based on Domain-Driven Design (DDD) patterns for context mapping and service decomposition. + +## System Requirements +The ContextMapper language server is implemented with Langium. To run the language server the following tools have to be installed locally: +* [Node.js](https://nodejs.org/en/download) (v22) + +## Build and/or Run the language server + +### Requirements +To build the language server the following tools have to be installed locally: +* [corepack](https://github.com/nodejs/corepack): Corepack is needed to install yarn v4. For that corepack has to be enabled with `corepack enable`. + (Corepack is included in v22 of Node.js) + +### Build +To build the language server, the Langium resources have to be generated first: +```bash +yarn langium:generate +``` +Then you can execute: +```bash +yarn build +``` + +### Bundle +For distribution, the language server is bundled into a single file using `ncc`. To bundle the language server execute: +```bash +yarn bundle:language-server +``` + +### Running the language server +To execute the bundled language server execute: +```bash +node cml-ls/index.js --stdio +```