aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language-web/src/main/js/xtext/HighlightingService.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-12 17:48:47 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-12 17:48:47 +0100
commitfc7e9312d00e60171ed77c477ed91231d3dbfff9 (patch)
treecc185dd088b5fa6e9357aab3c9062a70626d1953 /subprojects/language-web/src/main/js/xtext/HighlightingService.ts
parentbuild: refactor java-application conventions (diff)
downloadrefinery-fc7e9312d00e60171ed77c477ed91231d3dbfff9.tar.gz
refinery-fc7e9312d00e60171ed77c477ed91231d3dbfff9.tar.zst
refinery-fc7e9312d00e60171ed77c477ed91231d3dbfff9.zip
build: move modules into subproject directory
Diffstat (limited to 'subprojects/language-web/src/main/js/xtext/HighlightingService.ts')
-rw-r--r--subprojects/language-web/src/main/js/xtext/HighlightingService.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/subprojects/language-web/src/main/js/xtext/HighlightingService.ts b/subprojects/language-web/src/main/js/xtext/HighlightingService.ts
new file mode 100644
index 00000000..dfbb4a19
--- /dev/null
+++ b/subprojects/language-web/src/main/js/xtext/HighlightingService.ts
@@ -0,0 +1,37 @@
1import type { EditorStore } from '../editor/EditorStore';
2import type { IHighlightRange } from '../editor/semanticHighlighting';
3import type { UpdateService } from './UpdateService';
4import { highlightingResult } from './xtextServiceResults';
5
6export class HighlightingService {
7 private readonly store: EditorStore;
8
9 private readonly updateService: UpdateService;
10
11 constructor(store: EditorStore, updateService: UpdateService) {
12 this.store = store;
13 this.updateService = updateService;
14 }
15
16 onPush(push: unknown): void {
17 const { regions } = highlightingResult.parse(push);
18 const allChanges = this.updateService.computeChangesSinceLastUpdate();
19 const ranges: IHighlightRange[] = [];
20 regions.forEach(({ offset, length, styleClasses }) => {
21 if (styleClasses.length === 0) {
22 return;
23 }
24 const from = allChanges.mapPos(offset);
25 const to = allChanges.mapPos(offset + length);
26 if (to <= from) {
27 return;
28 }
29 ranges.push({
30 from,
31 to,
32 classes: styleClasses,
33 });
34 });
35 this.store.updateSemanticHighlighting(ranges);
36 }
37}