diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts index 7e0d622120f..b7c4c7c2abe 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts @@ -46,8 +46,7 @@ suite('vscode', function () { assert.fail(err); } assert.strictEqual(rpcPaths.length, 0, rpcPaths.join('\n')); - - // assert.strictEqual(proxyPaths.length, 0, proxyPaths.join('\n')); // proxies are accessible... + assert.strictEqual(proxyPaths.length, 0, proxyPaths.join('\n')); }); }); diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index a575b13d7c7..a32d5b80013 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -829,7 +829,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I return extHostFileSystem.registerFileSystemProvider(extension.identifier, scheme, provider, options); }, get fs() { - return extHostConsumerFileSystem; + return extHostConsumerFileSystem.value; }, registerFileSearchProvider: (scheme: string, provider: vscode.FileSearchProvider) => { checkProposedApiEnabled(extension); @@ -1290,9 +1290,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I class Extension implements vscode.Extension { - private _extensionService: IExtHostExtensionService; - private _originExtensionId: ExtensionIdentifier; - private _identifier: ExtensionIdentifier; + #extensionService: IExtHostExtensionService; + #originExtensionId: ExtensionIdentifier; + #identifier: ExtensionIdentifier; readonly id: string; readonly extensionUri: URI; @@ -1301,9 +1301,9 @@ class Extension implements vscode.Extension { readonly extensionKind: vscode.ExtensionKind; constructor(extensionService: IExtHostExtensionService, originExtensionId: ExtensionIdentifier, description: IExtensionDescription, kind: extHostTypes.ExtensionKind) { - this._extensionService = extensionService; - this._originExtensionId = originExtensionId; - this._identifier = description.identifier; + this.#extensionService = extensionService; + this.#originExtensionId = originExtensionId; + this.#identifier = description.identifier; this.id = description.identifier.value; this.extensionUri = description.extensionLocation; this.extensionPath = path.normalize(originalFSPath(description.extensionLocation)); @@ -1312,17 +1312,17 @@ class Extension implements vscode.Extension { } get isActive(): boolean { - return this._extensionService.isActivated(this._identifier); + return this.#extensionService.isActivated(this.#identifier); } get exports(): T { if (this.packageJSON.api === 'none') { return undefined!; // Strict nulloverride - Public api } - return this._extensionService.getExtensionExports(this._identifier); + return this.#extensionService.getExtensionExports(this.#identifier); } activate(): Thenable { - return this._extensionService.activateByIdWithErrors(this._identifier, { startup: false, extensionId: this._originExtensionId, activationEvent: 'api' }).then(() => this.exports); + return this.#extensionService.activateByIdWithErrors(this.#identifier, { startup: false, extensionId: this.#originExtensionId, activationEvent: 'api' }).then(() => this.exports); } } diff --git a/src/vs/workbench/api/common/extHostDebugService.ts b/src/vs/workbench/api/common/extHostDebugService.ts index d639431a13e..c1bbd4806c8 100644 --- a/src/vs/workbench/api/common/extHostDebugService.ts +++ b/src/vs/workbench/api/common/extHostDebugService.ts @@ -89,7 +89,7 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E get onDidReceiveDebugSessionCustomEvent(): Event { return this._onDidReceiveDebugSessionCustomEvent.event; } private _activeDebugConsole: ExtHostDebugConsole; - get activeDebugConsole(): ExtHostDebugConsole { return this._activeDebugConsole; } + get activeDebugConsole(): vscode.DebugConsole { return this._activeDebugConsole.value; } private _breakpoints: Map; private _breakpointEventsActive: boolean; @@ -911,20 +911,20 @@ export class ExtHostDebugSession implements vscode.DebugSession { } } -export class ExtHostDebugConsole implements vscode.DebugConsole { +export class ExtHostDebugConsole { - private _debugServiceProxy: MainThreadDebugServiceShape; + readonly value: vscode.DebugConsole; constructor(proxy: MainThreadDebugServiceShape) { - this._debugServiceProxy = proxy; - } - append(value: string): void { - this._debugServiceProxy.$appendDebugConsole(value); - } - - appendLine(value: string): void { - this.append(value + '\n'); + this.value = Object.freeze({ + append(value: string): void { + proxy.$appendDebugConsole(value); + }, + appendLine(value: string): void { + this.append(value + '\n'); + } + }); } } diff --git a/src/vs/workbench/api/common/extHostFileSystemConsumer.ts b/src/vs/workbench/api/common/extHostFileSystemConsumer.ts index 5bbd185c775..46e331f4c83 100644 --- a/src/vs/workbench/api/common/extHostFileSystemConsumer.ts +++ b/src/vs/workbench/api/common/extHostFileSystemConsumer.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { MainThreadFileSystemShape, MainContext } from './extHost.protocol'; +import { MainContext } from './extHost.protocol'; import * as vscode from 'vscode'; import * as files from 'vs/platform/files/common/files'; import { FileSystemError } from 'vs/workbench/api/common/extHostTypes'; @@ -12,49 +12,51 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo'; -export class ExtHostConsumerFileSystem implements vscode.FileSystem { +export class ExtHostConsumerFileSystem { readonly _serviceBrand: undefined; - private readonly _proxy: MainThreadFileSystemShape; + readonly value: vscode.FileSystem; constructor( @IExtHostRpcService extHostRpc: IExtHostRpcService, - @IExtHostFileSystemInfo private readonly _fileSystemInfo: IExtHostFileSystemInfo, + @IExtHostFileSystemInfo fileSystemInfo: IExtHostFileSystemInfo, ) { - this._proxy = extHostRpc.getProxy(MainContext.MainThreadFileSystem); - } + const proxy = extHostRpc.getProxy(MainContext.MainThreadFileSystem); - stat(uri: vscode.Uri): Promise { - return this._proxy.$stat(uri).catch(ExtHostConsumerFileSystem._handleError); - } - readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> { - return this._proxy.$readdir(uri).catch(ExtHostConsumerFileSystem._handleError); - } - createDirectory(uri: vscode.Uri): Promise { - return this._proxy.$mkdir(uri).catch(ExtHostConsumerFileSystem._handleError); - } - async readFile(uri: vscode.Uri): Promise { - return this._proxy.$readFile(uri).then(buff => buff.buffer).catch(ExtHostConsumerFileSystem._handleError); - } - writeFile(uri: vscode.Uri, content: Uint8Array): Promise { - return this._proxy.$writeFile(uri, VSBuffer.wrap(content)).catch(ExtHostConsumerFileSystem._handleError); - } - delete(uri: vscode.Uri, options?: { recursive?: boolean; useTrash?: boolean; }): Promise { - return this._proxy.$delete(uri, { ...{ recursive: false, useTrash: false }, ...options }).catch(ExtHostConsumerFileSystem._handleError); - } - rename(oldUri: vscode.Uri, newUri: vscode.Uri, options?: { overwrite?: boolean; }): Promise { - return this._proxy.$rename(oldUri, newUri, { ...{ overwrite: false }, ...options }).catch(ExtHostConsumerFileSystem._handleError); - } - copy(source: vscode.Uri, destination: vscode.Uri, options?: { overwrite?: boolean; }): Promise { - return this._proxy.$copy(source, destination, { ...{ overwrite: false }, ...options }).catch(ExtHostConsumerFileSystem._handleError); - } - isWritableFileSystem(scheme: string): boolean | undefined { - const capabilities = this._fileSystemInfo.getCapabilities(scheme); - if (typeof capabilities === 'number') { - return !(capabilities & files.FileSystemProviderCapabilities.Readonly); - } - return undefined; + this.value = Object.freeze({ + stat(uri: vscode.Uri): Promise { + return proxy.$stat(uri).catch(ExtHostConsumerFileSystem._handleError); + }, + readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> { + return proxy.$readdir(uri).catch(ExtHostConsumerFileSystem._handleError); + }, + createDirectory(uri: vscode.Uri): Promise { + return proxy.$mkdir(uri).catch(ExtHostConsumerFileSystem._handleError); + }, + async readFile(uri: vscode.Uri): Promise { + return proxy.$readFile(uri).then(buff => buff.buffer).catch(ExtHostConsumerFileSystem._handleError); + }, + writeFile(uri: vscode.Uri, content: Uint8Array): Promise { + return proxy.$writeFile(uri, VSBuffer.wrap(content)).catch(ExtHostConsumerFileSystem._handleError); + }, + delete(uri: vscode.Uri, options?: { recursive?: boolean; useTrash?: boolean; }): Promise { + return proxy.$delete(uri, { ...{ recursive: false, useTrash: false }, ...options }).catch(ExtHostConsumerFileSystem._handleError); + }, + rename(oldUri: vscode.Uri, newUri: vscode.Uri, options?: { overwrite?: boolean; }): Promise { + return proxy.$rename(oldUri, newUri, { ...{ overwrite: false }, ...options }).catch(ExtHostConsumerFileSystem._handleError); + }, + copy(source: vscode.Uri, destination: vscode.Uri, options?: { overwrite?: boolean; }): Promise { + return proxy.$copy(source, destination, { ...{ overwrite: false }, ...options }).catch(ExtHostConsumerFileSystem._handleError); + }, + isWritableFileSystem(scheme: string): boolean | undefined { + const capabilities = fileSystemInfo.getCapabilities(scheme); + if (typeof capabilities === 'number') { + return !(capabilities & files.FileSystemProviderCapabilities.Readonly); + } + return undefined; + } + }); } private static _handleError(err: any): never { diff --git a/src/vs/workbench/api/common/extHostStoragePaths.ts b/src/vs/workbench/api/common/extHostStoragePaths.ts index 34dc47ea635..45dc6abf5ed 100644 --- a/src/vs/workbench/api/common/extHostStoragePaths.ts +++ b/src/vs/workbench/api/common/extHostStoragePaths.ts @@ -48,7 +48,7 @@ export class ExtensionStoragePaths implements IExtensionStoragePaths { const storageUri = URI.joinPath(this._environment.workspaceStorageHome, storageName); try { - await this._extHostFileSystem.stat(storageUri); + await this._extHostFileSystem.value.stat(storageUri); this._logService.trace('[ExtHostStorage] storage dir already exists', storageUri); return storageUri; } catch { @@ -57,8 +57,8 @@ export class ExtensionStoragePaths implements IExtensionStoragePaths { try { this._logService.trace('[ExtHostStorage] creating dir and metadata-file', storageUri); - await this._extHostFileSystem.createDirectory(storageUri); - await this._extHostFileSystem.writeFile( + await this._extHostFileSystem.value.createDirectory(storageUri); + await this._extHostFileSystem.value.writeFile( URI.joinPath(storageUri, 'meta.json'), new TextEncoder().encode(JSON.stringify({ id: this._workspace.id,