Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that all services that return MaybePromises are properly awaited #36

Merged
merged 2 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { NavigationTarget } from '@eclipse-glsp/protocol';
import { MaybePromise, NavigationTarget } from '@eclipse-glsp/protocol';
import { ModelState } from '@eclipse-glsp/server-node';
import { NavigationTargetResolution } from '@eclipse-glsp/server-node/lib/features/navigation/navigation-target-resolution';
import { NavigationTargetResolver } from '@eclipse-glsp/server-node/lib/features/navigation/navigation-target-resolver';
Expand All @@ -25,7 +25,7 @@ export class WorkflowNavigationTargetResolver extends NavigationTargetResolver {
@inject(ModelState)
protected readonly modelState: ModelState;

async resolve(navigationTarget: NavigationTarget): Promise<NavigationTargetResolution> {
resolve(navigationTarget: NavigationTarget): MaybePromise<NavigationTargetResolution> {
if (navigationTarget.args && navigationTarget.args['name']) {
const name = navigationTarget.args['name'];
const taskNodes = this.modelState.index.getAllByClass<TaskNode>(TaskNode);
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
"watch": "lerna run --parallel watch"
},
"devDependencies": {
"@eclipse-glsp/cli": "1.1.0-next.4846de1.120",
"@eclipse-glsp/config": "1.1.0-next.4846de1.120",
"@eclipse-glsp/config-test": "1.1.0-next.4846de1.120",
"@eclipse-glsp/dev": "1.1.0-next.164cf99.124",
"@types/node": "16.x"
},
"engines": {
Expand Down
9 changes: 4 additions & 5 deletions packages/server-node/src/actions/action-dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,11 +13,10 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Action, flatPush, MaybeArray, RequestAction, ResponseAction, UpdateModelAction } from '@eclipse-glsp/protocol';
import { Action, Disposable, flatPush, MaybeArray, RequestAction, ResponseAction, UpdateModelAction } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ActionHandler } from '../actions/action-handler';
import { ClientActionKinds, ClientId } from '../di/service-identifiers';
import { Disposable } from '../utils/disposable';
import { GLSPServerError } from '../utils/glsp-server-error';
import { Logger } from '../utils/logger';
import { PromiseQueue } from '../utils/promise-queue';
Expand Down Expand Up @@ -59,7 +58,7 @@ export interface ActionDispatcher {
}

@injectable()
export class DefaultActionDispatcher extends Disposable implements ActionDispatcher {
export class DefaultActionDispatcher implements ActionDispatcher, Disposable {
@inject(ActionHandlerRegistry)
protected actionHandlerRegistry: ActionHandlerRegistry;

Expand Down Expand Up @@ -133,7 +132,7 @@ export class DefaultActionDispatcher extends Disposable implements ActionDispatc
}
}

override doDispose(): void {
dispose(): void {
this.actionQueue.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -47,8 +47,8 @@ describe('test RequestTypeHintsActionHandler', () => {
);
const handler = container.resolve(RequestTypeHintsActionHandler);

it('execute with correct action', () => {
const result = handler.execute(RequestTypeHintsAction.create());
it('execute with correct action', async () => {
const result = await handler.execute(RequestTypeHintsAction.create());

expect(result).to.have.length(1);
expect(SetTypeHintsAction.is(result[0])).true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Action, RequestTypeHintsAction, SetTypeHintsAction } from '@eclipse-glsp/protocol';
import { Action, MaybePromise, RequestTypeHintsAction, SetTypeHintsAction } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ActionHandler } from '../actions/action-handler';
import { DiagramConfiguration } from './diagram-configuration';
Expand All @@ -23,7 +23,7 @@ export class RequestTypeHintsActionHandler implements ActionHandler {
@inject(DiagramConfiguration) protected diagramConfiguration: DiagramConfiguration;
static KINDS = [RequestTypeHintsAction.KIND];

execute(action: RequestTypeHintsAction): Action[] {
execute(action: RequestTypeHintsAction): MaybePromise<Action[]> {
return [
SetTypeHintsAction.create({
shapeHints: this.diagramConfiguration.shapeTypeHints,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -17,6 +17,7 @@ import { GModelRootSchema } from '@eclipse-glsp/graph';
import {
Action,
DirtyStateChangeReason,
MaybePromise,
RequestBoundsAction,
SetDirtyStateAction,
SetModelAction,
Expand Down Expand Up @@ -56,7 +57,7 @@ export class ModelSubmissionHandler {
* @param reason The optional reason that caused the model update.
* @returns A list of actions to be processed in order to submit the model.
*/
submitModel(reason?: DirtyStateChangeReason): Action[] {
submitModel(reason?: DirtyStateChangeReason): MaybePromise<Action[]> {
this.modelFactory.createModel();
this.modelState.root.revision = (this.modelState.root.revision ?? 0) + 1;
const root = this.serializeGModel();
Expand All @@ -81,11 +82,11 @@ export class ModelSubmissionHandler {
* @param reason The optional reason that caused the model update.
* @returns A list of actions to be processed in order to submit the model.
*/
submitModelDirectly(reason?: DirtyStateChangeReason): Action[] {
async submitModelDirectly(reason?: DirtyStateChangeReason): Promise<Action[]> {
const root = this.serializeGModel();

if (this.diagramConfiguration.layoutKind === ServerLayoutKind.AUTOMATIC && this.layoutEngine) {
this.layoutEngine.layout();
await this.layoutEngine.layout();
}
const result: Action[] = [];
result.push(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,10 +13,9 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Action, MaybePromise, SaveModelAction, SetDirtyStateAction } from '@eclipse-glsp/protocol';
import { Action, SaveModelAction, SetDirtyStateAction } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ActionHandler } from '../../actions/action-handler';
import { GLSPServerError } from '../../utils/glsp-server-error';
import { ModelState } from './model-state';
import { SourceModelStorage } from './source-model-storage';

Expand All @@ -30,13 +29,10 @@ export class SaveModelActionHandler implements ActionHandler {
@inject(SourceModelStorage)
protected sourceModelStorage: SourceModelStorage;

execute(action: SaveModelAction): MaybePromise<Action[]> {
try {
this.sourceModelStorage.saveSourceModel(action);
this.modelState.isDirty = false; // TODO: call save is done when available
} catch (err) {
throw new GLSPServerError(`An error occurred during save process: ${err}`);
}
async execute(action: SaveModelAction): Promise<Action[]> {
await this.sourceModelStorage.saveSourceModel(action);
this.modelState.isDirty = false; // TODO: call save is done when available

return [SetDirtyStateAction.create(this.modelState.isDirty, { reason: 'save' })];
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -28,7 +28,7 @@ export class RequestMarkersHandler implements ActionHandler {
@inject(ModelValidator) @optional() validator: ModelValidator;
@inject(ModelState) modelState: ModelState;

async execute(action: RequestMarkersAction, ...args: unknown[]): Promise<Action[]> {
async execute(action: RequestMarkersAction): Promise<Action[]> {
let elementIDs = action.elementsIDs;
if (!this.validator) {
throw new GLSPServerError('Cannot compute markers! No implementation for ModelValidator has been bound');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { GLabel } from '@eclipse-glsp/graph';
import { ApplyLabelEditOperation } from '@eclipse-glsp/protocol';
import { ApplyLabelEditOperation, MaybePromise } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ModelState } from '../features/model/model-state';
import { OperationHandler } from '../operations/operation-handler';
Expand All @@ -27,7 +27,7 @@ export class ApplyLabelEditOperationHandler implements OperationHandler {
@inject(ModelState)
protected readonly modelState: ModelState;

execute(operation: ApplyLabelEditOperation): void {
execute(operation: ApplyLabelEditOperation): MaybePromise<void> {
const element = this.modelState.index.findByClass(operation.labelId, GLabel);
if (element) {
element.text = operation.text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { GModelRoot, GNode } from '@eclipse-glsp/graph';
import { ChangeBoundsOperation, Dimension, Point } from '@eclipse-glsp/protocol';
import { ChangeBoundsOperation, Dimension, MaybePromise, Point } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ModelState } from '../features/model/model-state';
import { OperationHandler } from '../operations/operation-handler';
Expand All @@ -26,7 +26,7 @@ export class ChangeBoundsOperationHandler implements OperationHandler {
@inject(ModelState)
protected modelState: ModelState;

execute(operation: ChangeBoundsOperation): void {
execute(operation: ChangeBoundsOperation): MaybePromise<void> {
for (const element of operation.newBounds) {
this.changeElementBounds(element.elementId, element.newSize, element.newPosition);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 EclipseSource and others.
* Copyright (c) 2022-2023 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ChangeRoutingPointsOperation } from '@eclipse-glsp/protocol';
import { ChangeRoutingPointsOperation, MaybePromise } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ModelState } from '../features/model/model-state';
import { OperationHandler } from '../operations/operation-handler';
Expand All @@ -28,7 +28,7 @@ export class ChangeRoutingPointsOperationHandler implements OperationHandler {
@inject(ModelState)
protected modelState: ModelState;

execute(operation: ChangeRoutingPointsOperation): void {
execute(operation: ChangeRoutingPointsOperation): MaybePromise<void> {
if (!operation.newRoutingPoints) {
throw new GLSPServerError('Incomplete change routingPoints action');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { GModelRoot } from '@eclipse-glsp/graph';
import { Action, ComputedBoundsAction } from '@eclipse-glsp/protocol';
import { Action, ComputedBoundsAction, MaybePromise } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ActionHandler } from '../actions/action-handler';
import { ModelState } from '../features/model/model-state';
Expand All @@ -30,7 +30,7 @@ export class ComputedBoundsActionHandler implements ActionHandler {
protected modelState: ModelState;

actionKinds = [ComputedBoundsAction.KIND];
execute(action: ComputedBoundsAction): Action[] {
execute(action: ComputedBoundsAction): MaybePromise<Action[]> {
const model = this.modelState.root;
if (action.revision === model.revision) {
this.applyBounds(model, action);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { GEdge, GModelElement, GNode } from '@eclipse-glsp/graph';
import { DeleteElementOperation } from '@eclipse-glsp/protocol';
import { DeleteElementOperation, MaybePromise } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { GModelIndex } from '../features/model/gmodel-index';
import { ModelState } from '../features/model/model-state';
Expand All @@ -34,7 +34,7 @@ export class GModelDeleteOperationHandler implements OperationHandler {
return DeleteElementOperation.KIND;
}

execute(operation: DeleteElementOperation): void {
execute(operation: DeleteElementOperation): MaybePromise<void> {
const elementIds = operation.elementIds;
if (!elementIds || elementIds.length === 0) {
this.logger.warn('Elements to delete are not specified');
Expand Down
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 { GBoundsAware, GEdge, GModelElement, isGBoundsAware } from '@eclipse-glsp/graph';
import { PasteOperation, Point, SModelElementSchema } from '@eclipse-glsp/protocol';
import { MaybePromise, PasteOperation, Point, SModelElementSchema } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import * as uuid from 'uuid';
import { GModelSerializer } from '../features/model/gmodel-serializer';
Expand All @@ -33,7 +33,7 @@ export class PasteOperationHandler implements OperationHandler {
@inject(GModelSerializer)
protected modelSerializer: GModelSerializer;

execute(operation: PasteOperation): void {
execute(operation: PasteOperation): MaybePromise<void> {
const schemas: SModelElementSchema[] = JSON.parse(operation.clipboardData['application/json']);
const elements = schemas.map(schema => this.modelSerializer.createElement(schema, this.modelState.root));
shift(elements, this.computeOffset(elements, operation.editorContext.lastMousePosition));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { GEdge, GNode, GPort } from '@eclipse-glsp/graph';
import { ReconnectEdgeOperation } from '@eclipse-glsp/protocol';
import { MaybePromise, ReconnectEdgeOperation } from '@eclipse-glsp/protocol';
import { inject, injectable } from 'inversify';
import { ModelState } from '../features/model/model-state';
import { OperationHandler } from '../operations/operation-handler';
Expand All @@ -27,7 +27,7 @@ export class ReconnectEdgeOperationHandler implements OperationHandler {
@inject(ModelState)
protected readonly modelState: ModelState;

execute(operation: ReconnectEdgeOperation): void {
execute(operation: ReconnectEdgeOperation): MaybePromise<void> {
if (!operation.edgeElementId || !operation.sourceElementId || !operation.targetElementId) {
throw new GLSPServerError('Incomplete reconnect connection action');
}
Expand Down
Loading