提交 4cc4ccef 编写于 作者: A Alex Dima

Simplify AbstractModeWorker

上级 53d62465
......@@ -58,7 +58,7 @@ export abstract class AbstractMode<W extends AbstractModeWorker> implements Mode
private _getOrCreateWorker(): TPromise<W> {
if (!this._workerPiecePromise) {
var workerDescriptor: AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], W> = this._getWorkerDescriptor();
var workerDescriptor: AsyncDescriptor2<string, Modes.IWorkerParticipant[], W> = this._getWorkerDescriptor();
// First, load the code of the worker (without instantiating it)
this._workerPiecePromise = AbstractMode._loadModule(workerDescriptor.moduleName).then(() => {
// Then, load & instantiate all the participants
......@@ -67,7 +67,7 @@ export abstract class AbstractMode<W extends AbstractModeWorker> implements Mode
return this._instantiationService.createInstance(participant);
}));
}).then((participants:Modes.IWorkerParticipant[]) => {
return this._instantiationService.createInstance<Modes.IMode, Modes.IWorkerParticipant[], W>(workerDescriptor, this, participants);
return this._instantiationService.createInstance<string, Modes.IWorkerParticipant[], W>(workerDescriptor, this.getId(), participants);
});
}
......@@ -82,7 +82,7 @@ export abstract class AbstractMode<W extends AbstractModeWorker> implements Mode
});
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], W> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], W> {
return createAsyncDescriptor2('vs/editor/common/modes/nullWorker', 'NullWorker');
}
......
......@@ -13,22 +13,22 @@ export abstract class AbstractModeWorker {
public resourceService:IResourceService;
public markerService: IMarkerService;
private _mode:Modes.IMode;
private _modeId: string;
constructor(
mode: Modes.IMode,
modeId: string,
participants: Modes.IWorkerParticipant[],
@IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService
) {
this._mode = mode;
this._modeId = modeId;
this.resourceService = resourceService;
this.markerService = markerService;
}
_getMode():Modes.IMode {
return this._mode;
_getModeId(): string {
return this._modeId;
}
}
......
......@@ -366,7 +366,7 @@ export class CSSMode extends AbstractMode<cssWorker.CSSWorker> {
}
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], cssWorker.CSSWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], cssWorker.CSSWorker> {
return createAsyncDescriptor2('vs/languages/css/common/cssWorker', 'CSSWorker');
}
......
......@@ -36,18 +36,18 @@ export class CSSWorker extends AbstractModeWorker {
private lintSettings : lintRules.IConfigurationSettings;
private _validationHelper: ValidationHelper;
constructor(mode: Modes.IMode, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
constructor(modeId: string, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService) {
super(mode, participants, resourceService, markerService);
super(modeId, participants, resourceService, markerService);
this._validationHelper = new ValidationHelper(
this.resourceService,
this._getMode().getId(),
this._getModeId(),
(toValidate) => this.doValidate(toValidate)
);
this.languageService = this.createLanguageService(resourceService, mode.getId());
this.languageService = this.createLanguageService(resourceService, modeId);
this.lintSettings = {};
this.validationEnabled = true;
}
......@@ -147,7 +147,7 @@ export class CSSWorker extends AbstractModeWorker {
private doValidate1(resource: URI):void {
if (!this.validationEnabled) {
this.markerService.changeOne(this._getMode().getId(), resource, []);
this.markerService.changeOne(this._getModeId(), resource, []);
return;
}
......@@ -164,7 +164,7 @@ export class CSSWorker extends AbstractModeWorker {
.filter(entry => entry.getLevel() !== _level.Level.Ignore)
.map(entry => this._createMarkerData(modelMirror, entry));
this.markerService.changeOne(this._getMode().getId(), resource, markerData);
this.markerService.changeOne(this._getModeId(), resource, markerData);
});
}
......
......@@ -40,7 +40,7 @@ suite('Validation - CSS', () => {
resourceService: resourceService,
markerService: markerService
});
var worker = new cssWorker.CSSWorker(modesUtil.createMockMode('mock.mode.id'), [], services.resourceService, services.markerService);
var worker = new cssWorker.CSSWorker('mock.mode.id', [], services.resourceService, services.markerService);
worker.doValidate([url]);
var markers = markerService.read({ resource: url });
......@@ -62,7 +62,7 @@ suite('Validation - CSS', () => {
markerService: markerService
});
var worker = new cssWorker.CSSWorker(modesUtil.createMockMode('mock.mode.id'), [], services.resourceService, services.markerService);
var worker = new cssWorker.CSSWorker('mock.mode.id', [], services.resourceService, services.markerService);
worker.doValidate([url]);
var markers = markerService.read({ resource: url });
......
......@@ -464,7 +464,7 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode<W> i
return null;
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], htmlWorker.HTMLWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], htmlWorker.HTMLWorker> {
return createAsyncDescriptor2('vs/languages/html/common/htmlWorker', 'HTMLWorker');
}
......
......@@ -38,10 +38,10 @@ export class HTMLWorker extends AbstractModeWorker {
private _tagProviders: htmlTags.IHTMLTagProvider[];
constructor(mode: Modes.IMode, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
constructor(modeId: string, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService, @IWorkspaceContextService contextService:IWorkspaceContextService) {
super(mode, participants, resourceService, markerService);
super(modeId, participants, resourceService, markerService);
this._contextService = contextService;
this._tagProviders = [];
......@@ -95,7 +95,7 @@ export class HTMLWorker extends AbstractModeWorker {
var modeAtPosition = modelAtPosition.getMode();
return callback(modeAtPosition.getId() !== this._getMode().getId(), modelAtPosition);
return callback(modeAtPosition.getId() !== this._getModeId(), modelAtPosition);
}
_delegateToAllModes<T>(resource:URI, callback:(models:EditorCommon.IMirrorModel[]) => T): T {
......
......@@ -40,7 +40,7 @@ suite('HTML - worker', () => {
markerService: markerService
});
var worker = new htmlWorker.HTMLWorker(mode, [], services.resourceService, services.markerService, services.contextService);
var worker = new htmlWorker.HTMLWorker(mode.getId(), [], services.resourceService, services.markerService, services.contextService);
return { worker: worker, model: model };
};
......
......@@ -143,7 +143,7 @@ export class JSMode extends typescriptMode.TypeScriptMode<javascriptWorker.JavaS
return model.getMode() === this || /\.(d\.ts|js)$/.test(model.getAssociatedResource().fsPath);
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], javascriptWorker.JavaScriptWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], javascriptWorker.JavaScriptWorker> {
return createAsyncDescriptor2('vs/languages/javascript/common/javascriptWorker', 'JavaScriptWorker');
}
......
......@@ -30,10 +30,10 @@ export class JavaScriptWorker extends typeScriptWorker.TypeScriptWorker2 {
private _fancyRewriters: rewriter.ISyntaxRewriter[];
constructor(mode: Modes.IMode, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
constructor(modeId: string, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService) {
super(mode, participants, resourceService, markerService);
super(modeId, participants, resourceService, markerService);
// since we colorize the shebang we should also always handle it
this._projectService.defaultRewriter = [new ShebangRewriter()];
......@@ -72,7 +72,7 @@ export class JavaScriptWorker extends typeScriptWorker.TypeScriptWorker2 {
markers.push(marker);
}
});
this.markerService.changeOne(`/${this._getMode().getId() }/semantic`, resource, markers);
this.markerService.changeOne(`/${this._getModeId() }/semantic`, resource, markers);
return result.hasMissingFiles;
}
}
......
......@@ -127,7 +127,7 @@ export class JSONMode extends AbstractMode<jsonWorker.JSONWorker> implements Mod
this._worker((w) => w.setSchemaContributions(data));
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], jsonWorker.JSONWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], jsonWorker.JSONWorker> {
return createAsyncDescriptor2('vs/languages/json/common/jsonWorker', 'JSONWorker');
}
......
......@@ -17,7 +17,6 @@ import JSONSchema = require('vs/base/common/jsonSchema');
import JSONIntellisense = require('./jsonIntellisense');
import WinJS = require('vs/base/common/winjs.base');
import Strings = require('vs/base/common/strings');
import {JSONMode} from './json';
import ProjectJSONContribution = require('./contributions/projectJSONContribution');
import PackageJSONContribution = require('./contributions/packageJSONContribution');
import BowerJSONContribution = require('./contributions/bowerJSONContribution');
......@@ -76,24 +75,22 @@ export class JSONWorker extends AbstractModeWorker implements Modes.IExtraInfoSu
private requestService: IRequestService;
private contextService: IWorkspaceContextService;
private jsonIntellisense : JSONIntellisense.JSONIntellisense;
private jsonMode: JSONMode;
private contributions: IJSONWorkerContribution[];
private _validationHelper: ValidationHelper;
constructor(mode: Modes.IMode, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
constructor(modeId: string, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService, @IRequestService requestService: IRequestService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IInstantiationService instantiationService: IInstantiationService) {
super(mode, participants, resourceService, markerService);
super(modeId, participants, resourceService, markerService);
this._validationHelper = new ValidationHelper(
this.resourceService,
this._getMode().getId(),
this._getModeId(),
(toValidate) => this.doValidate(toValidate)
);
this.jsonMode = <JSONMode>mode;
this.requestService = requestService;
this.contextService = contextService;
this.schemaService = instantiationService.createInstance(SchemaService.JSONSchemaService);
......@@ -255,7 +252,7 @@ export class JSONWorker extends AbstractModeWorker implements Modes.IExtraInfoSu
}
});
this.markerService.changeOne(this._getMode().getId(), resource, markerData);
this.markerService.changeOne(this._getModeId(), resource, markerData);
});
}
......
......@@ -41,7 +41,7 @@ suite('JSON - Worker', () => {
var _instantiationService = instantiationService.create({
resourceService: resourceModelMock
});
var worker = _instantiationService.createInstance(jsonworker.JSONWorker, mm.getMode(), []);
var worker = _instantiationService.createInstance(jsonworker.JSONWorker, mm.getMode().getId(), []);
return { worker: worker, model: mm };
};
......
......@@ -227,7 +227,7 @@ export class LESSMode extends Monarch.MonarchMode<lessWorker.LessWorker> impleme
}
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], lessWorker.LessWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], lessWorker.LessWorker> {
return createAsyncDescriptor2('vs/languages/less/common/lessWorker', 'LessWorker');
}
......
......@@ -29,7 +29,7 @@ suite('LESS - Intellisense', () => {
resourceService: resourceService,
});
var worker = new lessWorker.LessWorker(modesUtil.createMockMode('mock.mode.id'), [], services.resourceService, services.markerService);
var worker = new lessWorker.LessWorker('mock.mode.id', [], services.resourceService, services.markerService);
var position: EditorCommon.IPosition;
if (stringBefore === null) {
position = { column: 1, lineNumber: 1 };
......
......@@ -244,7 +244,7 @@ export class MarkdownMode extends Monarch.MonarchMode<MarkdownWorker.MarkdownWor
return this._worker((w) => w.getEmitOutput(resource, absoluteWorkerResourcesPath));
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], MarkdownWorker.MarkdownWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], MarkdownWorker.MarkdownWorker> {
return createAsyncDescriptor2('vs/languages/markdown/common/markdownWorker', 'MarkdownWorker');
}
}
......@@ -97,12 +97,12 @@ export class MarkdownWorker extends AbstractModeWorker {
private modeService: IModeService;
constructor(
mode: Modes.IMode, participants: Modes.IWorkerParticipant[],
modeId: string, participants: Modes.IWorkerParticipant[],
@IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService,
@IModeService modeService: IModeService
) {
super(mode, participants, resourceService, markerService);
super(modeId, participants, resourceService, markerService);
this.modeService = modeService;
}
......
......@@ -110,7 +110,7 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
});
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], RAZORWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], RAZORWorker> {
return createAsyncDescriptor2('vs/languages/razor/common/razorWorker', 'RAZORWorker');
}
......
......@@ -329,7 +329,7 @@ export class SASSMode extends Monarch.MonarchMode<sassWorker.SassWorker> impleme
}
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], sassWorker.SassWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], sassWorker.SassWorker> {
return createAsyncDescriptor2('vs/languages/sass/common/sassWorker', 'SassWorker');
}
......
......@@ -26,7 +26,7 @@ suite('SASS - Worker', () => {
resourceService: resourceService,
});
var worker = new sassWorker.SassWorker(modesUtil.createMockMode('mock.mode.id'), [], services.resourceService, services.markerService);
var worker = new sassWorker.SassWorker('mock.mode.id', [], services.resourceService, services.markerService);
return { worker: worker, model: model };
};
......
......@@ -395,7 +395,7 @@ export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extend
// ---- worker talk
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], typescriptWorker.TypeScriptWorker2> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, Modes.IWorkerParticipant[], typescriptWorker.TypeScriptWorker2> {
return createAsyncDescriptor2('vs/languages/typescript/common/typescriptWorker2', 'TypeScriptWorker2');
}
......
......@@ -43,14 +43,14 @@ export class TypeScriptWorker2 extends AbstractModeWorker {
protected _disposables: lifecycle.IDisposable[] = [];
private _validationHelper: ValidationHelper;
constructor(mode: Modes.IMode, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
constructor(modeId: string, participants: Modes.IWorkerParticipant[], @IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService) {
super(mode, participants, resourceService, markerService);
super(modeId, participants, resourceService, markerService);
this._validationHelper = new ValidationHelper(
this.resourceService,
this._getMode().getId(),
this._getModeId(),
(toValidate) => this.doValidate(toValidate)
);
......@@ -76,7 +76,7 @@ export class TypeScriptWorker2 extends AbstractModeWorker {
return (
/\.(ts|js)$/.test(element.getAssociatedResource().fsPath) ||
element.getMode() === this._getMode()
element.getMode().getId() === this._getModeId()
);
}
......@@ -177,14 +177,14 @@ export class TypeScriptWorker2 extends AbstractModeWorker {
markers.push.apply(markers, diagnostics.getSyntacticDiagnostics(project.languageService, resource, project.host.getCompilationSettings(),
this._options, this.resourceService.get(resource).getMode().getId() === 'javascript'));
markers.push.apply(markers, diagnostics.getExtraDiagnostics(project.languageService, resource, this._options));
this.markerService.changeOne(`/${this._getMode().getId() }/syntactic`, resource, markers);
this.markerService.changeOne(`/${this._getModeId() }/syntactic`, resource, markers);
}
public doValidateSemantics(resource: URI): boolean {
var project = this._projectService.getProject(resource);
var result = diagnostics.getSemanticDiagnostics(project.languageService, resource, this._options);
if (result) {
this.markerService.changeOne(`/${this._getMode().getId() }/semantic`, resource, result.markers);
this.markerService.changeOne(`/${this._getModeId() }/semantic`, resource, result.markers);
return result.hasMissingFiles;
}
}
......
......@@ -7,7 +7,7 @@
import {MonarchMode} from 'vs/editor/common/modes/monarch/monarch';
import types = require('vs/editor/common/modes/monarch/monarchTypes');
import {compile} from 'vs/editor/common/modes/monarch/monarchCompile';
import {IModeDescriptor, IMode, IWorkerParticipant} from 'vs/editor/common/modes';
import {IModeDescriptor, IWorkerParticipant} from 'vs/editor/common/modes';
import {AsyncDescriptor2, createAsyncDescriptor2} from 'vs/platform/instantiation/common/descriptors';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
......@@ -61,7 +61,7 @@ export class OutputMode extends MonarchMode<OutputWorker> {
this.linkSupport = this;
}
protected _getWorkerDescriptor(): AsyncDescriptor2<IMode, IWorkerParticipant[], OutputWorker> {
protected _getWorkerDescriptor(): AsyncDescriptor2<string, IWorkerParticipant[], OutputWorker> {
return createAsyncDescriptor2('vs/workbench/parts/output/common/outputWorker', 'OutputWorker');
}
......
......@@ -12,7 +12,7 @@ import URI from 'vs/base/common/uri';
import strings = require('vs/base/common/strings');
import arrays = require('vs/base/common/arrays');
import paths = require('vs/base/common/paths');
import {ILink, IMode, IWorkerParticipant} from 'vs/editor/common/modes';
import {ILink, IWorkerParticipant} from 'vs/editor/common/modes';
import {Range} from 'vs/editor/common/core/range';
import {IWorkspaceContextService, IWorkspace} from 'vs/platform/workspace/common/workspace';
......@@ -23,9 +23,9 @@ export class OutputWorker extends AbstractModeWorker {
private _contextService: IWorkspaceContextService;
private patterns: RegExp[];
constructor(mode: IMode, participants: IWorkerParticipant[], @IResourceService resourceService: IResourceService,
constructor(modeId: string, participants: IWorkerParticipant[], @IResourceService resourceService: IResourceService,
@IMarkerService markerService: IMarkerService, @IWorkspaceContextService contextService:IWorkspaceContextService) {
super(mode, participants, resourceService, markerService);
super(modeId, participants, resourceService, markerService);
this._contextService = contextService;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册