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

XIVY-13138 Change inscription lsp connection #456

Merged
merged 1 commit into from
Jan 9, 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
9 changes: 2 additions & 7 deletions integration/eclipse/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ import { IvyBaseJsonrpcGLSPClient } from '@axonivy/process-editor';
import { MessageConnection } from 'vscode-jsonrpc';

import createContainer from './di.config';
import {
EnableInscriptionAction,
EnableViewportAction,
ShowGridAction,
SwitchThemeAction,
ThemeMode
} from '@axonivy/process-editor-protocol';
import { EnableViewportAction, ShowGridAction, SwitchThemeAction, ThemeMode } from '@axonivy/process-editor-protocol';
import { MonacoUtil } from '@axonivy/inscription-core';
import { MonacoEditorUtil } from '@axonivy/inscription-editor';
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import * as reactMonaco from 'monaco-editor/esm/vs/editor/editor.api';
import './index.css';
import { EnableInscriptionAction } from '@axonivy/process-editor-inscription';

const urlParameters = getParameters();
const filePath = urlParameters.path;
Expand Down
16 changes: 1 addition & 15 deletions integration/eclipse/src/tool-bar/button.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
import { ToolBarButtonProvider, ToolBarButtonLocation } from '@axonivy/process-editor';
import { OpenDataClassAction, OpenInscriptionAction, OpenInsertExtensionAction } from '@axonivy/process-editor-protocol';
import { OpenDataClassAction, OpenInsertExtensionAction } from '@axonivy/process-editor-protocol';
import { IvyIcons } from '@axonivy/editor-icons/lib';
import { injectable } from 'inversify';

@injectable()
export class InscribeProcessButtonProvider implements ToolBarButtonProvider {
button() {
return {
icon: IvyIcons.PenEdit,
title: 'Inscribe Process',
sorting: 'D',
action: () => OpenInscriptionAction.create(''),
location: ToolBarButtonLocation.Right,
readonly: true
};
}
}

@injectable()
export class OpenDataClassButtonProvider implements ToolBarButtonProvider {
button() {
Expand Down
5 changes: 3 additions & 2 deletions integration/standalone/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import { IvyBaseJsonrpcGLSPClient, SwitchThemeActionHandler } from '@axonivy/pro
import { MessageConnection } from 'vscode-jsonrpc';
import createContainer from './di.config';
import { getParameters, getServerDomain, isReadonly, isSecureConnection } from './url-helper';
import { EnableInscriptionAction, EnableViewportAction, SwitchThemeAction, ThemeMode } from '@axonivy/process-editor-protocol';
import { EnableViewportAction, SwitchThemeAction, ThemeMode } from '@axonivy/process-editor-protocol';
import { MonacoUtil } from '@axonivy/inscription-core';
import { MonacoEditorUtil } from '@axonivy/inscription-editor';
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import * as reactMonaco from 'monaco-editor/esm/vs/editor/editor.api';
import './index.css';
import { EnableInscriptionAction } from '@axonivy/process-editor-inscription';

const parameters = getParameters();
const app = parameters.get('app') ?? 'designer';
Expand Down Expand Up @@ -65,7 +66,7 @@ async function initialize(connectionProvider: MessageConnection): Promise<void>
.then(() => {
actionDispatcher.onceModelInitialized().finally(() => {
MonacoUtil.initStandalone(editorWorker).then(() => MonacoEditorUtil.initMonaco(reactMonaco, theme));
actionDispatcher.dispatch(EnableInscriptionAction.create({ server: webSocketBase, app, pmv }));
actionDispatcher.dispatch(EnableInscriptionAction.create({ server: webSocketBase, inscriptionContext: { app, pmv } }));
if (selectElementIds) {
const elementIds = selectElementIds.split(NavigationTarget.ELEMENT_IDS_SEPARATOR);
actionDispatcher.dispatch(SelectAction.create({ selectedElementsIDs: elementIds }));
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"bpmn"
],
"dependencies": {
"@axonivy/editor-icons": "~11.3.0-next.837",
"@axonivy/editor-icons": "~11.3.0-next.925",
"@axonivy/process-editor-protocol": "11.3.0-next",
"@eclipse-glsp/client": "1.1.0-RC10",
"showdown": "^2.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/open-inscription/quick-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isOpenable, SModelElement } from '@eclipse-glsp/client';
import { injectable } from 'inversify';
import { IvyIcons } from '@axonivy/editor-icons/lib';
import { QuickAction, SingleQuickActionProvider } from '../ui-tools/quick-action/quick-action';
import { OpenInscriptionAction } from '@axonivy/process-editor-protocol';
import { OpenSwtInscriptionAction } from '@axonivy/process-editor-protocol';

@injectable()
export class InscribeQuickActionProvider extends SingleQuickActionProvider {
Expand All @@ -13,7 +13,7 @@ export class InscribeQuickActionProvider extends SingleQuickActionProvider {
title: 'Edit (E)',
location: 'Left',
sorting: 'B',
action: OpenInscriptionAction.create(element.id),
action: OpenSwtInscriptionAction.create(element.id),
readonlySupport: true,
shortcut: 'KeyE'
};
Expand Down
6 changes: 3 additions & 3 deletions packages/inscription/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"url": "https://github.com/axonivy/glsp-editor-client"
},
"dependencies": {
"@axonivy/inscription-core": "~11.3.0-next.837",
"@axonivy/inscription-editor": "~11.3.0-next.837",
"@axonivy/inscription-protocol": "~11.3.0-next.837",
"@axonivy/inscription-core": "~11.3.0-next.925",
"@axonivy/inscription-editor": "~11.3.0-next.925",
"@axonivy/inscription-protocol": "~11.3.0-next.925",
"@axonivy/process-editor": "11.3.0-next",
"@eclipse-glsp/client": "1.1.0-RC10",
"react": "^18.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/inscription/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as ivyInscriptionModule } from './inscription/di.config';
export * from './inscription/action';
37 changes: 37 additions & 0 deletions packages/inscription/src/inscription/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Action } from '@eclipse-glsp/client';
import { InscriptionContext } from '@axonivy/inscription-protocol';

export interface EnableInscriptionAction extends Action {
kind: typeof EnableInscriptionAction.KIND;
server?: string;
inscriptionContext?: InscriptionContext;
}

export namespace EnableInscriptionAction {
export const KIND = 'enableInscription';

export function is(object: any): object is EnableInscriptionAction {
return Action.hasKind(object, KIND);
}

export function create(options: { server?: string; inscriptionContext?: InscriptionContext }): EnableInscriptionAction {
return { kind: KIND, ...options };
}
}

export interface ToggleInscriptionAction extends Action {
kind: typeof ToggleInscriptionAction.KIND;
force?: boolean;
}

export namespace ToggleInscriptionAction {
export const KIND = 'showInscription';

export function is(object: any): object is ToggleInscriptionAction {
return Action.hasKind(object, KIND);
}

export function create(options: { force?: boolean }): ToggleInscriptionAction {
return { kind: KIND, ...options };
}
}
3 changes: 2 additions & 1 deletion packages/inscription/src/inscription/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import './inscription-ui.css';
import { ContainerModule } from 'inversify';
import { InscriptionUi } from './inscription-ui';
import { TYPES, configureActionHandler } from '@eclipse-glsp/client';
import { EnableInscriptionAction, SwitchThemeAction, ToggleInscriptionAction } from '@axonivy/process-editor-protocol';
import { SwitchThemeAction } from '@axonivy/process-editor-protocol';
import { OpenAction } from 'sprotty-protocol';
import { OpenInscriptionKeyListener, OpenInscriptionMouseListener } from './open-inscription-listener';
import { InscriptionButtonProvider } from './tool-bar';
import { IVY_TYPES } from '@axonivy/process-editor';
import { EnableInscriptionAction, ToggleInscriptionAction } from './action';

const ivyInscriptionModule = new ContainerModule((bind, _unbind, isBound) => {
bind(InscriptionUi).toSelf().inSingletonScope();
Expand Down
31 changes: 18 additions & 13 deletions packages/inscription/src/inscription/inscription-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import React from 'react';
import InscriptionView from './InscriptionView';
import { ClientContextProvider, MonacoEditorUtil, ThemeContextProvider, initQueryClient } from '@axonivy/inscription-editor';
import * as reactMonaco from 'monaco-editor/esm/vs/editor/editor.api';
import { InscriptionClient } from '@axonivy/inscription-protocol';
import { InscriptionClient, InscriptionContext } from '@axonivy/inscription-protocol';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { InscriptionClientJsonRpc, IvyScriptLanguage, MonacoUtil } from '@axonivy/inscription-core';
import { SwitchThemeActionHandler } from '@axonivy/process-editor';
import { EnableInscriptionAction, SwitchThemeAction, ToggleInscriptionAction } from '@axonivy/process-editor-protocol';
import { SwitchThemeAction } from '@axonivy/process-editor-protocol';
import { EnableInscriptionAction, ToggleInscriptionAction } from './action';

const JSX = { createElement: React.createElement };

Expand All @@ -38,9 +39,7 @@ export class InscriptionUi extends AbstractUIExtension implements IActionHandler

private inscriptionElement?: string;
private action?: EnableInscriptionAction;
private app: string;
private pmv: string;
private webSocketAddress: string;
private inscriptionContext: InscriptionContext;
private root: Root;
private inscriptionClient?: Promise<InscriptionClient>;
private queryClient: QueryClient;
Expand Down Expand Up @@ -73,9 +72,8 @@ export class InscriptionUi extends AbstractUIExtension implements IActionHandler
}

protected initializeContents(containerElement: HTMLElement) {
this.initConnection();
this.changeUiVisiblitiy(false);
IvyScriptLanguage.startWebSocketClient(this.webSocketAddress + 'ivy-script-lsp');
this.inscriptionContext = this.initInscriptionContext();
this.queryClient = initQueryClient();
this.inscriptionClient = this.startInscriptionClient();
this.root = createRoot(containerElement);
Expand All @@ -92,7 +90,7 @@ export class InscriptionUi extends AbstractUIExtension implements IActionHandler
<ThemeContextProvider theme={this.switchThemeHandler?.theme() ?? 'light'}>
<ClientContextProvider client={client}>
<QueryClientProvider client={this.queryClient}>
<InscriptionView app={this.app} pmv={this.pmv} pid={element} />
<InscriptionView app={this.inscriptionContext.app} pmv={this.inscriptionContext.pmv} pid={element} />
</QueryClientProvider>
</ClientContextProvider>
</ThemeContextProvider>
Expand All @@ -102,7 +100,10 @@ export class InscriptionUi extends AbstractUIExtension implements IActionHandler
}

async startInscriptionClient() {
const client = await InscriptionClientJsonRpc.startWebSocketClient(this.webSocketAddress + 'ivy-inscription-lsp');
const model = this.editorContext.modelRoot;
const webSocketAddress = this.action?.server ?? GArgument.getString(model, 'webSocket') ?? 'ws://localhost:8081/';
await IvyScriptLanguage.startWebSocketClient(webSocketAddress);
const client = await InscriptionClientJsonRpc.startWebSocketClient(webSocketAddress);
await client.initialize();
return client;
}
Expand Down Expand Up @@ -131,11 +132,15 @@ export class InscriptionUi extends AbstractUIExtension implements IActionHandler
return;
}

private initConnection() {
private initInscriptionContext() {
const model = this.editorContext.modelRoot;
this.app = this.action?.app ?? GArgument.getString(model, 'app') ?? 'designer';
this.pmv = this.action?.pmv ?? GArgument.getString(model, 'pmv') ?? '';
this.webSocketAddress = this.action?.server ?? GArgument.getString(model, 'webSocket') ?? 'ws://localhost:8081/';
if (this.action?.inscriptionContext) {
return this.action.inscriptionContext;
}
return {
app: GArgument.getString(model, 'app') ?? 'designer',
pmv: GArgument.getString(model, 'pmv') ?? ''
};
}

private changeUiVisiblitiy(force?: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion packages/inscription/src/inscription/tool-bar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ToolBarButtonLocation, ToolBarButtonProvider } from '@axonivy/process-editor';
import { ToggleInscriptionAction } from '@axonivy/process-editor-protocol';
import { IvyIcons } from '@axonivy/editor-icons/lib';
import { injectable } from 'inversify';
import { ToggleInscriptionAction } from './action';

@injectable()
export class InscriptionButtonProvider implements ToolBarButtonProvider {
Expand Down
46 changes: 5 additions & 41 deletions packages/protocol/src/action/inscription.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
import { Action, hasStringProp } from '@eclipse-glsp/protocol';

export interface OpenInscriptionAction extends Action {
kind: typeof OpenInscriptionAction.KIND;
export interface OpenSwtInscriptionAction extends Action {
kind: typeof OpenSwtInscriptionAction.KIND;
elementId: string;
}

export namespace OpenInscriptionAction {
export namespace OpenSwtInscriptionAction {
export const KIND = 'openInscription';

export function is(object: any): object is OpenInscriptionAction {
export function is(object: any): object is OpenSwtInscriptionAction {
return Action.hasKind(object, KIND) && hasStringProp(object, 'elementId');
}

export function create(elementId: string): OpenInscriptionAction {
export function create(elementId: string): OpenSwtInscriptionAction {
return {
kind: KIND,
elementId
};
}
}

export interface EnableInscriptionAction extends Action {
kind: typeof EnableInscriptionAction.KIND;
server?: string;
app?: string;
pmv?: string;
}

export namespace EnableInscriptionAction {
export const KIND = 'enableInscription';

export function is(object: any): object is EnableInscriptionAction {
return Action.hasKind(object, KIND);
}

export function create(options: { server?: string; app?: string; pmv?: string }): EnableInscriptionAction {
return { kind: KIND, ...options };
}
}

export interface ToggleInscriptionAction extends Action {
kind: typeof ToggleInscriptionAction.KIND;
force?: boolean;
}

export namespace ToggleInscriptionAction {
export const KIND = 'showInscription';

export function is(object: any): object is ToggleInscriptionAction {
return Action.hasKind(object, KIND);
}

export function create(options: { force?: boolean }): ToggleInscriptionAction {
return { kind: KIND, ...options };
}
}
Loading