src/vs/platform/instantiation/common/instantiation.ts
130 LOC · 128 covered · 2 uncovered · 13 ranges · 13296 concepts · 6 introducers · 6860 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
instantiation.ts ×5
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { DisposableStore } from '../../../base/common/lifecycle.js';
import * as descriptors from './descriptors.js';
import { ServiceCollection } from './serviceCollection.js';
// ------ internal util
export namespace _util {
export const serviceIds = new Map<string, ServiceIdentifier<any>>();
export const DI_TARGET = '$di$target';
export const DI_DEPENDENCIES = '$di$dependencies';
export function getServiceDependencies(ctor: DI_TARGET_OBJ): { id: ServiceIdentifier<any>; index: number }[] {
}
export interface DI_TARGET_OBJ extends Function {
[DI_TARGET]: Function;
[DI_DEPENDENCIES]: { id: ServiceIdentifier<any>; index: number }[];
}
}
// --- interfaces ------
export type BrandedService = { _serviceBrand: undefined };
export interface IConstructorSignature<T, Args extends any[] = []> {
new <Services extends BrandedService[]>(...args: [...Args, ...Services]): T;
}
export interface ServicesAccessor {
get<T>(id: ServiceIdentifier<T>): T;
}
export const IInstantiationService = createDecorator<IInstantiationService>('instantiationService');
/**
* Given a list of arguments as a tuple, attempt to extract the leading, non-service arguments
* to their own tuple.
*/
export type GetLeadingNonServiceArgs<TArgs extends any[]> =
TArgs extends [] ? []
: TArgs extends [...infer TFirst, BrandedService] ? GetLeadingNonServiceArgs<TFirst>
: TArgs;
export interface IInstantiationService {
readonly _serviceBrand: undefined;
/**
* Synchronously creates an instance that is denoted by the descriptor
*/
createInstance<T>(descriptor: descriptors.SyncDescriptor0<T>): T;
createInstance<Ctor extends new (...args: any[]) => unknown, R extends InstanceType<Ctor>>(ctor: Ctor, ...args: GetLeadingNonServiceArgs<ConstructorParameters<Ctor>>): R;
/**
* Calls a function with a service accessor.
*/
invokeFunction<R, TS extends any[] = []>(fn: (accessor: ServicesAccessor, ...args: TS) => R, ...args: TS): R;
/**
* Creates a child of this service which inherits all current services
* and adds/overwrites the given services.
*
* NOTE that the returned child is `disposable` and should be disposed when not used
* anymore. This will also dispose all the services that this service has created.
*/
createChild(services: ServiceCollection, store?: DisposableStore): IInstantiationService;
/**
* Disposes this instantiation service.
*
* - Will dispose all services that this instantiation service has created.
* - Will dispose all its children but not its parent.
* - Will NOT dispose services-instances that this service has been created with
* - Will NOT dispose consumer-instances this service has created
*/
dispose(): void;
}
/**
* Identifies a service of type `T`.
*/
export interface ServiceIdentifier<T> {
(...args: any[]): void;
type: T;
}
function storeServiceDependency(id: ServiceIdentifier<unknown>, target: Function, index: number): void {
instantiation.ts ×4
if ((target as _util.DI_TARGET_OBJ)[_util.DI_TARGET] === target) {
(target as _util.DI_TARGET_OBJ)[_util.DI_DEPENDENCIES].push({ id, index });
instantiation.ts ×1
(target as _util.DI_TARGET_OBJ)[_util.DI_DEPENDENCIES] = [{ id, index }];
(target as _util.DI_TARGET_OBJ)[_util.DI_TARGET] = target;
}
}
/**
* The *only* valid way to create a {{ServiceIdentifier}}.
*/
export function createDecorator<T>(serviceId: string): ServiceIdentifier<T> {
if (_util.serviceIds.has(serviceId)) {
}
const id = function (target: Function, key: string, index: number) {
throw new Error('@IServiceName-decorator can only be used to decorate a parameter');
}
} as ServiceIdentifier<T>;
id.toString = () => serviceId;
_util.serviceIds.set(serviceId, id);
return id;
}
export function refineServiceDecorator<T1, T extends T1>(serviceIdentifier: ServiceIdentifier<T1>): ServiceIdentifier<T> {
}