Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# context-mapper-language-server
![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
```
13 changes: 1 addition & 12 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -34,5 +23,5 @@ if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
ctx.dispose();
await ctx.dispose();
}
26 changes: 14 additions & 12 deletions src/language/ContextMapperDslValidator.ts
Original file line number Diff line number Diff line change
@@ -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<AstNode>[] = [
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<ContextMapperDslAstType>[] = []
for (const validator of validators) {
validatorChecks.push(validator.getChecks())
const checks: ValidationChecks<ContextMapperDslAstType> = {
ContextMappingModel: validator.checkContextMappingModel,
Value: validator.checkValue
}
const checks: ValidationChecks<ContextMapperDslAstType> = 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)
}
}
7 changes: 0 additions & 7 deletions src/language/validation/AbstractContextMapperValidator.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/language/validation/ContextMapperValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AstNode, ValidationAcceptor } from 'langium'

export interface ContextMapperValidator<T extends AstNode> {
validate (node: T, acceptor: ValidationAcceptor): void
}
14 changes: 4 additions & 10 deletions src/language/validation/ContextMappingModelValidator.ts
Original file line number Diff line number Diff line change
@@ -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<ContextMappingModel> {
getChecks (): ValidationChecks<ContextMapperDslAstType> {
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<ContextMappingModel> {
validate (model: ContextMappingModel, acceptor: ValidationAcceptor): void {
checkForZeroOrOneContextMap(model, acceptor)
}
Expand Down
14 changes: 4 additions & 10 deletions src/language/validation/ValueValidator.ts
Original file line number Diff line number Diff line change
@@ -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<Value> {
getChecks (): ValidationChecks<ContextMapperDslAstType> {
return {
Value: this.validate
}
}
import { ContextMapperValidator } from './ContextMapperValidator.js'
import { Value } from '../generated/ast.js'
import { ValidationAcceptor } from 'langium'

export class ValueValidator implements ContextMapperValidator<Value> {
validate (node: Value, acceptor: ValidationAcceptor): void {
if (node.coreValue.length > 1) {
acceptor('error', 'There must be zero or one isCore attribute', {
Expand Down