aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext/XtextClient.ts
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/xtext/XtextClient.ts')
-rw-r--r--subprojects/frontend/src/xtext/XtextClient.ts44
1 files changed, 42 insertions, 2 deletions
diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts
index e8181af0..7486d737 100644
--- a/subprojects/frontend/src/xtext/XtextClient.ts
+++ b/subprojects/frontend/src/xtext/XtextClient.ts
@@ -9,6 +9,7 @@ import type {
9 CompletionResult, 9 CompletionResult,
10} from '@codemirror/autocomplete'; 10} from '@codemirror/autocomplete';
11import type { Transaction } from '@codemirror/state'; 11import type { Transaction } from '@codemirror/state';
12import { type IReactionDisposer, reaction } from 'mobx';
12 13
13import type PWAStore from '../PWAStore'; 14import type PWAStore from '../PWAStore';
14import type EditorStore from '../editor/EditorStore'; 15import type EditorStore from '../editor/EditorStore';
@@ -16,7 +17,9 @@ import getLogger from '../utils/getLogger';
16 17
17import ContentAssistService from './ContentAssistService'; 18import ContentAssistService from './ContentAssistService';
18import HighlightingService from './HighlightingService'; 19import HighlightingService from './HighlightingService';
20import ModelGenerationService from './ModelGenerationService';
19import OccurrencesService from './OccurrencesService'; 21import OccurrencesService from './OccurrencesService';
22import SemanticsService from './SemanticsService';
20import UpdateService from './UpdateService'; 23import UpdateService from './UpdateService';
21import ValidationService from './ValidationService'; 24import ValidationService from './ValidationService';
22import XtextWebSocketClient from './XtextWebSocketClient'; 25import XtextWebSocketClient from './XtextWebSocketClient';
@@ -37,7 +40,16 @@ export default class XtextClient {
37 40
38 private readonly occurrencesService: OccurrencesService; 41 private readonly occurrencesService: OccurrencesService;
39 42
40 constructor(store: EditorStore, private readonly pwaStore: PWAStore) { 43 private readonly semanticsService: SemanticsService;
44
45 private readonly modelGenerationService: ModelGenerationService;
46
47 private readonly keepAliveDisposer: IReactionDisposer;
48
49 constructor(
50 private readonly store: EditorStore,
51 private readonly pwaStore: PWAStore,
52 ) {
41 this.webSocketClient = new XtextWebSocketClient( 53 this.webSocketClient = new XtextWebSocketClient(
42 () => this.onReconnect(), 54 () => this.onReconnect(),
43 () => this.onDisconnect(), 55 () => this.onDisconnect(),
@@ -51,6 +63,16 @@ export default class XtextClient {
51 ); 63 );
52 this.validationService = new ValidationService(store, this.updateService); 64 this.validationService = new ValidationService(store, this.updateService);
53 this.occurrencesService = new OccurrencesService(store, this.updateService); 65 this.occurrencesService = new OccurrencesService(store, this.updateService);
66 this.semanticsService = new SemanticsService(store, this.validationService);
67 this.modelGenerationService = new ModelGenerationService(
68 store,
69 this.updateService,
70 );
71 this.keepAliveDisposer = reaction(
72 () => store.generating,
73 (generating) => this.webSocketClient.setKeepAlive(generating),
74 { fireImmediately: true },
75 );
54 } 76 }
55 77
56 start(): void { 78 start(): void {
@@ -64,9 +86,11 @@ export default class XtextClient {
64 } 86 }
65 87
66 private onDisconnect(): void { 88 private onDisconnect(): void {
89 this.store.analysisCompleted(true);
67 this.highlightingService.onDisconnect(); 90 this.highlightingService.onDisconnect();
68 this.validationService.onDisconnect(); 91 this.validationService.onDisconnect();
69 this.occurrencesService.onDisconnect(); 92 this.occurrencesService.onDisconnect();
93 this.modelGenerationService.onDisconnect();
70 } 94 }
71 95
72 onTransaction(transaction: Transaction): void { 96 onTransaction(transaction: Transaction): void {
@@ -75,6 +99,7 @@ export default class XtextClient {
75 this.contentAssistService.onTransaction(transaction); 99 this.contentAssistService.onTransaction(transaction);
76 this.updateService.onTransaction(transaction); 100 this.updateService.onTransaction(transaction);
77 this.occurrencesService.onTransaction(transaction); 101 this.occurrencesService.onTransaction(transaction);
102 this.modelGenerationService.onTransaction(transaction);
78 } 103 }
79 104
80 private onPush( 105 private onPush(
@@ -93,7 +118,7 @@ export default class XtextClient {
93 ); 118 );
94 return; 119 return;
95 } 120 }
96 if (stateId !== xtextStateId) { 121 if (stateId !== xtextStateId && service !== 'modelGeneration') {
97 log.error( 122 log.error(
98 'Unexpected xtext state id: expected:', 123 'Unexpected xtext state id: expected:',
99 xtextStateId, 124 xtextStateId,
@@ -111,6 +136,12 @@ export default class XtextClient {
111 case 'validate': 136 case 'validate':
112 this.validationService.onPush(push); 137 this.validationService.onPush(push);
113 return; 138 return;
139 case 'semantics':
140 this.semanticsService.onPush(push);
141 return;
142 case 'modelGeneration':
143 this.modelGenerationService.onPush(push);
144 return;
114 default: 145 default:
115 throw new Error('Unknown service'); 146 throw new Error('Unknown service');
116 } 147 }
@@ -120,6 +151,14 @@ export default class XtextClient {
120 return this.contentAssistService.contentAssist(context); 151 return this.contentAssistService.contentAssist(context);
121 } 152 }
122 153
154 startModelGeneration(randomSeed?: number): Promise<void> {
155 return this.modelGenerationService.start(randomSeed);
156 }
157
158 cancelModelGeneration(): Promise<void> {
159 return this.modelGenerationService.cancel();
160 }
161
123 formatText(): void { 162 formatText(): void {
124 this.updateService.formatText().catch((e) => { 163 this.updateService.formatText().catch((e) => {
125 log.error('Error while formatting text', e); 164 log.error('Error while formatting text', e);
@@ -127,6 +166,7 @@ export default class XtextClient {
127 } 166 }
128 167
129 dispose(): void { 168 dispose(): void {
169 this.keepAliveDisposer();
130 this.webSocketClient.disconnect(); 170 this.webSocketClient.disconnect();
131 } 171 }
132} 172}