From bef346d62b4a1bca74b6c60062df80dbb0bfaa11 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 13 Dec 2017 16:21:27 +0100 Subject: [PATCH] Have the marshalling kind be a property of the proxy identifier (#36972) --- src/vs/workbench/api/node/extHost.protocol.ts | 101 +++++++++--------- .../extensions/node/proxyIdentifier.ts | 38 +++---- .../services/extensions/node/rpcProtocol.ts | 9 +- .../api/extHostDocumentsAndEditors.test.ts | 1 - .../electron-browser/api/testThreadService.ts | 12 --- 5 files changed, 72 insertions(+), 89 deletions(-) diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 29e54453820..1385a5226ea 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -8,7 +8,8 @@ import { createMainContextProxyIdentifier as createMainId, createExtHostContextProxyIdentifier as createExtId, ProxyIdentifier, - IRPCProtocol + IRPCProtocol, + ProxyType } from 'vs/workbench/services/extensions/node/proxyIdentifier'; import * as vscode from 'vscode'; @@ -664,56 +665,56 @@ export interface ExtHostWindowShape { // --- proxy identifiers export const MainContext = { - MainThreadCommands: >createMainId('MainThreadCommands'), - MainThreadConfiguration: createMainId('MainThreadConfiguration'), - MainThreadDebugService: createMainId('MainThreadDebugService'), - MainThreadDecorations: createMainId('MainThreadDecorations'), - MainThreadDiagnostics: createMainId('MainThreadDiagnostics'), - MainThreadDialogs: createMainId('MainThreadDiaglogs'), - MainThreadDocuments: createMainId('MainThreadDocuments'), - MainThreadDocumentContentProviders: createMainId('MainThreadDocumentContentProviders'), - MainThreadEditors: createMainId('MainThreadEditors'), - MainThreadErrors: createMainId('MainThreadErrors'), - MainThreadTreeViews: createMainId('MainThreadTreeViews'), - MainThreadLanguageFeatures: createMainId('MainThreadLanguageFeatures'), - MainThreadLanguages: createMainId('MainThreadLanguages'), - MainThreadMessageService: createMainId('MainThreadMessageService'), - MainThreadOutputService: createMainId('MainThreadOutputService'), - MainThreadProgress: createMainId('MainThreadProgress'), - MainThreadQuickOpen: createMainId('MainThreadQuickOpen'), - MainThreadStatusBar: createMainId('MainThreadStatusBar'), - MainThreadStorage: createMainId('MainThreadStorage'), - MainThreadTelemetry: createMainId('MainThreadTelemetry'), - MainThreadTerminalService: createMainId('MainThreadTerminalService'), - MainThreadWorkspace: createMainId('MainThreadWorkspace'), - MainThreadFileSystem: createMainId('MainThreadFileSystem'), - MainThreadExtensionService: createMainId('MainThreadExtensionService'), - MainThreadSCM: createMainId('MainThreadSCM'), - MainThreadTask: createMainId('MainThreadTask'), - MainThreadWindow: createMainId('MainThreadWindow'), + MainThreadCommands: >createMainId('MainThreadCommands', ProxyType.CustomMarshaller), + MainThreadConfiguration: createMainId('MainThreadConfiguration', ProxyType.CustomMarshaller), + MainThreadDebugService: createMainId('MainThreadDebugService', ProxyType.CustomMarshaller), + MainThreadDecorations: createMainId('MainThreadDecorations', ProxyType.CustomMarshaller), + MainThreadDiagnostics: createMainId('MainThreadDiagnostics', ProxyType.CustomMarshaller), + MainThreadDialogs: createMainId('MainThreadDiaglogs', ProxyType.CustomMarshaller), + MainThreadDocuments: createMainId('MainThreadDocuments', ProxyType.CustomMarshaller), + MainThreadDocumentContentProviders: createMainId('MainThreadDocumentContentProviders', ProxyType.CustomMarshaller), + MainThreadEditors: createMainId('MainThreadEditors', ProxyType.CustomMarshaller), + MainThreadErrors: createMainId('MainThreadErrors', ProxyType.CustomMarshaller), + MainThreadTreeViews: createMainId('MainThreadTreeViews', ProxyType.CustomMarshaller), + MainThreadLanguageFeatures: createMainId('MainThreadLanguageFeatures', ProxyType.CustomMarshaller), + MainThreadLanguages: createMainId('MainThreadLanguages', ProxyType.CustomMarshaller), + MainThreadMessageService: createMainId('MainThreadMessageService', ProxyType.CustomMarshaller), + MainThreadOutputService: createMainId('MainThreadOutputService', ProxyType.CustomMarshaller), + MainThreadProgress: createMainId('MainThreadProgress', ProxyType.CustomMarshaller), + MainThreadQuickOpen: createMainId('MainThreadQuickOpen', ProxyType.CustomMarshaller), + MainThreadStatusBar: createMainId('MainThreadStatusBar', ProxyType.CustomMarshaller), + MainThreadStorage: createMainId('MainThreadStorage', ProxyType.CustomMarshaller), + MainThreadTelemetry: createMainId('MainThreadTelemetry', ProxyType.CustomMarshaller), + MainThreadTerminalService: createMainId('MainThreadTerminalService', ProxyType.CustomMarshaller), + MainThreadWorkspace: createMainId('MainThreadWorkspace', ProxyType.CustomMarshaller), + MainThreadFileSystem: createMainId('MainThreadFileSystem', ProxyType.CustomMarshaller), + MainThreadExtensionService: createMainId('MainThreadExtensionService', ProxyType.CustomMarshaller), + MainThreadSCM: createMainId('MainThreadSCM', ProxyType.CustomMarshaller), + MainThreadTask: createMainId('MainThreadTask', ProxyType.CustomMarshaller), + MainThreadWindow: createMainId('MainThreadWindow', ProxyType.CustomMarshaller), }; export const ExtHostContext = { - ExtHostCommands: createExtId('ExtHostCommands'), - ExtHostConfiguration: createExtId('ExtHostConfiguration'), - ExtHostDiagnostics: createExtId('ExtHostDiagnostics'), - ExtHostDebugService: createExtId('ExtHostDebugService'), - ExtHostDecorations: createExtId('ExtHostDecorations'), - ExtHostDocumentsAndEditors: createExtId('ExtHostDocumentsAndEditors'), - ExtHostDocuments: createExtId('ExtHostDocuments'), - ExtHostDocumentContentProviders: createExtId('ExtHostDocumentContentProviders'), - ExtHostDocumentSaveParticipant: createExtId('ExtHostDocumentSaveParticipant'), - ExtHostEditors: createExtId('ExtHostEditors'), - ExtHostTreeViews: createExtId('ExtHostTreeViews'), - ExtHostFileSystem: createExtId('ExtHostFileSystem'), - ExtHostFileSystemEventService: createExtId('ExtHostFileSystemEventService'), - ExtHostHeapService: createExtId('ExtHostHeapMonitor'), - ExtHostLanguageFeatures: createExtId('ExtHostLanguageFeatures'), - ExtHostQuickOpen: createExtId('ExtHostQuickOpen'), - ExtHostExtensionService: createExtId('ExtHostExtensionService'), - ExtHostTerminalService: createExtId('ExtHostTerminalService'), - ExtHostSCM: createExtId('ExtHostSCM'), - ExtHostTask: createExtId('ExtHostTask'), - ExtHostWorkspace: createExtId('ExtHostWorkspace'), - ExtHostWindow: createExtId('ExtHostWindow'), + ExtHostCommands: createExtId('ExtHostCommands', ProxyType.CustomMarshaller), + ExtHostConfiguration: createExtId('ExtHostConfiguration', ProxyType.CustomMarshaller), + ExtHostDiagnostics: createExtId('ExtHostDiagnostics', ProxyType.CustomMarshaller), + ExtHostDebugService: createExtId('ExtHostDebugService', ProxyType.CustomMarshaller), + ExtHostDecorations: createExtId('ExtHostDecorations', ProxyType.CustomMarshaller), + ExtHostDocumentsAndEditors: createExtId('ExtHostDocumentsAndEditors', ProxyType.CustomMarshaller), + ExtHostDocuments: createExtId('ExtHostDocuments', ProxyType.CustomMarshaller), + ExtHostDocumentContentProviders: createExtId('ExtHostDocumentContentProviders', ProxyType.CustomMarshaller), + ExtHostDocumentSaveParticipant: createExtId('ExtHostDocumentSaveParticipant', ProxyType.CustomMarshaller), + ExtHostEditors: createExtId('ExtHostEditors', ProxyType.CustomMarshaller), + ExtHostTreeViews: createExtId('ExtHostTreeViews', ProxyType.CustomMarshaller), + ExtHostFileSystem: createExtId('ExtHostFileSystem', ProxyType.CustomMarshaller), + ExtHostFileSystemEventService: createExtId('ExtHostFileSystemEventService', ProxyType.CustomMarshaller), + ExtHostHeapService: createExtId('ExtHostHeapMonitor', ProxyType.CustomMarshaller), + ExtHostLanguageFeatures: createExtId('ExtHostLanguageFeatures', ProxyType.CustomMarshaller), + ExtHostQuickOpen: createExtId('ExtHostQuickOpen', ProxyType.CustomMarshaller), + ExtHostExtensionService: createExtId('ExtHostExtensionService', ProxyType.CustomMarshaller), + ExtHostTerminalService: createExtId('ExtHostTerminalService', ProxyType.CustomMarshaller), + ExtHostSCM: createExtId('ExtHostSCM', ProxyType.CustomMarshaller), + ExtHostTask: createExtId('ExtHostTask', ProxyType.CustomMarshaller), + ExtHostWorkspace: createExtId('ExtHostWorkspace', ProxyType.CustomMarshaller), + ExtHostWindow: createExtId('ExtHostWindow', ProxyType.CustomMarshaller), }; diff --git a/src/vs/workbench/services/extensions/node/proxyIdentifier.ts b/src/vs/workbench/services/extensions/node/proxyIdentifier.ts index 44ccdc882b6..5d2c7484abd 100644 --- a/src/vs/workbench/services/extensions/node/proxyIdentifier.ts +++ b/src/vs/workbench/services/extensions/node/proxyIdentifier.ts @@ -6,20 +6,10 @@ export interface IRPCProtocol { /** - * Returns a proxy to an object addressable/named in the extension host process. - * > **Note:** Arguments or results of type `URI` or `RegExp` will be serialized/deserialized automatically, - * > but this has a performance cost, as each argument/result must be visited. - * > - * > Use `getFast` for a proxy where such arguments are not automatically serialized/deserialized. + * Returns a proxy to an object addressable/named in the extension host process or in the renderer process. */ getProxy(identifier: ProxyIdentifier): T; - /** - * Returns a proxy to an object addressable/named in the extension host process. - * > **Note:** Arguments or results of type `URI` or `RegExp` will **not** be serialized/deserialized automatically. - */ - getFastProxy(identifier: ProxyIdentifier): T; - /** * Register manually created instance. */ @@ -35,19 +25,31 @@ export class ProxyIdentifier { _proxyIdentifierBrand: void; _suppressCompilerUnusedWarning: T; - isMain: boolean; - id: string; + public readonly isMain: boolean; + public readonly id: string; + public readonly isFancy: boolean; - constructor(isMain: boolean, id: string) { + constructor(isMain: boolean, id: string, isFancy: boolean) { this.isMain = isMain; this.id = id; + this.isFancy = isFancy; } } -export function createMainContextProxyIdentifier(identifier: string): ProxyIdentifier { - return new ProxyIdentifier(true, 'm' + identifier); +export const enum ProxyType { + NativeJSON = 0, + CustomMarshaller = 1 +} + +/** + * Using `isFancy` indicates that arguments or results of type `URI` or `RegExp` + * will be serialized/deserialized automatically, but this has a performance cost, + * as each argument/result must be visited. + */ +export function createMainContextProxyIdentifier(identifier: string, type: ProxyType = ProxyType.NativeJSON): ProxyIdentifier { + return new ProxyIdentifier(true, 'm' + identifier, type === ProxyType.CustomMarshaller); } -export function createExtHostContextProxyIdentifier(identifier: string): ProxyIdentifier { - return new ProxyIdentifier(false, 'e' + identifier); +export function createExtHostContextProxyIdentifier(identifier: string, type: ProxyType = ProxyType.NativeJSON): ProxyIdentifier { + return new ProxyIdentifier(false, 'e' + identifier, type === ProxyType.CustomMarshaller); } diff --git a/src/vs/workbench/services/extensions/node/rpcProtocol.ts b/src/vs/workbench/services/extensions/node/rpcProtocol.ts index 3a95f8feea6..eb8ce20304d 100644 --- a/src/vs/workbench/services/extensions/node/rpcProtocol.ts +++ b/src/vs/workbench/services/extensions/node/rpcProtocol.ts @@ -46,14 +46,7 @@ export class RPCProtocol implements IRPCProtocol { public getProxy(identifier: ProxyIdentifier): T { if (!this._proxies[identifier.id]) { - this._proxies[identifier.id] = this._createProxy(identifier.id, true); - } - return this._proxies[identifier.id]; - } - - public getFastProxy(identifier: ProxyIdentifier): T { - if (!this._proxies[identifier.id]) { - this._proxies[identifier.id] = this._createProxy(identifier.id, false); + this._proxies[identifier.id] = this._createProxy(identifier.id, identifier.isFancy); } return this._proxies[identifier.id]; } diff --git a/src/vs/workbench/test/electron-browser/api/extHostDocumentsAndEditors.test.ts b/src/vs/workbench/test/electron-browser/api/extHostDocumentsAndEditors.test.ts index a267a857a4a..cde58b49aa9 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostDocumentsAndEditors.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostDocumentsAndEditors.test.ts @@ -16,7 +16,6 @@ suite('ExtHostDocumentsAndEditors', () => { setup(function () { editors = new ExtHostDocumentsAndEditors({ getProxy: () => { return undefined; }, - getFastProxy: () => { return undefined; }, set: undefined, assertRegistered: undefined }); diff --git a/src/vs/workbench/test/electron-browser/api/testThreadService.ts b/src/vs/workbench/test/electron-browser/api/testThreadService.ts index ccabfbb32c0..7867d3d411b 100644 --- a/src/vs/workbench/test/electron-browser/api/testThreadService.ts +++ b/src/vs/workbench/test/electron-browser/api/testThreadService.ts @@ -13,9 +13,6 @@ export function OneGetThreadService(thing: any): IRPCProtocol { getProxy(): T { return thing; }, - getFastProxy(): T { - return thing; - }, set(identifier: ProxyIdentifier, value: R): R { return value; }, @@ -124,15 +121,6 @@ export class TestThreadService extends AbstractTestThreadService implements IRPC } getProxy(identifier: ProxyIdentifier): T { - return this._get(identifier); - } - - getFastProxy(identifier: ProxyIdentifier): T { - return this._get(identifier); - } - - _get(identifier: ProxyIdentifier): T { - let id = identifier.id; if (this._locals[id]) { return this._locals[id]; -- GitLab