Path: blob/main/extensions/copilot/src/util/common/services.ts
13397 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { SyncDescriptor } from '../vs/platform/instantiation/common/descriptors';6import * as insta from '../vs/platform/instantiation/common/instantiation';7import { ServiceIdentifier, createDecorator } from '../vs/platform/instantiation/common/instantiation';8import { InstantiationService } from '../vs/platform/instantiation/common/instantiationService';9import { ServiceCollection } from '../vs/platform/instantiation/common/serviceCollection';10export { ServiceIdentifier, createDecorator as createServiceIdentifier };1112export interface IInstantiationServiceBuilder {1314define<T>(id: insta.ServiceIdentifier<T>, instance: (T & insta.BrandedService) | SyncDescriptor<T>): void;1516seal(): insta.IInstantiationService;17}1819export class InstantiationServiceBuilder implements IInstantiationServiceBuilder {2021private _isSealed: boolean = false;22private readonly _collection: ServiceCollection;2324constructor(entries?: ServiceCollection | ([insta.ServiceIdentifier<unknown>, unknown][])) {25this._collection = Array.isArray(entries) ? new ServiceCollection(...entries) : entries ?? new ServiceCollection();26}2728define<T>(id: insta.ServiceIdentifier<T>, instance: (T & insta.BrandedService) | SyncDescriptor<T>): void {29if (this._isSealed) {30throw new Error('This accessor is sealed and cannot be modified anymore.');31}32this._collection.set(id, instance);33}3435seal(): insta.IInstantiationService {36if (this._isSealed) {37throw new Error('This accessor is sealed and cannot be seal again anymore.');38}39this._isSealed = true;40return new InstantiationService(this._collection, true);41}42}434445