Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstantiationService debt #5443

Merged
merged 14 commits into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/vs/editor/common/commonCodeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as objects from 'vs/base/common/objects';
import * as timer from 'vs/base/common/timer';
import {TPromise} from 'vs/base/common/winjs.base';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import ServiceCollection from 'vs/platform/instantiation/common/serviceCollection';
import {IKeybindingContextKey, IKeybindingScopeLocation, IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {CommonEditorConfiguration} from 'vs/editor/common/config/commonEditorConfig';
Expand Down Expand Up @@ -114,9 +115,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements IActionPr
this.forcedWidgetFocusCount = 0;

this._telemetryService = telemetryService;
this._instantiationService = instantiationService.createChild({
keybindingService: this._keybindingService
});
this._instantiationService = instantiationService.createChild(new ServiceCollection([IKeybindingService, this._keybindingService]));

this._attachModel(null);

Expand Down
63 changes: 33 additions & 30 deletions src/vs/editor/common/worker/editorWorkerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@ import Severity from 'vs/base/common/severity';
import {TPromise} from 'vs/base/common/winjs.base';
import {WorkerServer} from 'vs/base/common/worker/workerServer';
import {EventService} from 'vs/platform/event/common/eventService';
import {IEventService} from 'vs/platform/event/common/event';
import {AbstractExtensionService, ActivatedExtension} from 'vs/platform/extensions/common/abstractExtensionService';
import {IExtensionDescription} from 'vs/platform/extensions/common/extensions';
import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService';
import {IExtensionDescription, IExtensionService} from 'vs/platform/extensions/common/extensions';
import ServiceCollection from 'vs/platform/instantiation/common/serviceCollection';
import {InstantiationService} from 'vs/platform/instantiation/common/instantiationService';
import {SecondaryMarkerService} from 'vs/platform/markers/common/markerService';
import {IMarkerService} from 'vs/platform/markers/common/markers';
import {BaseRequestService} from 'vs/platform/request/common/baseRequestService';
import {IRequestService} from 'vs/platform/request/common/request';
import {RemoteTelemetryService} from 'vs/platform/telemetry/common/remoteTelemetryService';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {WorkerThreadService} from 'vs/platform/thread/common/workerThreadService';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/baseWorkspaceContextService';
import {IWorkspace} from 'vs/platform/workspace/common/workspace';
import {IWorkspaceContextService, IWorkspace} from 'vs/platform/workspace/common/workspace';
import {ModeServiceImpl, ModeServiceWorkerHelper} from 'vs/editor/common/services/modeServiceImpl';
import {IModeService} from 'vs/editor/common/services/modeService';
import {ModelServiceWorkerHelper} from 'vs/editor/common/services/modelServiceImpl';
import {ResourceService} from 'vs/editor/common/services/resourceServiceImpl';
import {IResourceService} from 'vs/editor/common/services/resourceService';


export interface IInitData {
contextService: {
Expand Down Expand Up @@ -86,35 +95,29 @@ export class EditorWorkerServer {

public initialize(mainThread:WorkerServer, complete:ICallback, error:ICallback, progress:ICallback, initData:IInitData):void {

var extensionService = new WorkerExtensionService();

var contextService = new BaseWorkspaceContextService(initData.contextService.workspace, initData.contextService.configuration, initData.contextService.options);
const services = new ServiceCollection();

const extensionService = new WorkerExtensionService();
const contextService = new BaseWorkspaceContextService(initData.contextService.workspace, initData.contextService.configuration, initData.contextService.options);
this.threadService = new WorkerThreadService(mainThread.getRemoteCom());
this.threadService.setInstantiationService(createInstantiationService({ threadService: this.threadService }));

var telemetryServiceInstance = new RemoteTelemetryService('workerTelemetry', this.threadService);

var resourceService = new ResourceService();
var markerService = new SecondaryMarkerService(this.threadService);

var modeService = new ModeServiceImpl(this.threadService, extensionService);

var requestService = new BaseRequestService(contextService, telemetryServiceInstance);

var _services : any = {
threadService: this.threadService,
extensionService: extensionService,
modeService: modeService,
contextService: contextService,
eventService: new EventService(),
resourceService: resourceService,
markerService: markerService,
telemetryService: telemetryServiceInstance,
requestService: requestService
};

var instantiationService = createInstantiationService(_services);
this.threadService.setInstantiationService(new InstantiationService(new ServiceCollection([IThreadService, this.threadService])));
const telemetryServiceInstance = new RemoteTelemetryService('workerTelemetry', this.threadService);
const resourceService = new ResourceService();
const markerService = new SecondaryMarkerService(this.threadService);
const modeService = new ModeServiceImpl(this.threadService, extensionService);
const requestService = new BaseRequestService(contextService, telemetryServiceInstance);

services.set(IExtensionService, extensionService);
services.set(IThreadService, this.threadService);
services.set(IModeService, modeService);
services.set(IWorkspaceContextService, contextService);
services.set(IEventService, new EventService());
services.set(IResourceService, resourceService);
services.set(IMarkerService, markerService);
services.set(ITelemetryService, telemetryServiceInstance);
services.set(IRequestService, requestService);

const instantiationService = new InstantiationService(services);
this.threadService.setInstantiationService(instantiationService);

// Instantiate thread actors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {DefaultController, LegacyRenderer} from 'vs/base/parts/tree/browser/tree
import {Tree} from 'vs/base/parts/tree/browser/treeImpl';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import ServiceCollection from 'vs/platform/instantiation/common/serviceCollection';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {DefaultConfig} from 'vs/editor/common/config/defaultConfig';
Expand All @@ -34,7 +35,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import {Model} from 'vs/editor/common/model/model';
import {ICodeEditor, IMouseTarget} from 'vs/editor/browser/editorBrowser';
import {EmbeddedCodeEditorWidget} from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import {PeekViewWidget} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
import {PeekViewWidget, IPeekViewService} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
import {EventType, FileReferences, OneReference, ReferencesModel} from './referenceSearchModel';

class DecorationsManager implements IDisposable {
Expand Down Expand Up @@ -398,7 +399,7 @@ export class ReferenceWidget extends PeekViewWidget {
super(editor, keybindingService, ReferenceWidget.INNER_EDITOR_CONTEXT_KEY, { frameColor: '#007ACC', showFrame: false, showArrow: true });
this.editorService = editorService;
this.contextService = contextService;
this.instantiationService = instantiationService.createChild({ peekViewService: this });
this.instantiationService = instantiationService.createChild(new ServiceCollection([IPeekViewService, this]));

this.callOnModel = [];

Expand Down
41 changes: 11 additions & 30 deletions src/vs/platform/instantiation/common/instantiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,22 @@
'use strict';

import {TPromise} from 'vs/base/common/winjs.base';
import ServiceCollection from './serviceCollection';
import * as descriptors from './descriptors';

// ----------------------- internal util -----------------------
// ------ internal util

export namespace _util {

export const DI_TARGET = '$di$target';
export const DI_DEPENDENCIES = '$di$dependencies';
export const DI_PROVIDES = '$di$provides_service';

export function getServiceId(id: ServiceIdentifier<any>): string {
return id[DI_PROVIDES];
}

export function getServiceDependencies(ctor: any): { serviceId: string, index: number }[] {
return ctor[DI_DEPENDENCIES];
export function getServiceDependencies(ctor: any): { id: ServiceIdentifier<any>, index: number }[] {
return ctor[DI_DEPENDENCIES] || [];
}
}

// ----------------------- interfaces -----------------------

// --- interfaces ------

export interface IConstructorSignature0<T> {
new (...services: { serviceId: ServiceIdentifier<any>; }[]): T;
Expand Down Expand Up @@ -103,7 +98,6 @@ export interface IFunctionSignature8<A1, A2, A3, A4, A5, A6, A7, A8, R> {
(accessor: ServicesAccessor, first: A1, second: A2, third: A3, forth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8): R;
}


export var IInstantiationService = createDecorator<IInstantiationService>('instantiationService');

export interface IInstantiationService {
Expand Down Expand Up @@ -175,12 +169,7 @@ export interface IInstantiationService {
* Creates a child of this service which inherts all current services
* and adds/overwrites the given services
*/
createChild(services: any): IInstantiationService;

/**
* Registers a new service to this instantation service.
*/
registerService(name: string, service: any): void;
createChild(services: ServiceCollection): IInstantiationService;

/**
* Adds a service or a descriptor to the collection of services and
Expand All @@ -204,29 +193,21 @@ export interface ServiceIdentifier<T> {
*/
export function createDecorator<T>(serviceId: string): { (...args: any[]): void; type: T; } {

let ret = function(target: any, key: string, index: number): any {
let id = function(target: any, key: string, index: number): any {

if (arguments.length !== 3) {
throw new Error('@IServiceName-decorator can only be used to decorate a parameter');
}

if (target[_util.DI_TARGET] === target) {
target[_util.DI_DEPENDENCIES].push({ serviceId, index });
target[_util.DI_DEPENDENCIES].push({ id, index });
} else {
target[_util.DI_DEPENDENCIES] = [{ serviceId, index }];
target[_util.DI_DEPENDENCIES] = [{ id, index }];
target[_util.DI_TARGET] = target;
}
};

ret[_util.DI_PROVIDES] = serviceId;
// ret['type'] = undefined;
return <any>ret;
}
id.toString = () => serviceId;

/**
* A service context which can be used to retrieve services
* given a valid service identifer is being presented
*/
export interface Context {
get<T>(id: ServiceIdentifier<T>): T;
return <any>id;
}
Loading