aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js/editor/semanticHighlighting.ts
diff options
context:
space:
mode:
Diffstat (limited to 'language-web/src/main/js/editor/semanticHighlighting.ts')
-rw-r--r--language-web/src/main/js/editor/semanticHighlighting.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/language-web/src/main/js/editor/semanticHighlighting.ts b/language-web/src/main/js/editor/semanticHighlighting.ts
new file mode 100644
index 00000000..2d6804f8
--- /dev/null
+++ b/language-web/src/main/js/editor/semanticHighlighting.ts
@@ -0,0 +1,34 @@
1import { StateEffect, StateField, TransactionSpec } from '@codemirror/state';
2import { EditorView, Decoration, DecorationSet } from '@codemirror/view';
3
4const setSemanticHighlightingEffect = StateEffect.define<DecorationSet>();
5
6export function setSemanticHighlighting(decorations: DecorationSet): TransactionSpec {
7 return {
8 effects: [
9 setSemanticHighlightingEffect.of(decorations),
10 ],
11 };
12}
13
14export const semanticHighlighting = StateField.define<DecorationSet>({
15 create() {
16 return Decoration.none;
17 },
18 update(currentDecorations, transaction) {
19 let newDecorations: DecorationSet | null = null;
20 transaction.effects.forEach((effect) => {
21 if (effect.is(setSemanticHighlightingEffect)) {
22 newDecorations = effect.value;
23 }
24 });
25 if (newDecorations === null) {
26 if (transaction.docChanged) {
27 return currentDecorations.map(transaction.changes);
28 }
29 return currentDecorations;
30 }
31 return newDecorations;
32 },
33 provide: (f) => EditorView.decorations.from(f),
34});