提交 5d76bbfd 编写于 作者: A Alex Dima

Synchronize only models belonging to compat modes to the modes workers

上级 557c2808
...@@ -153,9 +153,9 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I ...@@ -153,9 +153,9 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I
} }
services = services || {}; services = services || {};
var contextService = services.contextService; let contextService = services.contextService;
if (!contextService) { if (!contextService) {
var workspaceUri = URI.create('inmemory', 'model', '/'); let workspaceUri = URI.create('inmemory', 'model', '/');
contextService = new BaseWorkspaceContextService({ contextService = new BaseWorkspaceContextService({
resource: workspaceUri, resource: workspaceUri,
id: null, id: null,
...@@ -165,7 +165,7 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I ...@@ -165,7 +165,7 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I
}, {}); }, {});
} }
var telemetryService = services.telemetryService; let telemetryService = services.telemetryService;
if (!telemetryService) { if (!telemetryService) {
let config = contextService.getConfiguration(); let config = contextService.getConfiguration();
...@@ -179,16 +179,16 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I ...@@ -179,16 +179,16 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I
console.warn('standaloneEditorTelemetryEndpoint is obsolete'); console.warn('standaloneEditorTelemetryEndpoint is obsolete');
} }
var threadService = services.threadService || new mainThreadService.MainThreadService(contextService, 'vs/editor/common/worker/editorWorkerServer'); let threadService = services.threadService || new mainThreadService.MainThreadService(contextService, 'vs/editor/common/worker/editorWorkerServer');
var messageService = services.messageService || new SimpleServices.SimpleMessageService(); let messageService = services.messageService || new SimpleServices.SimpleMessageService();
var pluginService = services.pluginService || new SimpleServices.SimplePluginService(); let pluginService = services.pluginService || new SimpleServices.SimplePluginService();
var markerService = services.markerService || new MarkerService.MainProcessMarkerService(threadService); let markerService = services.markerService || new MarkerService.MainProcessMarkerService(threadService);
var requestService = services.requestService || new SimpleServices.SimpleEditorRequestService(contextService, telemetryService); let requestService = services.requestService || new SimpleServices.SimpleEditorRequestService(contextService, telemetryService);
var modelService = services.modelService || new ModelServiceImpl(threadService, markerService); let modeService = services.modeService || new MainThreadModeServiceImpl(threadService, pluginService);
var editorWorkerService = services.editorWorkerService || new EditorWorkerServiceImpl(modelService); let modelService = services.modelService || new ModelServiceImpl(threadService, markerService, modeService);
var modeService = services.modeService || new MainThreadModeServiceImpl(threadService, pluginService); let editorWorkerService = services.editorWorkerService || new EditorWorkerServiceImpl(modelService);
var codeEditorService = services.codeEditorService || new CodeEditorServiceImpl(); let codeEditorService = services.codeEditorService || new CodeEditorServiceImpl();
var eventService = services.eventService || new _eventService.EventService(); let eventService = services.eventService || new _eventService.EventService();
staticServices = { staticServices = {
pluginService: pluginService, pluginService: pluginService,
...@@ -206,7 +206,7 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I ...@@ -206,7 +206,7 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I
instantiationService: void 0 instantiationService: void 0
}; };
var instantiationService = InstantiationService.create(staticServices); let instantiationService = InstantiationService.create(staticServices);
staticServices.instantiationService = InstantiationService.create(staticServices); staticServices.instantiationService = InstantiationService.create(staticServices);
if (threadService instanceof mainThreadService.MainThreadService) { if (threadService instanceof mainThreadService.MainThreadService) {
threadService.setInstantiationService(instantiationService); threadService.setInstantiationService(instantiationService);
......
...@@ -48,6 +48,7 @@ export interface IModeService { ...@@ -48,6 +48,7 @@ export interface IModeService {
// --- reading // --- reading
isRegisteredMode(mimetypeOrModeId: string): boolean; isRegisteredMode(mimetypeOrModeId: string): boolean;
isCompatMode(modeId: string): boolean;
getRegisteredModes(): string[]; getRegisteredModes(): string[];
getRegisteredLanguageNames(): string[]; getRegisteredLanguageNames(): string[];
getExtensions(alias: string): string[]; getExtensions(alias: string): string[];
......
...@@ -212,6 +212,11 @@ export class ModeServiceImpl implements IModeService { ...@@ -212,6 +212,11 @@ export class ModeServiceImpl implements IModeService {
return this._registry.isRegisteredMode(mimetypeOrModeId); return this._registry.isRegisteredMode(mimetypeOrModeId);
} }
public isCompatMode(modeId:string): boolean {
let compatModeData = this._registry.getCompatMode(modeId);
return (compatModeData ? true : false);
}
public getRegisteredModes(): string[] { public getRegisteredModes(): string[] {
return this._registry.getRegisteredModes(); return this._registry.getRegisteredModes();
} }
......
...@@ -173,6 +173,7 @@ export class ModelServiceImpl implements IModelService { ...@@ -173,6 +173,7 @@ export class ModelServiceImpl implements IModelService {
private _markerService: IMarkerService; private _markerService: IMarkerService;
private _markerServiceSubscription: IDisposable; private _markerServiceSubscription: IDisposable;
private _threadService: IThreadService; private _threadService: IThreadService;
private _modeService: IModeService;
private _workerHelper: ModelServiceWorkerHelper; private _workerHelper: ModelServiceWorkerHelper;
private _onModelAdded: Emitter<EditorCommon.IModel>; private _onModelAdded: Emitter<EditorCommon.IModel>;
...@@ -184,9 +185,10 @@ export class ModelServiceImpl implements IModelService { ...@@ -184,9 +185,10 @@ export class ModelServiceImpl implements IModelService {
*/ */
private _models: {[modelId:string]:ModelData;}; private _models: {[modelId:string]:ModelData;};
constructor(threadService: IThreadService, markerService: IMarkerService) { constructor(threadService: IThreadService, markerService: IMarkerService, modeService:IModeService) {
this._threadService = threadService; this._threadService = threadService;
this._markerService = markerService; this._markerService = markerService;
this._modeService = modeService;
this._workerHelper = this._threadService.getRemotable(ModelServiceWorkerHelper); this._workerHelper = this._threadService.getRemotable(ModelServiceWorkerHelper);
this._models = {}; this._models = {};
...@@ -219,6 +221,14 @@ export class ModelServiceImpl implements IModelService { ...@@ -219,6 +221,14 @@ export class ModelServiceImpl implements IModelService {
// --- begin IModelService // --- begin IModelService
private _shouldSyncModelToWorkers(model:EditorCommon.IModel): boolean {
if (model.isTooLargeForHavingARichMode()) {
return false;
}
// Only sync models with compat modes to the workers
return this._modeService.isCompatMode(model.getMode().getId());
}
private _createModelData(value:string, modeOrPromise:TPromise<Modes.IMode>|Modes.IMode, resource: URI): ModelData { private _createModelData(value:string, modeOrPromise:TPromise<Modes.IMode>|Modes.IMode, resource: URI): ModelData {
// create & save the model // create & save the model
let model = new Model(value, modeOrPromise, resource); let model = new Model(value, modeOrPromise, resource);
...@@ -243,10 +253,9 @@ export class ModelServiceImpl implements IModelService { ...@@ -243,10 +253,9 @@ export class ModelServiceImpl implements IModelService {
ModelMarkerHandler.setMarkers(modelData, this._markerService.read({ resource: modelData.model.getAssociatedResource() })); ModelMarkerHandler.setMarkers(modelData, this._markerService.read({ resource: modelData.model.getAssociatedResource() }));
} }
if (!modelData.model.isTooLargeForHavingARichMode()) { if (this._shouldSyncModelToWorkers(modelData.model)) {
// send this model to the workers // send this model to the workers
modelData.isSyncedToWorkers = true; this._beginWorkerSync(modelData);
this._workerHelper.$_acceptNewModel(ModelServiceImpl._getBoundModelData(modelData.model));
} }
this._onModelAdded.fire(modelData.model); this._onModelAdded.fire(modelData.model);
...@@ -296,6 +305,23 @@ export class ModelServiceImpl implements IModelService { ...@@ -296,6 +305,23 @@ export class ModelServiceImpl implements IModelService {
// --- end IModelService // --- end IModelService
private _beginWorkerSync(modelData:ModelData): void {
if (modelData.isSyncedToWorkers) {
throw new Error('Model is already being synced to workers!');
}
modelData.isSyncedToWorkers = true;
this._workerHelper.$_acceptNewModel(ModelServiceImpl._getBoundModelData(modelData.model));
}
private _stopWorkerSync(modelData:ModelData): void {
if (!modelData.isSyncedToWorkers) {
throw new Error('Model is already not being synced to workers!');
}
modelData.isSyncedToWorkers = false;
this._workerHelper.$_acceptDidDisposeModel(modelData.model.getAssociatedResource());
}
private _onModelDisposing(model:EditorCommon.IModel): void { private _onModelDisposing(model:EditorCommon.IModel): void {
let modelId = MODEL_ID(model.getAssociatedResource()); let modelId = MODEL_ID(model.getAssociatedResource());
let modelData = this._models[modelId]; let modelData = this._models[modelId];
...@@ -311,7 +337,7 @@ export class ModelServiceImpl implements IModelService { ...@@ -311,7 +337,7 @@ export class ModelServiceImpl implements IModelService {
if (modelData.isSyncedToWorkers) { if (modelData.isSyncedToWorkers) {
// Dispose model in workers // Dispose model in workers
this._workerHelper.$_acceptDidDisposeModel(model.getAssociatedResource()); this._stopWorkerSync(modelData);
} }
delete this._models[modelId]; delete this._models[modelId];
...@@ -330,32 +356,63 @@ export class ModelServiceImpl implements IModelService { ...@@ -330,32 +356,63 @@ export class ModelServiceImpl implements IModelService {
} }
private _onModelEvents(modelData:ModelData, events:IEmitterEvent[]): void { private _onModelEvents(modelData:ModelData, events:IEmitterEvent[]): void {
let eventsForWorkers: IMirrorModelEvents = { contentChanged: [] };
// First look for dispose
for (let i = 0, len = events.length; i < len; i++) { for (let i = 0, len = events.length; i < len; i++) {
let e = events[i]; let e = events[i];
let data = e.getData(); if (e.getType() === EditorCommon.EventType.ModelDispose) {
this._onModelDisposing(modelData.model);
switch (e.getType()) { // no more processing since model got disposed
case EditorCommon.EventType.ModelDispose: return;
this._onModelDisposing(modelData.model); }
// no more event processing }
return;
case EditorCommon.EventType.ModelContentChanged: // Second, look for mode change
if (modelData.isSyncedToWorkers) { for (let i = 0, len = events.length; i < len; i++) {
eventsForWorkers.contentChanged.push(<EditorCommon.IModelContentChangedEvent>data); let e = events[i];
} if (e.getType() === EditorCommon.EventType.ModelModeChanged) {
break; let wasSyncedToWorkers = modelData.isSyncedToWorkers;
let shouldSyncToWorkers = this._shouldSyncModelToWorkers(modelData.model);
case EditorCommon.EventType.ModelModeChanged: if (wasSyncedToWorkers) {
let modeChangedEvent = <EditorCommon.IModelModeChangedEvent>data; if (shouldSyncToWorkers) {
if (modelData.isSyncedToWorkers) { // true -> true
// Forward mode change to all the workers // Forward mode change to all the workers
this._workerHelper.$_acceptDidChangeModelMode(modelData.getModelId(), modeChangedEvent.oldMode.getId(), modeChangedEvent.newMode.getId()); this._workerHelper.$_acceptDidChangeModelMode(modelData.getModelId(), modelData.model.getMode().getId());
} else {
// true -> false
// Stop worker sync for this model
this._stopWorkerSync(modelData);
// no more processing since we have removed the model from the workers
return;
}
} else {
if (shouldSyncToWorkers) {
// false -> true
// Begin syncing this model to the workers
this._beginWorkerSync(modelData);
// no more processing since we are sending the latest state
return;
} else {
// false -> false
// no more processing since this model was not synced and will not be synced
return;
} }
this._onModelModeChanged.fire({ model: modelData.model, oldModeId: modeChangedEvent.oldMode.getId() }); }
break; }
}
if (!modelData.isSyncedToWorkers) {
return;
}
// Finally, look for model content changes
let eventsForWorkers: IMirrorModelEvents = { contentChanged: [] };
for (let i = 0, len = events.length; i < len; i++) {
let e = events[i];
if (e.getType() === EditorCommon.EventType.ModelContentChanged) {
eventsForWorkers.contentChanged.push(<EditorCommon.IModelContentChangedEvent>e.getData());
} }
} }
...@@ -400,7 +457,7 @@ export class ModelServiceWorkerHelper { ...@@ -400,7 +457,7 @@ export class ModelServiceWorkerHelper {
}); });
} }
public $_acceptDidChangeModelMode(modelId:string, oldModeId:string, newModeId:string): TPromise<void> { public $_acceptDidChangeModelMode(modelId:string, newModeId:string): TPromise<void> {
let mirrorModel = this._resourceService.get(URI.parse(modelId)); let mirrorModel = this._resourceService.get(URI.parse(modelId));
// Block worker execution until the mode is instantiated // Block worker execution until the mode is instantiated
......
...@@ -155,6 +155,14 @@ export function createMockModeService(): IModeService { ...@@ -155,6 +155,14 @@ export function createMockModeService(): IModeService {
export function createMockModelService(): IModelService { export function createMockModelService(): IModelService {
var threadService = NULL_THREAD_SERVICE; var threadService = NULL_THREAD_SERVICE;
var modelService = new MockModelService(threadService, null); var pluginService = new MockPluginService();
var modeService = new MockModeService(threadService, pluginService);
var modelService = new MockModelService(threadService, null, modeService);
var inst = InstantiationService.create({
threadService: threadService,
pluginService: pluginService,
modeService: modeService
});
threadService.setInstantiationService(inst);
return modelService; return modelService;
} }
\ No newline at end of file
...@@ -274,9 +274,9 @@ export class WorkbenchShell { ...@@ -274,9 +274,9 @@ export class WorkbenchShell {
let pluginService = new MainProcessPluginService(this.contextService, this.threadService, this.messageService, this.telemetryService); let pluginService = new MainProcessPluginService(this.contextService, this.threadService, this.messageService, this.telemetryService);
this.keybindingService.setPluginService(pluginService); this.keybindingService.setPluginService(pluginService);
let modelService = new ModelServiceImpl(this.threadService, markerService);
let editorWorkerService = new EditorWorkerServiceImpl(modelService);
let modeService = new MainThreadModeServiceImpl(this.threadService, pluginService); let modeService = new MainThreadModeServiceImpl(this.threadService, pluginService);
let modelService = new ModelServiceImpl(this.threadService, markerService, modeService);
let editorWorkerService = new EditorWorkerServiceImpl(modelService);
let untitledEditorService = new UntitledEditorService(); let untitledEditorService = new UntitledEditorService();
this.themeService = new ThemeService(pluginService); this.themeService = new ThemeService(pluginService);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册