Skip to content

Commit 951121b

Browse files
authored
Merge pull request #17 from lstreckeisen/CMI-79-Create-SemanticTokenProvider-for-language-server
Cmi 79 create semantic token provider for language server
2 parents 591e6be + f3796f4 commit 951121b

File tree

7 files changed

+64
-52
lines changed

7 files changed

+64
-52
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
1-
# context-mapper-language-server
1+
![Context Mapper](https://raw.githubusercontent.com/wiki/ContextMapper/context-mapper-dsl/logo/cm-logo-github-small.png)
2+
# ContextMapper DSL Language Server
3+
[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.
4+
5+
## System Requirements
6+
The ContextMapper language server is implemented with Langium. To run the language server the following tools have to be installed locally:
7+
* [Node.js](https://nodejs.org/en/download) (v22)
8+
9+
## Build and/or Run the language server
10+
11+
### Requirements
12+
To build the language server the following tools have to be installed locally:
13+
* [corepack](https://github.com/nodejs/corepack): Corepack is needed to install yarn v4. For that corepack has to be enabled with `corepack enable`.
14+
(Corepack is included in v22 of Node.js)
15+
16+
### Build
17+
To build the language server, the Langium resources have to be generated first:
18+
```bash
19+
yarn langium:generate
20+
```
21+
Then you can execute:
22+
```bash
23+
yarn build
24+
```
25+
26+
### Bundle
27+
For distribution, the language server is bundled into a single file using `ncc`. To bundle the language server execute:
28+
```bash
29+
yarn bundle:language-server
30+
```
31+
32+
### Running the language server
33+
To execute the bundled language server execute:
34+
```bash
35+
node cml-ls/index.js --stdio
36+
```

esbuild.mjs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ import * as esbuild from 'esbuild';
44
const watch = process.argv.includes('--watch');
55
const minify = process.argv.includes('--minify');
66

7-
const success = watch ? 'Watch build succeeded' : 'Build succeeded';
8-
9-
function getTime() {
10-
const date = new Date();
11-
return `[${`${padZeroes(date.getHours())}:${padZeroes(date.getMinutes())}:${padZeroes(date.getSeconds())}`}] `;
12-
}
13-
14-
function padZeroes(i) {
15-
return i.toString().padStart(2, '0');
16-
}
17-
187
const ctx = await esbuild.context({
198
// Entry points for the vscode extension and the language server
209
entryPoints: ['src/language/main.ts'],
@@ -34,5 +23,5 @@ if (watch) {
3423
await ctx.watch();
3524
} else {
3625
await ctx.rebuild();
37-
ctx.dispose();
26+
await ctx.dispose();
3827
}
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import { AstNode, type ValidationChecks, ValidationRegistry } from 'langium'
1+
import { ValidationAcceptor, type ValidationChecks, ValidationRegistry } from 'langium'
22
import { ContextMappingModelValidator } from './validation/ContextMappingModelValidator.js'
33
import { ValueValidator } from './validation/ValueValidator.js'
4-
import { AbstractContextMapperValidator } from './validation/AbstractContextMapperValidator.js'
5-
import type { ContextMapperDslAstType } from './generated/ast.js'
6-
7-
const validators: AbstractContextMapperValidator<AstNode>[] = [
8-
new ContextMappingModelValidator(),
9-
new ValueValidator()
10-
]
4+
import type { ContextMapperDslAstType, ContextMappingModel, Value } from './generated/ast.js'
115

126
/**
137
* Register custom validation checks.
148
*/
159
export function registerValidationChecks (registry: ValidationRegistry, validator: ContextMapperDslValidator) {
16-
const validatorChecks: ValidationChecks<ContextMapperDslAstType>[] = []
17-
for (const validator of validators) {
18-
validatorChecks.push(validator.getChecks())
10+
const checks: ValidationChecks<ContextMapperDslAstType> = {
11+
ContextMappingModel: validator.checkContextMappingModel,
12+
Value: validator.checkValue
1913
}
20-
const checks: ValidationChecks<ContextMapperDslAstType> = Object.assign({}, ...validatorChecks)
2114
registry.register(checks, validator)
2215
}
2316

2417
export class ContextMapperDslValidator {
18+
private contextMappingModelValidator = new ContextMappingModelValidator()
19+
private valueValidator = new ValueValidator()
20+
21+
checkContextMappingModel (model: ContextMappingModel, acceptor: ValidationAcceptor) {
22+
this.contextMappingModelValidator.validate(model, acceptor)
23+
}
2524

25+
checkValue (value: Value, acceptor: ValidationAcceptor) {
26+
this.valueValidator.validate(value, acceptor)
27+
}
2628
}

src/language/validation/AbstractContextMapperValidator.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { AstNode, ValidationAcceptor } from 'langium'
2+
3+
export interface ContextMapperValidator<T extends AstNode> {
4+
validate (node: T, acceptor: ValidationAcceptor): void
5+
}

src/language/validation/ContextMappingModelValidator.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import type { ValidationAcceptor, ValidationChecks } from 'langium'
2-
import type { ContextMapperDslAstType, ContextMappingModel } from '../generated/ast.js'
3-
import { AbstractContextMapperValidator } from './AbstractContextMapperValidator.js'
4-
5-
export class ContextMappingModelValidator implements AbstractContextMapperValidator<ContextMappingModel> {
6-
getChecks (): ValidationChecks<ContextMapperDslAstType> {
7-
return {
8-
ContextMappingModel: this.validate
9-
}
10-
}
1+
import type { ValidationAcceptor } from 'langium'
2+
import type { ContextMappingModel } from '../generated/ast.js'
3+
import { ContextMapperValidator } from './ContextMapperValidator.js'
114

5+
export class ContextMappingModelValidator implements ContextMapperValidator<ContextMappingModel> {
126
validate (model: ContextMappingModel, acceptor: ValidationAcceptor): void {
137
checkForZeroOrOneContextMap(model, acceptor)
148
}

src/language/validation/ValueValidator.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import { AbstractContextMapperValidator } from './AbstractContextMapperValidator.js'
2-
import { ContextMapperDslAstType, Value } from '../generated/ast.js'
3-
import { ValidationAcceptor, ValidationChecks } from 'langium'
4-
5-
export class ValueValidator implements AbstractContextMapperValidator<Value> {
6-
getChecks (): ValidationChecks<ContextMapperDslAstType> {
7-
return {
8-
Value: this.validate
9-
}
10-
}
1+
import { ContextMapperValidator } from './ContextMapperValidator.js'
2+
import { Value } from '../generated/ast.js'
3+
import { ValidationAcceptor } from 'langium'
114

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

0 commit comments

Comments
 (0)