Skip to content

Commit

Permalink
#379#406 Consume protocol-update & DI rework
Browse files Browse the repository at this point in the history
- Update glsp dependencies  to latest next version
- Remove action definitions that are now provided by @eclipse-glsp/protocol
- Adapt code base to conform to new base protocol
- Update webpack config for codicons (eclipse-glsp/glsp/issues/406)

Fixes eclipse-glsp/glsp/issues/379
  • Loading branch information
tortmayr committed Nov 1, 2021
1 parent 11de3de commit 0757d60
Show file tree
Hide file tree
Showing 24 changed files with 809 additions and 903 deletions.
13 changes: 11 additions & 2 deletions example/workflow/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@
"server",
"webview"
],
"main": "./lib/workflow-extension",
"dependencies": {
"@vscode/codicons": "^0.0.25"
},
"main": "./lib/index",
"devDependencies": {
"@eclipse-glsp/vscode-integration": "0.9.0",
"@types/node": "^8.0.0",
"reflect-metadata": "^0.1.13",
"path": "^0.12.7",
"rimraf": "^2.6.3",
"ts-loader": "^6.2.1",
Expand All @@ -195,5 +198,11 @@
"build": "tsc && yarn download:Server",
"publish": "vsce publish",
"download:Server": "ts-node ../scripts/download.ts"
},
"workspaces": {
"nohoist": [
"**/@vscode/codicons",
"**/@vscode/codicons/**"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
export * from './action';
export * from './export';
export * from './external-navigation';
export * from './markers';
export * from './navigation';
export * from './operation';
export * from './save-state';
export * from './selection';
import 'reflect-metadata';
import * as vscode from 'vscode';
import { activate as extensionActivate } from './workflow-extension';

export function activate(context: vscode.ExtensionContext): Promise<void> {
return extensionActivate(context);
}
22 changes: 12 additions & 10 deletions example/workflow/extension/src/workflow-editor-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
********************************************************************************/
import { GlspVscodeConnector } from '@eclipse-glsp/vscode-integration';
import { GlspEditorProvider } from '@eclipse-glsp/vscode-integration/lib/quickstart-components';
import * as path from 'path';
import * as vscode from 'vscode';

export default class WorkflowEditorProvider extends GlspEditorProvider {
Expand All @@ -31,12 +30,14 @@ export default class WorkflowEditorProvider extends GlspEditorProvider {
_token: vscode.CancellationToken,
clientId: string
): void {
const localResourceRootsUri = vscode.Uri.file(path.join(this.extensionContext.extensionPath, './pack'));

const webviewScriptSourceUri = vscode.Uri.file(path.join(this.extensionContext.extensionPath, './pack/webview.js'));
const webview = webviewPanel.webview;
const extensionUri = this.extensionContext.extensionUri;
const webviewScriptSourceUri = webview.asWebviewUri(vscode.Uri.joinPath(extensionUri, 'pack', 'webview.js'));
const codiconsUri = webview.asWebviewUri(
vscode.Uri.joinPath(extensionUri, 'node_modules', '@vscode/codicons', 'dist', 'codicon.css')
);

webviewPanel.webview.options = {
localResourceRoots: [localResourceRootsUri],
enableScripts: true
};

Expand All @@ -46,14 +47,15 @@ export default class WorkflowEditorProvider extends GlspEditorProvider {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, height=device-height">
<link
rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/"
crossorigin="anonymous">
<meta http-equiv="Content-Security-Policy" content="
default-src http://*.fontawesome.com ${webview.cspSource} 'unsafe-inline' 'unsafe-eval';
">
<link href="${codiconsUri}" rel="stylesheet" />
</head>
<body>
<div id="${clientId}_container" style="height: 100%;"></div>
<script src="${webviewPanel.webview.asWebviewUri(webviewScriptSourceUri).toString()}"></script>
<script src="${webviewScriptSourceUri}"></script>
</body>
</html>`;
}
Expand Down
1 change: 1 addition & 0 deletions example/workflow/extension/src/workflow-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { GlspServerLauncher, SocketGlspVscodeServer } from '@eclipse-glsp/vscode-integration/lib/quickstart-components';
import * as path from 'path';
import * as process from 'process';
import 'reflect-metadata';
import * as vscode from 'vscode';
import WorkflowEditorProvider from './workflow-editor-provider';

Expand Down
20 changes: 12 additions & 8 deletions example/workflow/webview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@
},
"contributors": [
{
"name": "Tobias Ortmayr",
"email": "tortmayr@eclipsesource.com",
"url": "https://www.eclipsesource.com"
"name": "Eclipse GLSP Project",
"email": "glsp-dev@eclipse.org",
"url": "https://projects.eclipse.org/projects/ecd.glsp"
}
],
"dependencies": {
"@eclipse-glsp/vscode-integration-webview": "0.9.0",
"@eclipse-glsp-examples/workflow-glsp": "next"
},
"devDependencies": {
"circular-dependency-plugin": "^5.0.2",
"circular-dependency-plugin": "^5.2.2",
"css-loader": "^2.1.0",
"reflect-metadata": "^0.1.13",
"rimraf": "latest",
"source-map-loader": "^1.0.2",
"style-loader": "^0.23.1",
"typescript": "latest",
"webpack": "^4.28.1",
"webpack-cli": "^3.2.1",
"style-loader": "^2.0.0",
"ts-loader": "^8.1.0",
"ignore-loader":"^0.1.2",
"@vscode/codicons": "^0.0.25",
"typescript": "^3.9.2",
"webpack": "^4.46.0",
"webpack-cli": "^4.9.1",
"yargs": "^12.0.5"
},
"scripts": {
Expand Down
14 changes: 11 additions & 3 deletions example/workflow/webview/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const config = {
filename: 'webview.js',
path: outputPath
},
devtool: 'eval-source-map',
devtool: 'source-map-eval',
mode: 'development',

resolve: {
extensions: ['.ts', '.tsx', '.js']
Expand All @@ -30,12 +31,19 @@ const config = {
},
{
test: /\.css$/,
exclude: /\.useable\.css$/,
exclude: /(codicon|\.useable)\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /codicon.css$/,
use: ['ignore-loader']
}
]
},
node: { fs: 'empty', net: 'empty' }
node: { fs: 'empty', net: 'empty' },
stats: {
warningsFilter: [/Failed to parse source map/]
}
};

module.exports = config;
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
"lint": "lerna run lint --",
"publish:latest": "lerna publish",
"publish:next": "lerna publish --exact --canary=next --npm-tag=next --yes",
"upgrade:next": "yarn upgrade -p \"@eclipse-glsp.*\" --next",
"upgrade:next": "yarn upgrade -p \"@eclipse-glsp.*|sprotty\" --next",
"build:ci": "lerna run build:ci"
},
"devDependencies": {
"@eclipse-glsp/config": "next",
"@types/vscode": "^1.54.0",
"@eclipse-glsp/config": "0.9.0-next.a3910f6a",
"rimraf": "^2.6.3",
"lerna": "^2.2.0",
"mvn-artifact-download": "5.1.0",
"rimraf": "^2.6.3",
"typescript": "^3.9.7"
},
"resolutions": {
"**/sprotty": "0.10.0-next.0e06051"
"**/sprotty": "0.11.0-next.ef11ae9"
},
"workspaces": [
"packages/*/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,24 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
/* eslint-disable no-null/no-null */
import { InitializeResult } from '@eclipse-glsp/client';
import { isString } from '@eclipse-glsp/protocol';

export interface Action {
readonly kind: string;
}
export const GLSPDiagramIdentifier = Symbol('GLSPDiagramIdentifier');

export interface ActionMessage<A extends Action = Action> {
export interface GLSPDiagramIdentifier {
clientId: string;
action: A;
}

export function isAction(object: any): object is Action {
return typeof object === 'object' && object !== null && 'kind' in object && typeof object['kind'] === 'string';
diagramType: string;
uri: string;
initializeResult?: InitializeResult;
}

export function isActionMessage(object: any): object is ActionMessage {
export function isDiagramIdentifier(object: any): object is GLSPDiagramIdentifier {
return (
object !== undefined &&
typeof object === 'object' &&
object !== null &&
'clientId' in object &&
typeof object['clientId'] === 'string' &&
'action' in object &&
isAction(object.action)
isString(object, 'clientId') &&
isString(object, 'diagramType') &&
isString(object, 'uri')
);
}
43 changes: 40 additions & 3 deletions packages/vscode-integration-webview/src/glsp-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { DiagramServer, ExportSvgAction, NavigateToExternalTargetAction, SelectAction, TYPES } from '@eclipse-glsp/client';
import { RequestClipboardDataAction, SetClipboardDataAction } from '@eclipse-glsp/client/lib/features/copy-paste/copy-paste-actions';
import {
configureServerActions,
DiagramServer,
ExportSvgAction,
NavigateToExternalTargetAction,
RequestClipboardDataAction,
SelectAction,
SetClipboardDataAction,
TYPES
} from '@eclipse-glsp/client';
import { Container } from 'inversify';
import {
SprottyDiagramIdentifier,
Expand All @@ -23,17 +31,46 @@ import {
VscodeDiagramWidget,
VscodeDiagramWidgetFactory
} from 'sprotty-vscode-webview';
import { GLSPDiagramIdentifier, isDiagramIdentifier } from './diagram-identifer';
import { GLSPVscodeExtensionActionHandler } from './extension-action-handler';
import { GLSPVscodeDiagramWidget } from './glsp-vscode-diagram-widget';
import { GLSPVscodeDiagramServer } from './glsp-vscode-diagramserver';

export abstract class GLSPStarter extends SprottyStarter {
protected addVscodeBindings(container: Container, diagramIdentifier: SprottyDiagramIdentifier): void {
protected acceptDiagramIdentifier(): void {
console.log('Waiting for diagram identifier...');
const eventListener = (message: any): void => {
if (isDiagramIdentifier(message.data)) {
console.log(message);
if (this.container) {
const oldIdentifier = this.container.get<GLSPDiagramIdentifier>(GLSPDiagramIdentifier);
const newIdentifier = message.data as GLSPDiagramIdentifier;
oldIdentifier.diagramType = newIdentifier.diagramType;
oldIdentifier.uri = newIdentifier.uri;
const diagramWidget = this.container.get(VscodeDiagramWidget);
diagramWidget.requestModel();
} else {
console.log('...received...', message);
const diagramIdentifier = message.data as GLSPDiagramIdentifier;
this.container = this.createContainer(diagramIdentifier);
this.addVscodeBindings(this.container, diagramIdentifier);
if (diagramIdentifier.initializeResult) {
configureServerActions(diagramIdentifier.initializeResult, diagramIdentifier.diagramType, this.container);
}
this.container.get(VscodeDiagramWidget);
}
}
};
window.addEventListener('message', eventListener);
}

protected addVscodeBindings(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void {
container.bind(GLSPVscodeDiagramWidget).toSelf().inSingletonScope();
container.bind(VscodeDiagramWidget).toService(GLSPVscodeDiagramWidget);
container
.bind(VscodeDiagramWidgetFactory)
.toFactory(context => () => context.container.get<GLSPVscodeDiagramWidget>(GLSPVscodeDiagramWidget));
container.bind(GLSPDiagramIdentifier).toConstantValue(diagramIdentifier);
container.bind(SprottyDiagramIdentifier).toConstantValue(diagramIdentifier);
container.bind(GLSPVscodeDiagramServer).toSelf().inSingletonScope();
container.bind(VscodeDiagramServer).toService(GLSPVscodeDiagramServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import {
DiagramServer,
EnableToolPaletteAction,
InitializeClientSessionAction,
RequestModelAction,
RequestTypeHintsAction
} from '@eclipse-glsp/client';
import { DiagramServer, EnableToolPaletteAction, RequestModelAction, RequestTypeHintsAction } from '@eclipse-glsp/client';
import { injectable } from 'inversify';
import { VscodeDiagramWidget } from 'sprotty-vscode-webview';

Expand All @@ -29,7 +23,6 @@ export abstract class GLSPVscodeDiagramWidget extends VscodeDiagramWidget {
if (this.modelSource instanceof DiagramServer) {
this.modelSource.clientId = this.diagramIdentifier.clientId;
}
this.actionDispatcher.dispatch(new InitializeClientSessionAction(this.diagramIdentifier.clientId));
this.actionDispatcher.dispatch(
new RequestModelAction({
sourceUri: decodeURI(this.diagramIdentifier.uri),
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"vscode-jsonrpc": "^4.0.0"
},
"devDependencies": {
"@types/node": "^8.0.0",
"@types/node": "^12.12.0",
"rimraf": "^2.6.3",
"typescript": "^3.9.7",
"vscode": "^1.1.37"
Expand Down
39 changes: 0 additions & 39 deletions packages/vscode-integration/src/actions/external-navigation.ts

This file was deleted.

Loading

0 comments on commit 0757d60

Please sign in to comment.