aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/xtext')
-rw-r--r--subprojects/frontend/src/xtext/OccurrencesService.ts5
-rw-r--r--subprojects/frontend/src/xtext/XtextClient.ts4
-rw-r--r--subprojects/frontend/src/xtext/XtextWebSocketClient.ts3
-rw-r--r--subprojects/frontend/src/xtext/webSocketMachine.ts9
4 files changed, 13 insertions, 8 deletions
diff --git a/subprojects/frontend/src/xtext/OccurrencesService.ts b/subprojects/frontend/src/xtext/OccurrencesService.ts
index 9d738d76..248a9a87 100644
--- a/subprojects/frontend/src/xtext/OccurrencesService.ts
+++ b/subprojects/frontend/src/xtext/OccurrencesService.ts
@@ -1,5 +1,6 @@
1import { Transaction } from '@codemirror/state'; 1import { Transaction } from '@codemirror/state';
2import { debounce } from 'lodash-es'; 2import { debounce } from 'lodash-es';
3import ms from 'ms';
3 4
4import type EditorStore from '../editor/EditorStore'; 5import type EditorStore from '../editor/EditorStore';
5import { 6import {
@@ -11,7 +12,7 @@ import getLogger from '../utils/getLogger';
11import type UpdateService from './UpdateService'; 12import type UpdateService from './UpdateService';
12import type { TextRegion } from './xtextServiceResults'; 13import type { TextRegion } from './xtextServiceResults';
13 14
14const FIND_OCCURRENCES_TIMEOUT_MS = 1000; 15const FIND_OCCURRENCES_TIMEOUT = ms('1s');
15 16
16const log = getLogger('xtext.OccurrencesService'); 17const log = getLogger('xtext.OccurrencesService');
17 18
@@ -33,7 +34,7 @@ export default class OccurrencesService {
33 34
34 private readonly findOccurrencesLater = debounce( 35 private readonly findOccurrencesLater = debounce(
35 () => this.findOccurrences(), 36 () => this.findOccurrences(),
36 FIND_OCCURRENCES_TIMEOUT_MS, 37 FIND_OCCURRENCES_TIMEOUT,
37 ); 38 );
38 39
39 constructor( 40 constructor(
diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts
index 1f7e446f..cd5d280d 100644
--- a/subprojects/frontend/src/xtext/XtextClient.ts
+++ b/subprojects/frontend/src/xtext/XtextClient.ts
@@ -4,6 +4,7 @@ import type {
4} from '@codemirror/autocomplete'; 4} from '@codemirror/autocomplete';
5import type { Transaction } from '@codemirror/state'; 5import type { Transaction } from '@codemirror/state';
6 6
7import type PWAStore from '../PWAStore';
7import type EditorStore from '../editor/EditorStore'; 8import type EditorStore from '../editor/EditorStore';
8import getLogger from '../utils/getLogger'; 9import getLogger from '../utils/getLogger';
9 10
@@ -30,7 +31,7 @@ export default class XtextClient {
30 31
31 private readonly occurrencesService: OccurrencesService; 32 private readonly occurrencesService: OccurrencesService;
32 33
33 constructor(store: EditorStore) { 34 constructor(store: EditorStore, private readonly pwaStore: PWAStore) {
34 this.webSocketClient = new XtextWebSocketClient( 35 this.webSocketClient = new XtextWebSocketClient(
35 () => this.onReconnect(), 36 () => this.onReconnect(),
36 () => this.onDisconnect(), 37 () => this.onDisconnect(),
@@ -54,6 +55,7 @@ export default class XtextClient {
54 private onReconnect(): void { 55 private onReconnect(): void {
55 this.updateService.onReconnect(); 56 this.updateService.onReconnect();
56 this.occurrencesService.onReconnect(); 57 this.occurrencesService.onReconnect();
58 this.pwaStore.checkForUpdates();
57 } 59 }
58 60
59 private onDisconnect(): void { 61 private onDisconnect(): void {
diff --git a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts
index cba6f064..a39620cb 100644
--- a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts
+++ b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts
@@ -1,4 +1,5 @@
1import { createAtom, makeAutoObservable, observable } from 'mobx'; 1import { createAtom, makeAutoObservable, observable } from 'mobx';
2import ms from 'ms';
2import { nanoid } from 'nanoid'; 3import { nanoid } from 'nanoid';
3import { interpret } from 'xstate'; 4import { interpret } from 'xstate';
4 5
@@ -18,7 +19,7 @@ const XTEXT_SUBPROTOCOL_V1 = 'tools.refinery.language.web.xtext.v1';
18 19
19// Use a large enough timeout so that a request can complete successfully 20// Use a large enough timeout so that a request can complete successfully
20// even if the browser has throttled the background tab. 21// even if the browser has throttled the background tab.
21const REQUEST_TIMEOUT = 5000; 22const REQUEST_TIMEOUT = ms('5s');
22 23
23const log = getLogger('xtext.XtextWebSocketClient'); 24const log = getLogger('xtext.XtextWebSocketClient');
24 25
diff --git a/subprojects/frontend/src/xtext/webSocketMachine.ts b/subprojects/frontend/src/xtext/webSocketMachine.ts
index 25689cec..a1eee781 100644
--- a/subprojects/frontend/src/xtext/webSocketMachine.ts
+++ b/subprojects/frontend/src/xtext/webSocketMachine.ts
@@ -1,8 +1,9 @@
1import ms from 'ms';
1import { actions, assign, createMachine, RaiseAction } from 'xstate'; 2import { actions, assign, createMachine, RaiseAction } from 'xstate';
2 3
3const { raise } = actions; 4const { raise } = actions;
4 5
5const ERROR_WAIT_TIMES = [200, 1000, 5000, 30_000]; 6const ERROR_WAIT_TIMES = ['200', '1s', '5s', '30s'].map(ms);
6 7
7export interface WebSocketContext { 8export interface WebSocketContext {
8 webSocketURL: string | undefined; 9 webSocketURL: string | undefined;
@@ -229,9 +230,9 @@ export default createMachine(
229 needsNetwork: ({ webSocketURL }) => !isWebSocketURLLocal(webSocketURL), 230 needsNetwork: ({ webSocketURL }) => !isWebSocketURLLocal(webSocketURL),
230 }, 231 },
231 delays: { 232 delays: {
232 IDLE_TIMEOUT: 300_000, 233 IDLE_TIMEOUT: ms('5m'),
233 OPEN_TIMEOUT: 10_000, 234 OPEN_TIMEOUT: ms('10s'),
234 PING_PERIOD: 10_000, 235 PING_PERIOD: ms('10s'),
235 ERROR_WAIT_TIME: ({ errors: { length: retryCount } }) => { 236 ERROR_WAIT_TIME: ({ errors: { length: retryCount } }) => {
236 const { length } = ERROR_WAIT_TIMES; 237 const { length } = ERROR_WAIT_TIMES;
237 const index = retryCount < length ? retryCount : length - 1; 238 const index = retryCount < length ? retryCount : length - 1;