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

GLSP-1254 Fix client-server action forwarding #58

Merged
merged 4 commits into from
Feb 19, 2024
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
10 changes: 5 additions & 5 deletions example/workflow/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "workflow-vscode-example",
"displayName": "Workflow GLSP Example",
"version": "2.1.0",
"version": "2.2.0-next",
"private": "true",
"description": "An example graphical language used for modeling workflows",
"categories": [
Expand Down Expand Up @@ -194,16 +194,16 @@
"onStartupFinished"
],
"devDependencies": {
"@eclipse-glsp-examples/workflow-server": "2.1.0",
"@eclipse-glsp-examples/workflow-server-bundled": "2.1.0",
"@eclipse-glsp/vscode-integration": "^2.1.0",
"@eclipse-glsp-examples/workflow-server": "next",
"@eclipse-glsp-examples/workflow-server-bundled": "next",
"@eclipse-glsp/vscode-integration": "2.2.0-next",
"@vscode/vsce": "^2.19.0",
"copy-webpack-plugin": "^11.0.0",
"ts-loader": "^9.4.4",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.9.0",
"workflow-glsp-webview": "^2.1.0"
"workflow-glsp-webview": "2.2.0-next"
},
"engines": {
"vscode": "^1.54.0"
Expand Down
6 changes: 3 additions & 3 deletions example/workflow/extension/src/workflow-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>

context.subscriptions.push(
vscode.commands.registerCommand('workflow.goToNextNode', () => {
glspVscodeConnector.sendActionToActiveClient(NavigateAction.create('next'));
glspVscodeConnector.dispatchAction(NavigateAction.create('next'));
}),
vscode.commands.registerCommand('workflow.goToPreviousNode', () => {
glspVscodeConnector.sendActionToActiveClient(NavigateAction.create('previous'));
glspVscodeConnector.dispatchAction(NavigateAction.create('previous'));
}),
vscode.commands.registerCommand('workflow.showDocumentation', () => {
glspVscodeConnector.sendActionToActiveClient(NavigateAction.create('documentation'));
glspVscodeConnector.dispatchAction(NavigateAction.create('documentation'));
})
);
}
Expand Down
8 changes: 4 additions & 4 deletions example/workflow/web-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "workflow-vscode-example-web",
"displayName": "Workflow GLSP Example (Web)",
"version": "2.1.0",
"version": "2.2.0-next",
"private": "true",
"description": "An example graphical language used for modeling workflows",
"categories": [
Expand Down Expand Up @@ -195,15 +195,15 @@
"onStartupFinished"
],
"devDependencies": {
"@eclipse-glsp-examples/workflow-server": "2.1.0",
"@eclipse-glsp/vscode-integration": "^2.1.0",
"@eclipse-glsp-examples/workflow-server": "next",
"@eclipse-glsp/vscode-integration": "2.2.0-next",
"@types/node": "16.x",
"@vscode/vsce": "^2.19.0",
"copy-webpack-plugin": "^11.0.0",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-merge": "^5.9.0",
"workflow-glsp-webview": "^2.1.0"
"workflow-glsp-webview": "2.2.0-next"
},
"engines": {
"vscode": "^1.54.0"
Expand Down
6 changes: 3 additions & 3 deletions example/workflow/web-extension/src/workflow-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>

context.subscriptions.push(
vscode.commands.registerCommand('workflow.goToNextNode', () => {
glspVscodeConnector.sendActionToActiveClient(NavigateAction.create('next'));
glspVscodeConnector.dispatchAction(NavigateAction.create('next'));
}),
vscode.commands.registerCommand('workflow.goToPreviousNode', () => {
glspVscodeConnector.sendActionToActiveClient(NavigateAction.create('previous'));
glspVscodeConnector.dispatchAction(NavigateAction.create('previous'));
}),
vscode.commands.registerCommand('workflow.showDocumentation', () => {
glspVscodeConnector.sendActionToActiveClient(NavigateAction.create('documentation'));
glspVscodeConnector.dispatchAction(NavigateAction.create('documentation'));
})
);
}
Expand Down
6 changes: 3 additions & 3 deletions example/workflow/webview/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workflow-glsp-webview",
"version": "2.1.0",
"version": "2.2.0-next",
"private": "true",
"description": "Example of the Workflow GLSP diagram in a VS Code extensions (WebView part)",
"keywords": [
Expand Down Expand Up @@ -38,8 +38,8 @@
"watch": "tsc -w"
},
"devDependencies": {
"@eclipse-glsp-examples/workflow-glsp": "2.1.0",
"@eclipse-glsp/vscode-integration-webview": "^2.1.0",
"@eclipse-glsp-examples/workflow-glsp": "next",
"@eclipse-glsp/vscode-integration-webview": "2.2.0-next",
"@vscode/codicons": "^0.0.25",
"circular-dependency-plugin": "^5.2.2",
"css-loader": "^6.7.1",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.1.0",
"version": "2.1.1",
"npmClient": "yarn",
"command": {
"run": {
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-integration-webview/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eclipse-glsp/vscode-integration-webview",
"version": "2.1.0",
"version": "2.2.0-next",
"description": "Integration of a GLSP diagram in a VS Code extensions (WebView part)",
"keywords": [
"vscode",
Expand Down Expand Up @@ -42,7 +42,7 @@
"watch": "tsc -w"
},
"dependencies": {
"@eclipse-glsp/client": "2.1.0",
"@eclipse-glsp/client": "next",
"vscode-messenger-webview": "^0.4.5"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import {
FeatureModule,
ICopyPasteHandler,
RequestClipboardDataAction,
SetClipboardDataAction,
TYPES,
bindAsService,
copyPasteModule
} from '@eclipse-glsp/client';
import { ExtensionActionKind } from '../default/extension-action-handler';
import { FeatureModule, ICopyPasteHandler, TYPES, bindAsService, copyPasteModule } from '@eclipse-glsp/client';
import { CopyPasteHandlerProvider, CopyPasteStartup } from './copy-paste-startup';

export const vscodeCopyPasteModule = new FeatureModule(
Expand All @@ -32,8 +23,6 @@ export const vscodeCopyPasteModule = new FeatureModule(
ctx => () => new Promise<ICopyPasteHandler>(resolve => resolve(ctx.container.get<ICopyPasteHandler>(TYPES.ICopyPasteHandler)))
);
bindAsService(bind, TYPES.IDiagramStartup, CopyPasteStartup);
bind(ExtensionActionKind).toConstantValue(RequestClipboardDataAction.KIND);
bind(ExtensionActionKind).toConstantValue(SetClipboardDataAction.KIND);
},
{ requires: copyPasteModule }
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { FeatureModule, GLSPModelSource, SelectAction, TYPES, bindAsService, defaultModule } from '@eclipse-glsp/client';
import { FeatureModule, SelectAction, TYPES, bindAsService, defaultModule } from '@eclipse-glsp/client';
import { GLSPDiagramWidget, GLSPDiagramWidgetFactory } from '../../glsp-diagram-widget';
import { ExtensionActionKind, HostExtensionActionHandler } from './extension-action-handler';
import { VsCodeGLSPModelSource } from './vscode-glsp-modelsource';

export const vscodeDefaultModule = new FeatureModule(
(bind, _unbind, _isBound, rebind) => {
bind => {
bind(GLSPDiagramWidget).toSelf().inSingletonScope();
bind(GLSPDiagramWidgetFactory).toFactory(context => () => context.container.get<GLSPDiagramWidget>(GLSPDiagramWidget));
bind(VsCodeGLSPModelSource).toSelf().inSingletonScope();
rebind(GLSPModelSource).toService(VsCodeGLSPModelSource);
bindAsService(bind, TYPES.IActionHandlerInitializer, HostExtensionActionHandler);
bind(ExtensionActionKind).toConstantValue(SelectAction.KIND);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export class HostExtensionActionHandler implements IActionHandler, IActionHandle
if (this.actionKinds.includes(action.kind)) {
const message = {
clientId: this.diagramOptions.clientId,
action,
__localDispatch: true
action
};
this.glspClient?.sendActionMessage(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Action, ActionMessage, GLSPModelSource, ServerAction } from '@eclipse-glsp/client';
/* eslint-disable deprecation/deprecation */
import { Action, GLSPModelSource } from '@eclipse-glsp/client';
import { injectable } from 'inversify';

/**
* A helper interface that allows the webview to mark actions that have been received directly from the vscode extension
* (i.e. they are not forwarded to the GLSP Server).
*
* @deprecated The concept of marking actions as locally dispatched `ExtensionAction`s is no longer necessary and usage is discouraged.
*/
export interface ExtensionAction extends Action {
__localDispatch: true;
}

export namespace ExtensionAction {
/**
* @deprecated The concept of marking actions as locally dispatched `ExtensionAction`s is no longer necessary and usage is discouraged.
* */
export function is(object: unknown): object is ExtensionAction {
return Action.is(object) && '__localDispatch' in object && object.__localDispatch === true;
}

/**
* Mark the given action as {@link ServerAction} by attaching the "_receivedFromServer" property
* @param action The action that should be marked as server action
*
* @deprecated The concept of marking actions as locally dispatched `ExtensionAction`s is no longer necessary and usage is discouraged.
*/
export function mark(action: Action): void {
(action as ExtensionAction).__localDispatch = true;
Expand All @@ -41,23 +49,8 @@ export namespace ExtensionAction {
/**
* Customization of the default {@link GLSPModelSource} for the vscode integration.
* Also takes locally dispatched actions (i.e. actions that are originating from or intended for the host extension) into consideration.
*
* @deprecated A customized model source is no longer necessary. Use the default {@link GLSPModelSource} instead.
*/
@injectable()
export class VsCodeGLSPModelSource extends GLSPModelSource {
protected override messageReceived(message: ActionMessage): void {
if (this.clientId !== message.clientId) {
return;
}
this.checkMessageOrigin(message);
const action = message.action;
this.logger.log(this, 'receiving', action);
this.actionDispatcher.dispatch(action);
}

protected checkMessageOrigin(message: ActionMessage): void {
const isLocalDispatch = (message as any)['__localDispatch'] ?? false;
if (!isLocalDispatch) {
ServerAction.mark(message.action);
}
}
}
export class VsCodeGLSPModelSource extends GLSPModelSource {}
5 changes: 2 additions & 3 deletions packages/vscode-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eclipse-glsp/vscode-integration",
"displayName": "GLSP VSCode Integration",
"version": "2.1.0",
"version": "2.2.0-next",
martin-fleck-at marked this conversation as resolved.
Show resolved Hide resolved
"description": "Glue code to integrate GLSP diagrams in VSCode extensions (extension part)",
"keywords": [
"eclipse",
Expand Down Expand Up @@ -47,13 +47,12 @@
"watch": "tsc -w"
},
"dependencies": {
"@eclipse-glsp/protocol": "2.1.0",
"@eclipse-glsp/protocol": "next",
martin-fleck-at marked this conversation as resolved.
Show resolved Hide resolved
"vscode-jsonrpc": "^8.0.2",
"vscode-messenger": "^0.4.5",
"ws": "^8.13.0"
},
"devDependencies": {
"@types/node": "^12.12.0",
"@types/vscode": "^1.54.0",
"@types/ws": "^8.5.4"
},
Expand Down
Loading