aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js/xtext/ValidationService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'language-web/src/main/js/xtext/ValidationService.ts')
-rw-r--r--language-web/src/main/js/xtext/ValidationService.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/language-web/src/main/js/xtext/ValidationService.ts b/language-web/src/main/js/xtext/ValidationService.ts
new file mode 100644
index 00000000..8e4934ac
--- /dev/null
+++ b/language-web/src/main/js/xtext/ValidationService.ts
@@ -0,0 +1,45 @@
1import type { Diagnostic } from '@codemirror/lint';
2
3import type { EditorStore } from '../editor/EditorStore';
4import type { UpdateService } from './UpdateService';
5import { getLogger } from '../utils/logger';
6import { isValidationResult } from './xtextServiceResults';
7
8const log = getLogger('xtext.ValidationService');
9
10export class ValidationService {
11 private readonly store: EditorStore;
12
13 private readonly updateService: UpdateService;
14
15 constructor(store: EditorStore, updateService: UpdateService) {
16 this.store = store;
17 this.updateService = updateService;
18 }
19
20 onPush(push: unknown): void {
21 if (!isValidationResult(push)) {
22 log.error('Invalid validation result', push);
23 return;
24 }
25 const allChanges = this.updateService.computeChangesSinceLastUpdate();
26 const diagnostics: Diagnostic[] = [];
27 push.issues.forEach(({
28 offset,
29 length,
30 severity,
31 description,
32 }) => {
33 if (severity === 'ignore') {
34 return;
35 }
36 diagnostics.push({
37 from: allChanges.mapPos(offset),
38 to: allChanges.mapPos(offset + length),
39 severity,
40 message: description,
41 });
42 });
43 this.store.updateDiagnostics(diagnostics);
44 }
45}