diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2023-09-14 19:29:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-14 19:29:36 +0200 |
commit | 98ed3b6db5f4e51961a161050cc31c66015116e8 (patch) | |
tree | 8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/frontend/src/xtext/XtextClient.ts | |
parent | Merge pull request #38 from nagilooh/design-space-exploration (diff) | |
parent | Merge remote-tracking branch 'upstream/main' into partial-interpretation (diff) | |
download | refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.gz refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.zst refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.zip |
Merge pull request #39 from kris7t/partial-interpretation
Implement partial interpretation based model generation
Diffstat (limited to 'subprojects/frontend/src/xtext/XtextClient.ts')
-rw-r--r-- | subprojects/frontend/src/xtext/XtextClient.ts | 44 |
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'; |
11 | import type { Transaction } from '@codemirror/state'; | 11 | import type { Transaction } from '@codemirror/state'; |
12 | import { type IReactionDisposer, reaction } from 'mobx'; | ||
12 | 13 | ||
13 | import type PWAStore from '../PWAStore'; | 14 | import type PWAStore from '../PWAStore'; |
14 | import type EditorStore from '../editor/EditorStore'; | 15 | import type EditorStore from '../editor/EditorStore'; |
@@ -16,7 +17,9 @@ import getLogger from '../utils/getLogger'; | |||
16 | 17 | ||
17 | import ContentAssistService from './ContentAssistService'; | 18 | import ContentAssistService from './ContentAssistService'; |
18 | import HighlightingService from './HighlightingService'; | 19 | import HighlightingService from './HighlightingService'; |
20 | import ModelGenerationService from './ModelGenerationService'; | ||
19 | import OccurrencesService from './OccurrencesService'; | 21 | import OccurrencesService from './OccurrencesService'; |
22 | import SemanticsService from './SemanticsService'; | ||
20 | import UpdateService from './UpdateService'; | 23 | import UpdateService from './UpdateService'; |
21 | import ValidationService from './ValidationService'; | 24 | import ValidationService from './ValidationService'; |
22 | import XtextWebSocketClient from './XtextWebSocketClient'; | 25 | import 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 | } |