From dff82923dd8e01a10c387ba33a256ba602cd286c Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Wed, 11 Sep 2019 08:42:31 +0000 Subject: [PATCH] [plugin] fix #6160: decorate vscode-ws-jsonrpc to be es5 compatible otherwise es5 plugin reader and writers cannot extend them Signed-off-by: Anton Kosyakov --- .theia/settings.json | 2 +- .../plugin-ext/src/common/plugin-message-reader.ts | 3 ++- .../plugin-ext/src/common/plugin-message-writer.ts | 3 ++- packages/plugin-ext/src/common/types.ts | 12 ++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.theia/settings.json b/.theia/settings.json index a911f5e896bc2..c2dbbd51b3c27 100644 --- a/.theia/settings.json +++ b/.theia/settings.json @@ -12,4 +12,4 @@ }, "typescript.tsdk": "node_modules/typescript/lib", "clang-format.language.typescript.enable": false -} +} \ No newline at end of file diff --git a/packages/plugin-ext/src/common/plugin-message-reader.ts b/packages/plugin-ext/src/common/plugin-message-reader.ts index 0bbb454b1f511..c7060cd02514c 100644 --- a/packages/plugin-ext/src/common/plugin-message-reader.ts +++ b/packages/plugin-ext/src/common/plugin-message-reader.ts @@ -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 diff --git a/packages/plugin-ext/src/common/plugin-message-writer.ts b/packages/plugin-ext/src/common/plugin-message-writer.ts index 997e112ec6888..781caabc850ec 100644 --- a/packages/plugin-ext/src/common/plugin-message-writer.ts +++ b/packages/plugin-ext/src/common/plugin-message-writer.ts @@ -14,6 +14,7 @@ * 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'; @@ -21,7 +22,7 @@ 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) { diff --git a/packages/plugin-ext/src/common/types.ts b/packages/plugin-ext/src/common/types.ts index 6714dc721c5ce..d902cfaad592c 100644 --- a/packages/plugin-ext/src/common/types.ts +++ b/packages/plugin-ext/src/common/types.ts @@ -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(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