blob: dfbb4a19abe502e87bba98f09f182cc46554638f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import type { EditorStore } from '../editor/EditorStore';
import type { IHighlightRange } from '../editor/semanticHighlighting';
import type { UpdateService } from './UpdateService';
import { highlightingResult } from './xtextServiceResults';
export class HighlightingService {
private readonly store: EditorStore;
private readonly updateService: UpdateService;
constructor(store: EditorStore, updateService: UpdateService) {
this.store = store;
this.updateService = updateService;
}
onPush(push: unknown): void {
const { regions } = highlightingResult.parse(push);
const allChanges = this.updateService.computeChangesSinceLastUpdate();
const ranges: IHighlightRange[] = [];
regions.forEach(({ offset, length, styleClasses }) => {
if (styleClasses.length === 0) {
return;
}
const from = allChanges.mapPos(offset);
const to = allChanges.mapPos(offset + length);
if (to <= from) {
return;
}
ranges.push({
from,
to,
classes: styleClasses,
});
});
this.store.updateSemanticHighlighting(ranges);
}
}
|