aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-09-05 01:29:11 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-09-06 01:05:24 +0200
commiteb94326bb64552dbd7df62ae201ccca37f368467 (patch)
treeb810f0230ace058cac8a6343455ca60113925221 /subprojects/frontend/src/xtext
parentrefactor(frontend): more readable indentation (diff)
downloadrefinery-eb94326bb64552dbd7df62ae201ccca37f368467.tar.gz
refinery-eb94326bb64552dbd7df62ae201ccca37f368467.tar.zst
refinery-eb94326bb64552dbd7df62ae201ccca37f368467.zip
feat(frontend): show connection status
Diffstat (limited to 'subprojects/frontend/src/xtext')
-rw-r--r--subprojects/frontend/src/xtext/ContentAssistService.ts7
-rw-r--r--subprojects/frontend/src/xtext/HighlightingService.ts4
-rw-r--r--subprojects/frontend/src/xtext/OccurrencesService.ts11
-rw-r--r--subprojects/frontend/src/xtext/UpdateService.ts4
-rw-r--r--subprojects/frontend/src/xtext/ValidationService.ts4
-rw-r--r--subprojects/frontend/src/xtext/XtextClient.ts16
-rw-r--r--subprojects/frontend/src/xtext/XtextWebSocketClient.ts12
7 files changed, 55 insertions, 3 deletions
diff --git a/subprojects/frontend/src/xtext/ContentAssistService.ts b/subprojects/frontend/src/xtext/ContentAssistService.ts
index 9e41f57b..101990af 100644
--- a/subprojects/frontend/src/xtext/ContentAssistService.ts
+++ b/subprojects/frontend/src/xtext/ContentAssistService.ts
@@ -115,6 +115,13 @@ export default class ContentAssistService {
115 } 115 }
116 116
117 async contentAssist(context: CompletionContext): Promise<CompletionResult> { 117 async contentAssist(context: CompletionContext): Promise<CompletionResult> {
118 if (!this.updateService.opened) {
119 this.lastCompletion = undefined;
120 return {
121 from: context.pos,
122 options: [],
123 };
124 }
118 const tokenBefore = findToken(context); 125 const tokenBefore = findToken(context);
119 if (!context.explicit && !shouldCompleteImplicitly(tokenBefore, context)) { 126 if (!context.explicit && !shouldCompleteImplicitly(tokenBefore, context)) {
120 return { 127 return {
diff --git a/subprojects/frontend/src/xtext/HighlightingService.ts b/subprojects/frontend/src/xtext/HighlightingService.ts
index f9ab7b7e..a126ee40 100644
--- a/subprojects/frontend/src/xtext/HighlightingService.ts
+++ b/subprojects/frontend/src/xtext/HighlightingService.ts
@@ -31,4 +31,8 @@ export default class HighlightingService {
31 }); 31 });
32 this.store.updateSemanticHighlighting(ranges); 32 this.store.updateSemanticHighlighting(ranges);
33 } 33 }
34
35 onDisconnect(): void {
36 this.store.updateSemanticHighlighting([]);
37 }
34} 38}
diff --git a/subprojects/frontend/src/xtext/OccurrencesService.ts b/subprojects/frontend/src/xtext/OccurrencesService.ts
index c8d6fd7b..9d738d76 100644
--- a/subprojects/frontend/src/xtext/OccurrencesService.ts
+++ b/subprojects/frontend/src/xtext/OccurrencesService.ts
@@ -41,6 +41,15 @@ export default class OccurrencesService {
41 private readonly updateService: UpdateService, 41 private readonly updateService: UpdateService,
42 ) {} 42 ) {}
43 43
44 onReconnect(): void {
45 this.clearOccurrences();
46 this.findOccurrencesLater();
47 }
48
49 onDisconnect(): void {
50 this.clearOccurrences();
51 }
52
44 onTransaction(transaction: Transaction): void { 53 onTransaction(transaction: Transaction): void {
45 if (transaction.docChanged) { 54 if (transaction.docChanged) {
46 // Must clear occurrences asynchronously from `onTransaction`, 55 // Must clear occurrences asynchronously from `onTransaction`,
@@ -91,7 +100,7 @@ export default class OccurrencesService {
91 } 100 }
92 101
93 private async updateOccurrences() { 102 private async updateOccurrences() {
94 if (!this.needsOccurrences) { 103 if (!this.needsOccurrences || !this.updateService.opened) {
95 this.clearOccurrences(); 104 this.clearOccurrences();
96 return; 105 return;
97 } 106 }
diff --git a/subprojects/frontend/src/xtext/UpdateService.ts b/subprojects/frontend/src/xtext/UpdateService.ts
index d7471cdc..63e28652 100644
--- a/subprojects/frontend/src/xtext/UpdateService.ts
+++ b/subprojects/frontend/src/xtext/UpdateService.ts
@@ -82,6 +82,10 @@ export default class UpdateService {
82 } 82 }
83 } 83 }
84 84
85 get opened(): boolean {
86 return this.webSocketClient.opened;
87 }
88
85 private idleUpdate(): void { 89 private idleUpdate(): void {
86 if (!this.webSocketClient.opened || !this.tracker.needsUpdate) { 90 if (!this.webSocketClient.opened || !this.tracker.needsUpdate) {
87 return; 91 return;
diff --git a/subprojects/frontend/src/xtext/ValidationService.ts b/subprojects/frontend/src/xtext/ValidationService.ts
index e78318f7..72414590 100644
--- a/subprojects/frontend/src/xtext/ValidationService.ts
+++ b/subprojects/frontend/src/xtext/ValidationService.ts
@@ -28,4 +28,8 @@ export default class ValidationService {
28 }); 28 });
29 this.store.updateDiagnostics(diagnostics); 29 this.store.updateDiagnostics(diagnostics);
30 } 30 }
31
32 onDisconnect(): void {
33 this.store.updateDiagnostics([]);
34 }
31} 35}
diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts
index 6351c9fd..c02afb3b 100644
--- a/subprojects/frontend/src/xtext/XtextClient.ts
+++ b/subprojects/frontend/src/xtext/XtextClient.ts
@@ -18,7 +18,7 @@ import type { XtextWebPushService } from './xtextMessages';
18const log = getLogger('xtext.XtextClient'); 18const log = getLogger('xtext.XtextClient');
19 19
20export default class XtextClient { 20export default class XtextClient {
21 private readonly webSocketClient: XtextWebSocketClient; 21 readonly webSocketClient: XtextWebSocketClient;
22 22
23 private readonly updateService: UpdateService; 23 private readonly updateService: UpdateService;
24 24
@@ -32,7 +32,8 @@ export default class XtextClient {
32 32
33 constructor(store: EditorStore) { 33 constructor(store: EditorStore) {
34 this.webSocketClient = new XtextWebSocketClient( 34 this.webSocketClient = new XtextWebSocketClient(
35 () => this.updateService.onReconnect(), 35 () => this.onReconnect(),
36 () => this.onDisconnect(),
36 (resource, stateId, service, push) => 37 (resource, stateId, service, push) =>
37 this.onPush(resource, stateId, service, push), 38 this.onPush(resource, stateId, service, push),
38 ); 39 );
@@ -46,6 +47,17 @@ export default class XtextClient {
46 this.occurrencesService = new OccurrencesService(store, this.updateService); 47 this.occurrencesService = new OccurrencesService(store, this.updateService);
47 } 48 }
48 49
50 private onReconnect(): void {
51 this.updateService.onReconnect();
52 this.occurrencesService.onReconnect();
53 }
54
55 private onDisconnect(): void {
56 this.highlightingService.onDisconnect();
57 this.validationService.onDisconnect();
58 this.occurrencesService.onDisconnect();
59 }
60
49 onTransaction(transaction: Transaction): void { 61 onTransaction(transaction: Transaction): void {
50 // `ContentAssistService.prototype.onTransaction` needs the dirty change desc 62 // `ContentAssistService.prototype.onTransaction` needs the dirty change desc
51 // _before_ the current edit, so we call it before `updateService`. 63 // _before_ the current edit, so we call it before `updateService`.
diff --git a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts
index eedfa365..b69e1d6c 100644
--- a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts
+++ b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts
@@ -22,6 +22,8 @@ const log = getLogger('xtext.XtextWebSocketClient');
22 22
23export type ReconnectHandler = () => void; 23export type ReconnectHandler = () => void;
24 24
25export type DisconnectHandler = () => void;
26
25export type PushHandler = ( 27export type PushHandler = (
26 resourceId: string, 28 resourceId: string,
27 stateId: string, 29 stateId: string,
@@ -136,6 +138,7 @@ export default class XtextWebSocketClient {
136 138
137 constructor( 139 constructor(
138 private readonly onReconnect: ReconnectHandler, 140 private readonly onReconnect: ReconnectHandler,
141 private readonly onDisconnect: DisconnectHandler,
139 private readonly onPush: PushHandler, 142 private readonly onPush: PushHandler,
140 ) { 143 ) {
141 this.interpreter 144 this.interpreter
@@ -179,10 +182,18 @@ export default class XtextWebSocketClient {
179 return this.interpreter.state; 182 return this.interpreter.state;
180 } 183 }
181 184
185 get opening(): boolean {
186 return this.state.matches('connection.socketCreated.open.opening');
187 }
188
182 get opened(): boolean { 189 get opened(): boolean {
183 return this.state.matches('connection.socketCreated.open.opened'); 190 return this.state.matches('connection.socketCreated.open.opened');
184 } 191 }
185 192
193 get errors(): string[] {
194 return this.state.context.errors;
195 }
196
186 connect(): void { 197 connect(): void {
187 this.interpreter.send('CONNECT'); 198 this.interpreter.send('CONNECT');
188 } 199 }
@@ -261,6 +272,7 @@ export default class XtextWebSocketClient {
261 } 272 }
262 273
263 private cancelPendingRequests(): void { 274 private cancelPendingRequests(): void {
275 this.onDisconnect();
264 this.pendingRequests.forEach((task) => 276 this.pendingRequests.forEach((task) =>
265 task.reject(new CancelledError('Closing connection')), 277 task.reject(new CancelledError('Closing connection')),
266 ); 278 );