Skip to content

Commit

Permalink
[plugin] fix #6160: decorate vscode-ws-jsonrpc to be es5 compatible
Browse files Browse the repository at this point in the history
otherwise es5 plugin reader and writers cannot extend them

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Sep 12, 2019
1 parent 98f12a9 commit dff8292
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .theia/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
},
"typescript.tsdk": "node_modules/typescript/lib",
"clang-format.language.typescript.enable": false
}
}
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/common/plugin-message-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { es5ClassCompat } from './types';
import { AbstractMessageReader, DataCallback } from 'vscode-jsonrpc/lib/messageReader';

/**
* Support for reading string message through RPC protocol.
*/
export class PluginMessageReader extends AbstractMessageReader {
export class PluginMessageReader extends es5ClassCompat(AbstractMessageReader) {
protected state: 'initial' | 'listening' | 'closed' = 'initial';
protected callback: DataCallback | undefined;
// tslint:disable-next-line:no-any
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/common/plugin-message-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { es5ClassCompat } from './types';
import { AbstractMessageWriter, MessageWriter } from 'vscode-jsonrpc/lib/messageWriter';
import { ConnectionMain, ConnectionExt } from './plugin-api-rpc';
import { Message } from 'vscode-jsonrpc';

/**
* Support for writing string message through RPC protocol.
*/
export class PluginMessageWriter extends AbstractMessageWriter implements MessageWriter {
export class PluginMessageWriter extends es5ClassCompat(AbstractMessageWriter) implements MessageWriter {
constructor(
protected readonly id: string,
protected readonly proxy: ConnectionMain | ConnectionExt) {
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-ext/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ export interface LogPart {
// tslint:disable-next-line:no-any
export interface KeysToAnyValues { [key: string]: any }
export interface KeysToKeysToAnyValue { [key: string]: KeysToAnyValues }

// tslint:disable:no-any
/** copied from https://github.com/TypeFox/vscode/blob/70b8db24a37fafc77247de7f7cb5bb0195120ed0/src/vs/workbench/api/common/extHostTypes.ts#L18-L27 */
export function es5ClassCompat<T extends Function>(target: T): T {
/// @ts-ignore
function _(): any { return Reflect.construct(target, arguments, this.constructor); }
Object.defineProperty(_, 'name', Object.getOwnPropertyDescriptor(target, 'name')!);
Object.setPrototypeOf(_, target);
Object.setPrototypeOf(_.prototype, target.prototype);
return _ as unknown as T;
}
// tslint:enable:no-any

0 comments on commit dff8292

Please sign in to comment.