diff options
Diffstat (limited to 'subprojects/frontend/src/xtext/ValidationService.ts')
-rw-r--r-- | subprojects/frontend/src/xtext/ValidationService.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/subprojects/frontend/src/xtext/ValidationService.ts b/subprojects/frontend/src/xtext/ValidationService.ts new file mode 100644 index 00000000..ff7d3700 --- /dev/null +++ b/subprojects/frontend/src/xtext/ValidationService.ts | |||
@@ -0,0 +1,39 @@ | |||
1 | import type { Diagnostic } from '@codemirror/lint'; | ||
2 | |||
3 | import type { EditorStore } from '../editor/EditorStore'; | ||
4 | import type { UpdateService } from './UpdateService'; | ||
5 | import { validationResult } from './xtextServiceResults'; | ||
6 | |||
7 | export class ValidationService { | ||
8 | private readonly store: EditorStore; | ||
9 | |||
10 | private readonly updateService: UpdateService; | ||
11 | |||
12 | constructor(store: EditorStore, updateService: UpdateService) { | ||
13 | this.store = store; | ||
14 | this.updateService = updateService; | ||
15 | } | ||
16 | |||
17 | onPush(push: unknown): void { | ||
18 | const { issues } = validationResult.parse(push); | ||
19 | const allChanges = this.updateService.computeChangesSinceLastUpdate(); | ||
20 | const diagnostics: Diagnostic[] = []; | ||
21 | issues.forEach(({ | ||
22 | offset, | ||
23 | length, | ||
24 | severity, | ||
25 | description, | ||
26 | }) => { | ||
27 | if (severity === 'ignore') { | ||
28 | return; | ||
29 | } | ||
30 | diagnostics.push({ | ||
31 | from: allChanges.mapPos(offset), | ||
32 | to: allChanges.mapPos(offset + length), | ||
33 | severity, | ||
34 | message: description, | ||
35 | }); | ||
36 | }); | ||
37 | this.store.updateDiagnostics(diagnostics); | ||
38 | } | ||
39 | } | ||