Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'
This commit is contained in:
@@ -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 { URI } from 'vs/base/common/uri';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
|
||||
import { FileAccess, Schemas } from 'vs/base/common/network';
|
||||
|
||||
class ExtensionResourceLoaderService implements IExtensionResourceLoaderService {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
constructor(
|
||||
@IFileService private readonly _fileService: IFileService
|
||||
) { }
|
||||
|
||||
async readExtensionResource(uri: URI): Promise<string> {
|
||||
uri = FileAccess.asBrowserUri(uri);
|
||||
|
||||
if (uri.scheme !== Schemas.http && uri.scheme !== Schemas.https) {
|
||||
const result = await this._fileService.readFile(uri);
|
||||
return result.value.toString();
|
||||
}
|
||||
|
||||
const response = await fetch(uri.toString(true));
|
||||
if (response.status !== 200) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
return response.text();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IExtensionResourceLoaderService, ExtensionResourceLoaderService);
|
||||
@@ -0,0 +1,21 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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';
|
||||
|
||||
export const IExtensionResourceLoaderService = createDecorator<IExtensionResourceLoaderService>('extensionResourceLoaderService');
|
||||
|
||||
/**
|
||||
* A service useful for reading resources from within extensions.
|
||||
*/
|
||||
export interface IExtensionResourceLoaderService {
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
/**
|
||||
* Read a certain resource within an extension.
|
||||
*/
|
||||
readExtensionResource(uri: URI): Promise<string>;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
|
||||
|
||||
export class ExtensionResourceLoaderService implements IExtensionResourceLoaderService {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
constructor(
|
||||
@IFileService private readonly _fileService: IFileService
|
||||
) { }
|
||||
|
||||
async readExtensionResource(uri: URI): Promise<string> {
|
||||
const result = await this._fileService.readFile(uri);
|
||||
return result.value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IExtensionResourceLoaderService, ExtensionResourceLoaderService);
|
||||
Reference in New Issue
Block a user