aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js/xtext/HighlightingService.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-11-16 03:00:45 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-11-16 03:11:00 +0100
commit5810a7eb3b19ef9868db170c9214686bfc613eee (patch)
treeda122997d4ad58f4104d0f84b06a00fe14e7ad02 /language-web/src/main/js/xtext/HighlightingService.ts
parentfeat(lang): basic formatting (diff)
downloadrefinery-5810a7eb3b19ef9868db170c9214686bfc613eee.tar.gz
refinery-5810a7eb3b19ef9868db170c9214686bfc613eee.tar.zst
refinery-5810a7eb3b19ef9868db170c9214686bfc613eee.zip
chore(web): json validation with zod
Use the zod library instead of manually written type assertions for validating json messages from the server. This makes it easier to add and handle new messages.
Diffstat (limited to 'language-web/src/main/js/xtext/HighlightingService.ts')
-rw-r--r--language-web/src/main/js/xtext/HighlightingService.ts12
1 files changed, 3 insertions, 9 deletions
diff --git a/language-web/src/main/js/xtext/HighlightingService.ts b/language-web/src/main/js/xtext/HighlightingService.ts
index fc3e9e53..dfbb4a19 100644
--- a/language-web/src/main/js/xtext/HighlightingService.ts
+++ b/language-web/src/main/js/xtext/HighlightingService.ts
@@ -1,10 +1,7 @@
1import type { EditorStore } from '../editor/EditorStore'; 1import type { EditorStore } from '../editor/EditorStore';
2import type { IHighlightRange } from '../editor/semanticHighlighting'; 2import type { IHighlightRange } from '../editor/semanticHighlighting';
3import type { UpdateService } from './UpdateService'; 3import type { UpdateService } from './UpdateService';
4import { getLogger } from '../utils/logger'; 4import { highlightingResult } from './xtextServiceResults';
5import { isHighlightingResult } from './xtextServiceResults';
6
7const log = getLogger('xtext.ValidationService');
8 5
9export class HighlightingService { 6export class HighlightingService {
10 private readonly store: EditorStore; 7 private readonly store: EditorStore;
@@ -17,13 +14,10 @@ export class HighlightingService {
17 } 14 }
18 15
19 onPush(push: unknown): void { 16 onPush(push: unknown): void {
20 if (!isHighlightingResult(push)) { 17 const { regions } = highlightingResult.parse(push);
21 log.error('Invalid highlighting result', push);
22 return;
23 }
24 const allChanges = this.updateService.computeChangesSinceLastUpdate(); 18 const allChanges = this.updateService.computeChangesSinceLastUpdate();
25 const ranges: IHighlightRange[] = []; 19 const ranges: IHighlightRange[] = [];
26 push.regions.forEach(({ offset, length, styleClasses }) => { 20 regions.forEach(({ offset, length, styleClasses }) => {
27 if (styleClasses.length === 0) { 21 if (styleClasses.length === 0) {
28 return; 22 return;
29 } 23 }