-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathworkflow-extension.ts
More file actions
129 lines (115 loc) · 5.78 KB
/
workflow-extension.ts
File metadata and controls
129 lines (115 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/********************************************************************************
* Copyright (c) 2021-2022 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import 'reflect-metadata';
import { WorkflowDiagramModule, WorkflowLayoutConfigurator, WorkflowServerModule } from '@eclipse-glsp-examples/workflow-server/node';
import { configureELKLayoutModule } from '@eclipse-glsp/layout-elk';
import { GModelStorage, LogLevel, createAppModule } from '@eclipse-glsp/server/node';
import { configureCollaborationCommands } from '@eclipse-glsp/vscode-integration/lib/collaboration';
import { LiveshareGlspClientProvider, writeExtensionPermissionsForLiveshare } from '@eclipse-glsp/vscode-integration/lib/liveshare';
import {
GlspSocketServerLauncher,
GlspVscodeConnector,
NavigateAction,
NodeGlspVscodeServer,
SocketGlspVscodeServer,
configureDefaultCommands
} from '@eclipse-glsp/vscode-integration/node';
import { ContainerModule } from 'inversify';
import * as path from 'path';
import * as process from 'process';
import * as vscode from 'vscode';
import WorkflowEditorProvider from './workflow-editor-provider';
const DEFAULT_SERVER_PORT = '0';
const NODE_EXECUTABLE = path.join(__dirname, '..', 'dist', 'wf-glsp-server-node.js');
const LOG_DIR = process.env.GLSP_LOG_DIR;
export async function activate(context: vscode.ExtensionContext): Promise<void> {
// Start server process using quickstart component
let serverProcess: GlspSocketServerLauncher | undefined;
const useIntegratedServer = JSON.parse(process.env.GLSP_INTEGRATED_SERVER ?? 'false');
if (!useIntegratedServer && process.env.GLSP_SERVER_DEBUG !== 'true') {
const additionalArgs = [];
if (LOG_DIR) {
additionalArgs.push('--fileLog', 'true', '--logDir', LOG_DIR);
}
if (process.env.GLSP_WEBSOCKET_PATH) {
additionalArgs.push('--webSocket');
}
serverProcess = new GlspSocketServerLauncher({
executable: NODE_EXECUTABLE,
socketConnectionOptions: { port: JSON.parse(process.env.GLSP_SERVER_PORT || DEFAULT_SERVER_PORT) },
additionalArgs,
logging: true
});
context.subscriptions.push(serverProcess);
await serverProcess.start();
}
writeExtensionPermissionsForLiveshare('Eclipse-GLSP');
const liveshareGlspClientProvider = new LiveshareGlspClientProvider();
// Wrap server with quickstart component
const workflowServer = useIntegratedServer
? new NodeGlspVscodeServer({
clientId: 'glsp.workflow',
clientName: 'workflow',
serverModules: createServerModules()
// collaboration: liveshareGlspClientProvider TODO implement collaboration for Node-Server
})
: new SocketGlspVscodeServer({
clientId: 'glsp.workflow',
clientName: 'workflow',
connectionOptions: {
port: serverProcess?.getPort() || JSON.parse(process.env.GLSP_SERVER_PORT || DEFAULT_SERVER_PORT),
path: process.env.GLSP_WEBSOCKET_PATH
},
collaboration: liveshareGlspClientProvider
});
// Initialize GLSP-VSCode connector with server wrapper
const glspVscodeConnector = new GlspVscodeConnector({
server: workflowServer,
logging: true
});
const customEditorProvider = vscode.window.registerCustomEditorProvider(
'workflow.glspDiagram',
new WorkflowEditorProvider(context, glspVscodeConnector),
{
webviewOptions: { retainContextWhenHidden: true },
supportsMultipleEditorsPerDocument: false
}
);
context.subscriptions.push(workflowServer, glspVscodeConnector, customEditorProvider);
workflowServer.start();
configureDefaultCommands({ extensionContext: context, connector: glspVscodeConnector, diagramPrefix: 'workflow' });
configureCollaborationCommands({ extensionContext: context, connector: glspVscodeConnector });
context.subscriptions.push(
vscode.commands.registerCommand('workflow.goToNextNode', () => {
glspVscodeConnector.dispatchAction(NavigateAction.create('next'));
}),
vscode.commands.registerCommand('workflow.goToPreviousNode', () => {
glspVscodeConnector.dispatchAction(NavigateAction.create('previous'));
}),
vscode.commands.registerCommand('workflow.showDocumentation', () => {
glspVscodeConnector.dispatchAction(NavigateAction.create('documentation'));
}),
vscode.commands.registerCommand('workflow.liveshare.init', () => {
writeExtensionPermissionsForLiveshare('Eclipse-GLSP', true);
})
);
}
function createServerModules(): ContainerModule[] {
const appModule = createAppModule({ logLevel: LogLevel.info, logDir: LOG_DIR, fileLog: true, consoleLog: false });
const elkLayoutModule = configureELKLayoutModule({ algorithms: ['layered'], layoutConfigurator: WorkflowLayoutConfigurator });
const mainModule = new WorkflowServerModule().configureDiagramModule(new WorkflowDiagramModule(() => GModelStorage), elkLayoutModule);
return [appModule, mainModule];
}