Skip to content

Commit

Permalink
GLSP-77: Allow WebSocket connections to reconnect after interrupt (#54)
Browse files Browse the repository at this point in the history
* GLSP-77: Allow WebSocket connections to reconnect after interrupt

If Websocket connections reconnect after an interrupt, ensure that the last modelState is restored on RequestModelAction if available

Part of eclipse-glsp/glsp#77
  • Loading branch information
ndoschek authored Jul 24, 2023
1 parent de91dcd commit 5fd686c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Action, RequestModelAction, ServerStatusAction } from '@eclipse-glsp/pr
import { inject, injectable } from 'inversify';
import { ActionDispatcher } from '../../actions/action-dispatcher';
import { ActionHandler } from '../../actions/action-handler';
import { ClientOptionsUtil } from '../../utils/client-options-util';
import { Logger } from '../../utils/logger';
import { ProgressMonitor, ProgressService } from '../progress/progress-service';
import { ModelState } from './model-state';
Expand Down Expand Up @@ -49,13 +50,31 @@ export class RequestModelActionHandler implements ActionHandler {
this.logger.debug('Execute RequestModelAction:', action);
this.modelState.setAll(action.options ?? {});

const isReconnecting = ClientOptionsUtil.isReconnecting(action.options);

const progress = this.reportModelLoading('Model loading in progress');
await this.sourceModelStorage.loadSourceModel(action);

if (isReconnecting) {
await this.handleReconnect(action);
} else {
await this.sourceModelStorage.loadSourceModel(action);
}
this.reportModelLoadingFinished(progress);

return this.submissionHandler.submitModel();
}

protected async handleReconnect(action: RequestModelAction): Promise<void> {
const oldModelRoot = this.modelState.root;
if (oldModelRoot) {
// decrease revision by one, as each submit will increase it by one;
// the next save would produce warning that source model was changed otherwise
this.modelState.root.revision = (this.modelState.root.revision ?? 0) - 1;
} else {
await this.sourceModelStorage.loadSourceModel(action);
}
}

protected reportModelLoading(message: string): ProgressMonitor {
this.actionDispatcher.dispatch(ServerStatusAction.create(message, { severity: 'INFO' }));
return this.progressService.start(message);
Expand Down
8 changes: 8 additions & 0 deletions packages/server/src/common/utils/client-options-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Args } from '@eclipse-glsp/protocol';
import { ArgsUtil } from './args-util';

export class ClientOptionsUtil {
private static FILE_PREFIX = 'file://';
public static IS_RECONNECTING = 'isReconnecting';

public static adaptUri(uri: string): string {
return uri.replace(this.FILE_PREFIX, '');
}

public static isReconnecting(options?: Args): boolean {
return ArgsUtil.getBoolean(options, ClientOptionsUtil.IS_RECONNECTING);
}
}

0 comments on commit 5fd686c

Please sign in to comment.