diff options
Diffstat (limited to 'subprojects/frontend/src/xtext/XtextClient.ts')
-rw-r--r-- | subprojects/frontend/src/xtext/XtextClient.ts | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts index 0898e725..7297c674 100644 --- a/subprojects/frontend/src/xtext/XtextClient.ts +++ b/subprojects/frontend/src/xtext/XtextClient.ts | |||
@@ -4,19 +4,20 @@ import type { | |||
4 | } from '@codemirror/autocomplete'; | 4 | } from '@codemirror/autocomplete'; |
5 | import type { Transaction } from '@codemirror/state'; | 5 | import type { Transaction } from '@codemirror/state'; |
6 | 6 | ||
7 | import type { EditorStore } from '../editor/EditorStore'; | 7 | import type EditorStore from '../editor/EditorStore'; |
8 | import { ContentAssistService } from './ContentAssistService'; | 8 | import getLogger from '../utils/getLogger'; |
9 | import { HighlightingService } from './HighlightingService'; | 9 | |
10 | import { OccurrencesService } from './OccurrencesService'; | 10 | import ContentAssistService from './ContentAssistService'; |
11 | import { UpdateService } from './UpdateService'; | 11 | import HighlightingService from './HighlightingService'; |
12 | import { getLogger } from '../utils/logger'; | 12 | import OccurrencesService from './OccurrencesService'; |
13 | import { ValidationService } from './ValidationService'; | 13 | import UpdateService from './UpdateService'; |
14 | import { XtextWebSocketClient } from './XtextWebSocketClient'; | 14 | import ValidationService from './ValidationService'; |
15 | import { XtextWebPushService } from './xtextMessages'; | 15 | import XtextWebSocketClient from './XtextWebSocketClient'; |
16 | import type { XtextWebPushService } from './xtextMessages'; | ||
16 | 17 | ||
17 | const log = getLogger('xtext.XtextClient'); | 18 | const log = getLogger('xtext.XtextClient'); |
18 | 19 | ||
19 | export class XtextClient { | 20 | export default class XtextClient { |
20 | private readonly webSocketClient: XtextWebSocketClient; | 21 | private readonly webSocketClient: XtextWebSocketClient; |
21 | 22 | ||
22 | private readonly updateService: UpdateService; | 23 | private readonly updateService: UpdateService; |
@@ -32,11 +33,15 @@ export class XtextClient { | |||
32 | constructor(store: EditorStore) { | 33 | constructor(store: EditorStore) { |
33 | this.webSocketClient = new XtextWebSocketClient( | 34 | this.webSocketClient = new XtextWebSocketClient( |
34 | () => this.updateService.onReconnect(), | 35 | () => this.updateService.onReconnect(), |
35 | (resource, stateId, service, push) => this.onPush(resource, stateId, service, push), | 36 | (resource, stateId, service, push) => |
37 | this.onPush(resource, stateId, service, push), | ||
36 | ); | 38 | ); |
37 | this.updateService = new UpdateService(store, this.webSocketClient); | 39 | this.updateService = new UpdateService(store, this.webSocketClient); |
38 | this.contentAssistService = new ContentAssistService(this.updateService); | 40 | this.contentAssistService = new ContentAssistService(this.updateService); |
39 | this.highlightingService = new HighlightingService(store, this.updateService); | 41 | this.highlightingService = new HighlightingService( |
42 | store, | ||
43 | this.updateService, | ||
44 | ); | ||
40 | this.validationService = new ValidationService(store, this.updateService); | 45 | this.validationService = new ValidationService(store, this.updateService); |
41 | this.occurrencesService = new OccurrencesService( | 46 | this.occurrencesService = new OccurrencesService( |
42 | store, | 47 | store, |
@@ -53,14 +58,29 @@ export class XtextClient { | |||
53 | this.occurrencesService.onTransaction(transaction); | 58 | this.occurrencesService.onTransaction(transaction); |
54 | } | 59 | } |
55 | 60 | ||
56 | private onPush(resource: string, stateId: string, service: XtextWebPushService, push: unknown) { | 61 | private onPush( |
62 | resource: string, | ||
63 | stateId: string, | ||
64 | service: XtextWebPushService, | ||
65 | push: unknown, | ||
66 | ) { | ||
57 | const { resourceName, xtextStateId } = this.updateService; | 67 | const { resourceName, xtextStateId } = this.updateService; |
58 | if (resource !== resourceName) { | 68 | if (resource !== resourceName) { |
59 | log.error('Unknown resource name: expected:', resourceName, 'got:', resource); | 69 | log.error( |
70 | 'Unknown resource name: expected:', | ||
71 | resourceName, | ||
72 | 'got:', | ||
73 | resource, | ||
74 | ); | ||
60 | return; | 75 | return; |
61 | } | 76 | } |
62 | if (stateId !== xtextStateId) { | 77 | if (stateId !== xtextStateId) { |
63 | log.error('Unexpected xtext state id: expected:', xtextStateId, 'got:', stateId); | 78 | log.error( |
79 | 'Unexpected xtext state id: expected:', | ||
80 | xtextStateId, | ||
81 | 'got:', | ||
82 | stateId, | ||
83 | ); | ||
64 | // The current push message might be stale (referring to a previous state), | 84 | // The current push message might be stale (referring to a previous state), |
65 | // so this is not neccessarily an error and there is no need to force-reconnect. | 85 | // so this is not neccessarily an error and there is no need to force-reconnect. |
66 | return; | 86 | return; |
@@ -71,6 +91,9 @@ export class XtextClient { | |||
71 | return; | 91 | return; |
72 | case 'validate': | 92 | case 'validate': |
73 | this.validationService.onPush(push); | 93 | this.validationService.onPush(push); |
94 | return; | ||
95 | default: | ||
96 | throw new Error('Unknown service'); | ||
74 | } | 97 | } |
75 | } | 98 | } |
76 | 99 | ||