diff options
Diffstat (limited to 'subprojects/frontend/src/xtext')
4 files changed, 31 insertions, 9 deletions
diff --git a/subprojects/frontend/src/xtext/ModelGenerationService.ts b/subprojects/frontend/src/xtext/ModelGenerationService.ts index 1e9f837a..29a70623 100644 --- a/subprojects/frontend/src/xtext/ModelGenerationService.ts +++ b/subprojects/frontend/src/xtext/ModelGenerationService.ts | |||
@@ -4,12 +4,18 @@ | |||
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | 6 | ||
7 | import type { Transaction } from '@codemirror/state'; | ||
8 | |||
7 | import type EditorStore from '../editor/EditorStore'; | 9 | import type EditorStore from '../editor/EditorStore'; |
8 | 10 | ||
9 | import type UpdateService from './UpdateService'; | 11 | import type UpdateService from './UpdateService'; |
10 | import { ModelGenerationResult } from './xtextServiceResults'; | 12 | import { ModelGenerationResult } from './xtextServiceResults'; |
11 | 13 | ||
14 | const INITIAL_RANDOM_SEED = 1; | ||
15 | |||
12 | export default class ModelGenerationService { | 16 | export default class ModelGenerationService { |
17 | private nextRandomSeed = INITIAL_RANDOM_SEED; | ||
18 | |||
13 | constructor( | 19 | constructor( |
14 | private readonly store: EditorStore, | 20 | private readonly store: EditorStore, |
15 | private readonly updateService: UpdateService, | 21 | private readonly updateService: UpdateService, |
@@ -26,14 +32,24 @@ export default class ModelGenerationService { | |||
26 | } | 32 | } |
27 | } | 33 | } |
28 | 34 | ||
35 | onTransaction(transaction: Transaction): void { | ||
36 | if (transaction.docChanged) { | ||
37 | this.resetRandomSeed(); | ||
38 | } | ||
39 | } | ||
40 | |||
29 | onDisconnect(): void { | 41 | onDisconnect(): void { |
30 | this.store.modelGenerationCancelled(); | 42 | this.store.modelGenerationCancelled(); |
43 | this.resetRandomSeed(); | ||
31 | } | 44 | } |
32 | 45 | ||
33 | async start(): Promise<void> { | 46 | async start(randomSeed?: number): Promise<void> { |
34 | const result = await this.updateService.startModelGeneration(); | 47 | const randomSeedOrNext = randomSeed ?? this.nextRandomSeed; |
48 | this.nextRandomSeed = randomSeedOrNext + 1; | ||
49 | const result = | ||
50 | await this.updateService.startModelGeneration(randomSeedOrNext); | ||
35 | if (!result.cancelled) { | 51 | if (!result.cancelled) { |
36 | this.store.addGeneratedModel(result.data.uuid); | 52 | this.store.addGeneratedModel(result.data.uuid, randomSeedOrNext); |
37 | } | 53 | } |
38 | } | 54 | } |
39 | 55 | ||
@@ -43,4 +59,8 @@ export default class ModelGenerationService { | |||
43 | this.store.modelGenerationCancelled(); | 59 | this.store.modelGenerationCancelled(); |
44 | } | 60 | } |
45 | } | 61 | } |
62 | |||
63 | private resetRandomSeed() { | ||
64 | this.nextRandomSeed = INITIAL_RANDOM_SEED; | ||
65 | } | ||
46 | } | 66 | } |
diff --git a/subprojects/frontend/src/xtext/UpdateService.ts b/subprojects/frontend/src/xtext/UpdateService.ts index d1246d5e..70e79764 100644 --- a/subprojects/frontend/src/xtext/UpdateService.ts +++ b/subprojects/frontend/src/xtext/UpdateService.ts | |||
@@ -343,9 +343,9 @@ export default class UpdateService { | |||
343 | return { cancelled: false, data: parsedOccurrencesResult }; | 343 | return { cancelled: false, data: parsedOccurrencesResult }; |
344 | } | 344 | } |
345 | 345 | ||
346 | async startModelGeneration(): Promise< | 346 | async startModelGeneration( |
347 | CancellableResult<ModelGenerationStartedResult> | 347 | randomSeed: number, |
348 | > { | 348 | ): Promise<CancellableResult<ModelGenerationStartedResult>> { |
349 | try { | 349 | try { |
350 | await this.updateOrThrow(); | 350 | await this.updateOrThrow(); |
351 | } catch (error) { | 351 | } catch (error) { |
@@ -360,6 +360,7 @@ export default class UpdateService { | |||
360 | serviceType: 'modelGeneration', | 360 | serviceType: 'modelGeneration', |
361 | requiredStateId: this.xtextStateId, | 361 | requiredStateId: this.xtextStateId, |
362 | start: true, | 362 | start: true, |
363 | randomSeed, | ||
363 | }); | 364 | }); |
364 | if (isConflictResult(data)) { | 365 | if (isConflictResult(data)) { |
365 | return { cancelled: true }; | 366 | return { cancelled: true }; |
diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts index 4df4f57a..7486d737 100644 --- a/subprojects/frontend/src/xtext/XtextClient.ts +++ b/subprojects/frontend/src/xtext/XtextClient.ts | |||
@@ -99,6 +99,7 @@ export default class XtextClient { | |||
99 | this.contentAssistService.onTransaction(transaction); | 99 | this.contentAssistService.onTransaction(transaction); |
100 | this.updateService.onTransaction(transaction); | 100 | this.updateService.onTransaction(transaction); |
101 | this.occurrencesService.onTransaction(transaction); | 101 | this.occurrencesService.onTransaction(transaction); |
102 | this.modelGenerationService.onTransaction(transaction); | ||
102 | } | 103 | } |
103 | 104 | ||
104 | private onPush( | 105 | private onPush( |
@@ -150,8 +151,8 @@ export default class XtextClient { | |||
150 | return this.contentAssistService.contentAssist(context); | 151 | return this.contentAssistService.contentAssist(context); |
151 | } | 152 | } |
152 | 153 | ||
153 | startModelGeneration(): Promise<void> { | 154 | startModelGeneration(randomSeed?: number): Promise<void> { |
154 | return this.modelGenerationService.start(); | 155 | return this.modelGenerationService.start(randomSeed); |
155 | } | 156 | } |
156 | 157 | ||
157 | cancelModelGeneration(): Promise<void> { | 158 | cancelModelGeneration(): Promise<void> { |
diff --git a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts index bb84223c..280ac875 100644 --- a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts +++ b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts | |||
@@ -204,7 +204,7 @@ export default class XtextWebSocketClient { | |||
204 | 204 | ||
205 | get state() { | 205 | get state() { |
206 | this.stateAtom.reportObserved(); | 206 | this.stateAtom.reportObserved(); |
207 | return this.interpreter.state; | 207 | return this.interpreter.getSnapshot(); |
208 | } | 208 | } |
209 | 209 | ||
210 | get opening(): boolean { | 210 | get opening(): boolean { |