Skip to content

Commit

Permalink
GLSP-1096: Update to sprotty 0.14.0
Browse files Browse the repository at this point in the history
Update to sprotty 0.14.0 and adapt code to conform to latest changes/API breaks.
With 0.14.0 the `ToolManager API` was deprecated and it will be removed in future versions.
The intention is that this API moves to GLSP as it is only used there => refactor `ToolManager API`

GLSP-960: Make glspClient retrieval async

Fixes eclipse-glsp/glsp#1096
Fixes eclipse-glsp/glsp#1094
  • Loading branch information
tortmayr committed Aug 25, 2023
1 parent 976795c commit c6b2140
Show file tree
Hide file tree
Showing 40 changed files with 443 additions and 288 deletions.
2 changes: 1 addition & 1 deletion examples/workflow-standalone/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ wsProvider.listen({ onConnection: initialize, onReconnect: reconnect, logger: co

async function initialize(connectionProvider: MessageConnection, isReconnecting = false): Promise<void> {
glspClient = new BaseJsonrpcGLSPClient({ id, connectionProvider });
container = createContainer({ clientId, diagramType, glspClient, sourceUri: examplePath });
container = createContainer({ clientId, diagramType, glspClientProvider: async () => glspClient, sourceUri: examplePath });
const actionDispatcher = container.get(GLSPActionDispatcher);
const diagramLoader = container.get(DiagramLoader);
await diagramLoader.load({ isReconnecting });
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@eclipse-glsp/protocol": "1.1.0-next",
"autocompleter": "5.1.0",
"lodash": "4.17.21",
"sprotty": "0.14.0-next.02bbac0.26"
"sprotty": "~0.14.0"
},
"devDependencies": {
"@types/file-saver": "^2.0.3",
Expand Down
13 changes: 10 additions & 3 deletions packages/client/src/base/default.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import { GLSPModelSource } from './model/glsp-model-source';
import { GLSPModelRegistry } from './model/model-registry';
import { SelectionClearingMouseListener } from './selection-clearing-mouse-listener';
import { SelectionService } from './selection-service';
import { GLSPToolManager } from './tool-manager/glsp-tool-manager';
import { EnableDefaultToolsAction, EnableToolsAction } from './tool-manager/tool';
import { DefaultToolsEnablingKeyListener, ToolManager, ToolManagerActionHandler } from './tool-manager/tool-manager';
import { GLSPKeyTool } from './view/key-tool';
import { GLSPMouseTool } from './view/mouse-tool';
import { GLSPViewRegistry } from './view/view-registry';
Expand Down Expand Up @@ -88,8 +89,6 @@ export const defaultModule = new FeatureModule((bind, unbind, isBound, rebind, .
bindAsService(context, TYPES.MouseListener, SelectionClearingMouseListener);

bindOrRebind(context, TYPES.ICommandStack).to(GLSPCommandStack).inSingletonScope();
bind(GLSPToolManager).toSelf().inSingletonScope();
bindOrRebind(context, TYPES.IToolManager).toService(GLSPToolManager);
bind(GLSPActionDispatcher).toSelf().inSingletonScope();
bindOrRebind(context, TYPES.IActionDispatcher).toService(GLSPActionDispatcher);

Expand All @@ -112,4 +111,12 @@ export const defaultModule = new FeatureModule((bind, unbind, isBound, rebind, .

bindAsService(context, TYPES.IVNodePostprocessor, LocationPostprocessor);
bind(TYPES.HiddenVNodePostprocessor).toService(LocationPostprocessor);

// Tool manager initialization ------------------------------------
bind(TYPES.IToolManager).to(ToolManager).inSingletonScope();
bind(DefaultToolsEnablingKeyListener).toSelf().inSingletonScope();
bind(TYPES.KeyListener).toService(DefaultToolsEnablingKeyListener);
bind(ToolManagerActionHandler).toSelf().inSingletonScope();
configureActionHandler(context, EnableDefaultToolsAction.KIND, ToolManagerActionHandler);
configureActionHandler(context, EnableToolsAction.KIND, ToolManagerActionHandler);
});
5 changes: 0 additions & 5 deletions packages/client/src/base/editor-context-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
EditorContext,
Emitter,
Event,
GLSPClient,
IActionHandler,
MaybePromise,
MousePositionTracker,
Expand Down Expand Up @@ -154,10 +153,6 @@ export class EditorContextService implements IActionHandler, Disposable, IDiagra
return this.diagramOptions.clientId;
}

get glspClient(): GLSPClient {
return this.diagramOptions.glspClient;
}

get modelRoot(): Readonly<SModelRoot> {
return this.selectionService.getModelRoot();
}
Expand Down
10 changes: 3 additions & 7 deletions packages/client/src/base/model/diagram-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import {
ApplicationIdProvider,
Args,
EMPTY_ROOT,
EndProgressAction,
GLSPClient,
MaybePromise,
RequestModelAction,
ServerStatusAction,
SetModelAction,
StartProgressAction,
TYPES,
hasNumberProp
} from '~glsp-sprotty';
Expand All @@ -47,9 +45,9 @@ export interface IDiagramOptions {
*/
diagramType: string;
/**
* The GLSP client used by this diagram to communicate with the server.
* The provider function to retrieve the GLSP client used by this diagram to communicate with the server.
*/
glspClient: GLSPClient;
glspClientProvider: () => Promise<GLSPClient>;
/**
* The file source URI associated with this diagram.
*/
Expand Down Expand Up @@ -140,17 +138,15 @@ export class DiagramLoader {
const result = this.actionDispatcher.dispatch(RequestModelAction.create({ options }));
if (this.enableLoadingNotifications) {
this.actionDispatcher.dispatch(ServerStatusAction.create('', { severity: 'NONE' }));
this.actionDispatcher.dispatch(EndProgressAction.create('initializeClient'));
}
return result;
}

protected async configureGLSPClient(): Promise<void> {
const glspClient = this.options.glspClient;
const glspClient = await this.options.glspClientProvider();

if (this.enableLoadingNotifications) {
this.actionDispatcher.dispatch(ServerStatusAction.create('Initializing...', { severity: 'INFO' }));
this.actionDispatcher.dispatch(StartProgressAction.create({ progressId: 'initializeClient', title: 'Initializing' }));
}

await glspClient.start();
Expand Down
55 changes: 36 additions & 19 deletions packages/client/src/base/model/glsp-model-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { inject, injectable } from 'inversify';
import { inject, injectable, postConstruct } from 'inversify';
import {
Action,
ActionHandlerRegistry,
Expand All @@ -26,7 +26,8 @@ import {
InitializeResult,
ModelSource,
SModelRootSchema,
TYPES
TYPES,
Writable
} from '~glsp-sprotty';
import { IDiagramOptions } from './diagram-loader';
/**
Expand Down Expand Up @@ -65,18 +66,25 @@ export class GLSPModelSource extends ModelSource implements Disposable {
@inject(TYPES.ILogger)
protected logger: ILogger;

@inject(TYPES.IDiagramOptions)
protected options: IDiagramOptions;

protected toDispose = new DisposableCollection();
clientId: string;
readonly glspClient: GLSPClient;
readonly sourceUri?: string;
readonly diagramType: string;

constructor(@inject(TYPES.IDiagramOptions) options: IDiagramOptions) {
super();
this.glspClient = options.glspClient;
this.clientId = options.clientId ?? this.viewerOptions.baseDiv;
this.diagramType = options.diagramType;
this.sourceUri = options.sourceUri;
readonly glspClient: GLSPClient | undefined;
protected _currentRoot: SModelRootSchema;

get diagramType(): string {
return this.options.diagramType;
}

get sourceUri(): string | undefined {
return this.options.sourceUri;
}

@postConstruct()
protected postConstruct(): void {
this.clientId = this.options.clientId ?? this.viewerOptions.baseDiv;
}

configure(registry: ActionHandlerRegistry, initializeResult: InitializeResult): Promise<void> {
Expand All @@ -85,8 +93,8 @@ export class GLSPModelSource extends ModelSource implements Disposable {
throw new Error(`No server-handled actions could be derived from the initialize result for diagramType: ${this.diagramType}!`);
}
serverActions.forEach(action => registry.register(action, this));
this.toDispose.push(this.glspClient.onActionMessage(message => this.messageReceived(message), this.clientId));
return this.glspClient.initializeClientSession({ clientSessionId: this.clientId, diagramType: this.diagramType });
this.toDispose.push(this.glspClient!.onActionMessage(message => this.messageReceived(message), this.clientId));
return this.glspClient!.initializeClientSession({ clientSessionId: this.clientId, diagramType: this.diagramType });
}

protected messageReceived(message: ActionMessage): void {
Expand All @@ -105,11 +113,15 @@ export class GLSPModelSource extends ModelSource implements Disposable {
if (!this.clientId) {
this.clientId = this.viewerOptions.baseDiv;
}
if (this.glspClient.initializeResult) {
this.configure(registry, this.glspClient.initializeResult);
} else {
this.glspClient.onServerInitialized(result => this.configure(registry, result));
}

this.options.glspClientProvider().then(glspClient => {
(this as Writable<GLSPModelSource>).glspClient = glspClient;
if (glspClient.initializeResult) {
this.configure(registry, glspClient.initializeResult);
} else {
glspClient.onServerInitialized(result => this.configure(registry, result));
}
});
}

handle(action: Action): void {
Expand Down Expand Up @@ -143,9 +155,14 @@ export class GLSPModelSource extends ModelSource implements Disposable {
* The internal/local model should never be committed back to the model source i.e. GLSP server.
* => no-op implementation that simply returns the `newRoot`
*/
this._currentRoot = newRoot;
return newRoot;
}

override get model(): SModelRootSchema {
return this._currentRoot;
}

dispose(): void {
this.toDispose.dispose();
}
Expand Down
96 changes: 0 additions & 96 deletions packages/client/src/base/tool-manager/glsp-tool-manager.ts

This file was deleted.

Loading

0 comments on commit c6b2140

Please sign in to comment.