Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'

This commit is contained in:
Joe Previte
2020-12-15 15:52:33 -07:00
4649 changed files with 1311795 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { CancellationToken } from 'vs/base/common/cancellation';
export const IDownloadService = createDecorator<IDownloadService>('downloadService');
export interface IDownloadService {
readonly _serviceBrand: undefined;
download(uri: URI, to: URI, cancellationToken?: CancellationToken): Promise<void>;
}

View File

@@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { Event } from 'vs/base/common/event';
import { IDownloadService } from 'vs/platform/download/common/download';
import { IURITransformer } from 'vs/base/common/uriIpc';
export class DownloadServiceChannel implements IServerChannel {
constructor(private readonly service: IDownloadService) { }
listen(_: unknown, event: string, arg?: any): Event<any> {
throw new Error('Invalid listen');
}
call(context: any, command: string, args?: any): Promise<any> {
switch (command) {
case 'download': return this.service.download(URI.revive(args[0]), URI.revive(args[1]));
}
throw new Error('Invalid call');
}
}
export class DownloadServiceChannelClient implements IDownloadService {
declare readonly _serviceBrand: undefined;
constructor(private channel: IChannel, private getUriTransformer: () => IURITransformer | null) { }
async download(from: URI, to: URI): Promise<void> {
const uriTransfomer = this.getUriTransformer();
if (uriTransfomer) {
from = uriTransfomer.transformOutgoingURI(from);
to = uriTransfomer.transformOutgoingURI(to);
}
await this.channel.call('download', [from, to]);
}
}

View File

@@ -0,0 +1,37 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDownloadService } from 'vs/platform/download/common/download';
import { URI } from 'vs/base/common/uri';
import { IRequestService, asText } from 'vs/platform/request/common/request';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IFileService } from 'vs/platform/files/common/files';
import { Schemas } from 'vs/base/common/network';
export class DownloadService implements IDownloadService {
declare readonly _serviceBrand: undefined;
constructor(
@IRequestService private readonly requestService: IRequestService,
@IFileService private readonly fileService: IFileService
) { }
async download(resource: URI, target: URI, cancellationToken: CancellationToken = CancellationToken.None): Promise<void> {
if (resource.scheme === Schemas.file || resource.scheme === Schemas.vscodeRemote) {
// Intentionally only support this for file|remote<->file|remote scenarios
await this.fileService.copy(resource, target);
return;
}
const options = { type: 'GET', url: resource.toString() };
const context = await this.requestService.request(options, cancellationToken);
if (context.res.statusCode === 200) {
await this.fileService.writeFile(target, context.stream);
} else {
const message = await asText(context);
throw new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`);
}
}
}