diff options
Diffstat (limited to 'language-web/src/main/js/xtext/ValidationService.ts')
-rw-r--r-- | language-web/src/main/js/xtext/ValidationService.ts | 40 |
1 files changed, 40 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..838aa31e --- /dev/null +++ b/language-web/src/main/js/xtext/ValidationService.ts | |||
@@ -0,0 +1,40 @@ | |||
1 | import type { Diagnostic } from '@codemirror/lint'; | ||
2 | |||
3 | import type { EditorStore } from '../editor/EditorStore'; | ||
4 | import { getLogger } from '../logging'; | ||
5 | import type { UpdateService } from './UpdateService'; | ||
6 | import { isValidationResult } from './xtextServiceResults'; | ||
7 | |||
8 | const log = getLogger('xtext.ValidationService'); | ||
9 | |||
10 | export class ValidationService { | ||
11 | private store: EditorStore; | ||
12 | |||
13 | private 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((issue) => { | ||
28 | if (issue.severity === 'ignore') { | ||
29 | return; | ||
30 | } | ||
31 | diagnostics.push({ | ||
32 | from: allChanges.mapPos(issue.offset), | ||
33 | to: allChanges.mapPos(issue.offset + issue.length), | ||
34 | severity: issue.severity, | ||
35 | message: issue.description, | ||
36 | }); | ||
37 | }); | ||
38 | this.store.updateDiagnostics(diagnostics); | ||
39 | } | ||
40 | } | ||