diff --git a/src/vs/workbench/api/browser/mainThreadFileSystem.ts b/src/vs/workbench/api/browser/mainThreadFileSystem.ts index fc8f4301c80..f419a053be0 100644 --- a/src/vs/workbench/api/browser/mainThreadFileSystem.ts +++ b/src/vs/workbench/api/browser/mainThreadFileSystem.ts @@ -159,6 +159,10 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape { return consumeStream(stream, chunks => chunks.join()); } + async $encode(resource: UriComponents, content: string): Promise { + return this._textFileService.getEncodedReadable(URI.revive(resource), content); + } + private static _handleError(err: any): never { if (err instanceof FileOperationError) { switch (err.fileOperationResult) { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 22e1219af3e..66767d57ca0 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1499,6 +1499,7 @@ export interface MainThreadFileSystemShape extends IDisposable { $delete(resource: UriComponents, opts: files.IFileDeleteOptions): Promise; $decode(resource: UriComponents, content: VSBuffer): Promise; + $encode(resource: UriComponents, content: string): Promise; $ensureActivation(scheme: string): Promise; } diff --git a/src/vs/workbench/api/common/extHostFileSystemConsumer.ts b/src/vs/workbench/api/common/extHostFileSystemConsumer.ts index 5f657b57e9f..ab93b4692b0 100644 --- a/src/vs/workbench/api/common/extHostFileSystemConsumer.ts +++ b/src/vs/workbench/api/common/extHostFileSystemConsumer.ts @@ -157,6 +157,10 @@ export class ExtHostConsumerFileSystem { }, decode(uri: vscode.Uri, content: Uint8Array): Promise { return that._proxy.$decode(uri, VSBuffer.wrap(content)); + }, + async encode(uri: vscode.Uri, content: string): Promise { + const buff = await that._proxy.$encode(uri, content); + return buff.buffer; } }); } diff --git a/src/vscode-dts/vscode.proposed.textDocumentEncoding.d.ts b/src/vscode-dts/vscode.proposed.textDocumentEncoding.d.ts index aa107eeb4a4..4357d91755b 100644 --- a/src/vscode-dts/vscode.proposed.textDocumentEncoding.d.ts +++ b/src/vscode-dts/vscode.proposed.textDocumentEncoding.d.ts @@ -40,8 +40,21 @@ declare module 'vscode' { * @param uri The URI that represents the file. This information * is used to figure out the encoding related configuration for the file. * @param content The content to decode as a `Uint8Array`. - * @returns A Thenable that resolves to the decoded string. + * @returns A thenable that resolves to the decoded `string`. */ decode(uri: Uri, content: Uint8Array): Thenable; + + /** + * Encodes the content of a string to a `Uint8Array` using + * the same encoding logic that is used when saving text documents. + * + * This method will respect the user configured file encoding. + * + *@param uri The URI that represents the file. This information + * is used to figure out the encoding related configuration for the file. + * @param content The content to decode as a `string`. + * @returns A thenable that resolves to the encoded `Uint8Array`. + */ + encode(uri: Uri, content: string): Thenable; } }