提交 ee499ab7 编写于 作者: A Alex Dima

Make AbstractMode as thin as possible

上级 c78b8a2f
......@@ -12,7 +12,6 @@ import EditorCommon = require('vs/editor/common/editorCommon');
import {IDisposable} from 'vs/base/common/lifecycle';
import {TPromise} from 'vs/base/common/winjs.base';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {AsyncDescriptor2, createAsyncDescriptor2} from 'vs/platform/instantiation/common/descriptors';
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
......@@ -81,28 +80,20 @@ export class ModeWorkerManager<W> {
}
}
export abstract class AbstractMode<W> implements Modes.IMode {
export abstract class AbstractMode implements Modes.IMode {
_instantiationService:IInstantiationService;
_threadService:IThreadService;
private _descriptor:Modes.IModeDescriptor;
private _eventEmitter = new EventEmitter();
private _modeId: string;
private _eventEmitter: EventEmitter;
private _simplifiedMode: Modes.IMode;
constructor(
descriptor:Modes.IModeDescriptor,
instantiationService: IInstantiationService,
threadService: IThreadService
) {
this._instantiationService = instantiationService;
this._threadService = threadService;
this._descriptor = descriptor;
constructor(modeId:string) {
this._modeId = modeId;
this._eventEmitter = new EventEmitter();
this._simplifiedMode = null;
}
public getId(): string {
return this._descriptor.id;
return this._modeId;
}
public toSimplifiedMode(): Modes.IMode {
......@@ -112,8 +103,6 @@ export abstract class AbstractMode<W> implements Modes.IMode {
return this._simplifiedMode;
}
// START mics interface implementations
public addSupportChangedListener(callback: (e: EditorCommon.IModeSupportChangedEvent) => void) : IDisposable {
return this._eventEmitter.addListener2('modeSupportChanged', callback);
}
......@@ -132,8 +121,6 @@ export abstract class AbstractMode<W> implements Modes.IMode {
}
};
}
// END
}
class SimplifiedMode implements Modes.IMode {
......@@ -265,17 +252,15 @@ export var isDigit:(character:string, base:number)=>boolean = (function () {
};
})();
export class FrankensteinMode extends AbstractMode<void> {
export class FrankensteinMode extends AbstractMode {
public suggestSupport:Modes.ISuggestSupport;
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(descriptor, instantiationService, threadService);
super(descriptor.id);
this.suggestSupport = new TextualSuggestSupport(this.getId(), editorWorkerService);
}
......
......@@ -14,8 +14,6 @@ import {ILexer} from 'vs/editor/common/modes/monarch/monarchCommon';
import Modes = require('vs/editor/common/modes');
import MonarchDefinition = require('vs/editor/common/modes/monarch/monarchDefinition');
import {createTokenizationSupport} from 'vs/editor/common/modes/monarch/monarchLexer';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
......@@ -24,22 +22,20 @@ import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerServic
/**
* The MonarchMode creates a Monaco language mode given a certain language description
*/
export class MonarchMode<W> extends AbstractMode<W> {
export class MonarchMode extends AbstractMode {
public suggestSupport:Modes.ISuggestSupport;
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
constructor(
descriptor:Modes.IModeDescriptor,
modeId:string,
lexer: ILexer,
instantiationService: IInstantiationService,
threadService: IThreadService,
modeService: IModeService,
modelService: IModelService,
editorWorkerService: IEditorWorkerService
) {
super(descriptor, instantiationService, threadService);
super(modeId);
this.tokenizationSupport = createTokenizationSupport(modeService, this, lexer);
......
......@@ -278,7 +278,7 @@ export class State extends AbstractState {
}
}
export class CSSMode extends AbstractMode<cssWorker.CSSWorker> {
export class CSSMode extends AbstractMode {
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
......@@ -294,14 +294,16 @@ export class CSSMode extends AbstractMode<cssWorker.CSSWorker> {
public quickFixSupport: Modes.IQuickFixSupport;
private _modeWorkerManager: ModeWorkerManager<cssWorker.CSSWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService
) {
super(descriptor, instantiationService, threadService);
super(descriptor.id);
this._modeWorkerManager = new ModeWorkerManager<cssWorker.CSSWorker>(descriptor, 'vs/languages/css/common/cssWorker', 'CSSWorker', null, instantiationService);
this._threadService = threadService;
this.tokenizationSupport = new TokenizationSupport(this, {
getInitialState: () => new State(this, States.Selector, false, null, false, 0)
......
......@@ -9,7 +9,6 @@ import htmlMode = require('vs/languages/html/common/html');
import handlebarsTokenTypes = require('vs/languages/handlebars/common/handlebarsTokenTypes');
import htmlWorker = require('vs/languages/html/common/htmlWorker');
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {IModeService} from 'vs/editor/common/services/modeService';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {createWordRegExp} from 'vs/editor/common/modes/abstractMode';
......@@ -109,10 +108,9 @@ export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IModeService modeService: IModeService
) {
super(descriptor, instantiationService, threadService, modeService);
super(descriptor, instantiationService, modeService);
this.formattingSupport = null;
}
......
......@@ -14,7 +14,6 @@ import { AbstractState } from 'vs/editor/common/modes/abstractState';
import {OneWorkerAttr} from 'vs/platform/thread/common/threadService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService } from 'vs/platform/thread/common/thread';
import * as htmlTokenTypes from 'vs/languages/html/common/htmlTokenTypes';
import {EMPTY_ELEMENTS} from 'vs/languages/html/common/htmlEmptyTagsShared';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
......@@ -269,7 +268,7 @@ export class State extends AbstractState {
}
}
export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode<W> implements ITokenizationCustomization {
export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode implements ITokenizationCustomization {
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
......@@ -288,10 +287,9 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode<W> i
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IModeService modeService: IModeService
) {
super(descriptor, instantiationService, threadService);
super(descriptor.id);
this._modeWorkerManager = this._createModeWorkerManager(descriptor, instantiationService);
this.modeService = modeService;
......
......@@ -20,7 +20,7 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {SuggestSupport} from 'vs/editor/common/modes/supports/suggestSupport';
export class JSONMode extends AbstractMode<jsonWorker.JSONWorker> implements Modes.IExtraInfoSupport, Modes.IOutlineSupport, IThreadSynchronizableObject<ISchemaContributions> {
export class JSONMode extends AbstractMode implements Modes.IExtraInfoSupport, Modes.IOutlineSupport, IThreadSynchronizableObject<ISchemaContributions> {
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
......@@ -34,14 +34,16 @@ export class JSONMode extends AbstractMode<jsonWorker.JSONWorker> implements Mod
public outlineGroupLabel : { [name: string]: string; };
private _modeWorkerManager: ModeWorkerManager<jsonWorker.JSONWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService
) {
super(descriptor, instantiationService, threadService);
super(descriptor.id);
this._modeWorkerManager = new ModeWorkerManager<jsonWorker.JSONWorker>(descriptor, 'vs/languages/json/common/jsonWorker', 'JSONWorker', null, instantiationService);
this._threadService = threadService;
this.tokenizationSupport = tokenization.createTokenizationSupport(this, true);
......
......@@ -176,7 +176,7 @@ export var language: Types.ILanguage = <Types.ILanguage> {
}
};
export class LESSMode extends Monarch.MonarchMode<lessWorker.LessWorker> implements Modes.IExtraInfoSupport, Modes.IOutlineSupport {
export class LESSMode extends Monarch.MonarchMode implements Modes.IExtraInfoSupport, Modes.IOutlineSupport {
public inplaceReplaceSupport:Modes.IInplaceReplaceSupport;
public configSupport:Modes.IConfigurationSupport;
......@@ -189,6 +189,7 @@ export class LESSMode extends Monarch.MonarchMode<lessWorker.LessWorker> impleme
private modeService: IModeService;
private _modeWorkerManager: ModeWorkerManager<lessWorker.LessWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
......@@ -198,8 +199,9 @@ export class LESSMode extends Monarch.MonarchMode<lessWorker.LessWorker> impleme
@IModelService modelService: IModelService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(descriptor, Compile.compile(language), instantiationService, threadService, modeService, modelService, editorWorkerService);
super(descriptor.id, Compile.compile(language), modeService, modelService, editorWorkerService);
this._modeWorkerManager = new ModeWorkerManager<lessWorker.LessWorker>(descriptor, 'vs/languages/less/common/lessWorker', 'LessWorker', 'vs/languages/css/common/cssWorker', instantiationService);
this._threadService = threadService;
this.modeService = modeService;
......
......@@ -206,12 +206,13 @@ export const language =
}
};
export class MarkdownMode extends Monarch.MonarchMode<MarkdownWorker.MarkdownWorker> implements Modes.IEmitOutputSupport {
export class MarkdownMode extends Monarch.MonarchMode implements Modes.IEmitOutputSupport {
public emitOutputSupport: Modes.IEmitOutputSupport;
public configSupport:Modes.IConfigurationSupport;
private _modeWorkerManager: ModeWorkerManager<MarkdownWorker.MarkdownWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
......@@ -222,8 +223,9 @@ export class MarkdownMode extends Monarch.MonarchMode<MarkdownWorker.MarkdownWor
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(descriptor, Compile.compile(language), instantiationService, threadService, modeService, modelService, editorWorkerService);
super(descriptor.id, Compile.compile(language), modeService, modelService, editorWorkerService);
this._modeWorkerManager = new ModeWorkerManager<MarkdownWorker.MarkdownWorker>(descriptor, 'vs/languages/markdown/common/markdownWorker', 'MarkdownWorker', null, instantiationService);
this._threadService = threadService;
this.emitOutputSupport = this;
this.configSupport = this;
......
......@@ -10,8 +10,6 @@ import Modes = require('vs/editor/common/modes');
import {AbstractMode, isDigit, createWordRegExp} from 'vs/editor/common/modes/abstractMode';
import {AbstractState} from 'vs/editor/common/modes/abstractState';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {TokenizationSupport, ILeavingNestedModeData, ITokenizationCustomization} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {TextualSuggestSupport} from 'vs/editor/common/modes/supports/suggestSupport';
......@@ -458,7 +456,7 @@ export class PHPEnterHTMLState extends PHPState {
}
export class PHPMode extends AbstractMode<void> implements ITokenizationCustomization {
export class PHPMode extends AbstractMode implements ITokenizationCustomization {
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
......@@ -468,12 +466,10 @@ export class PHPMode extends AbstractMode<void> implements ITokenizationCustomiz
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IModeService modeService: IModeService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(descriptor, instantiationService, threadService);
super(descriptor.id);
this.modeService = modeService;
this.tokenizationSupport = new TokenizationSupport(this, this, true, false);
......
......@@ -7,8 +7,6 @@
import Modes = require('vs/editor/common/modes');
import {AbstractMode} from 'vs/editor/common/modes/abstractMode';
import {AbstractState} from 'vs/editor/common/modes/abstractState';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {TokenizationSupport} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {TextualSuggestSupport} from 'vs/editor/common/modes/supports/suggestSupport';
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
......@@ -38,18 +36,16 @@ class State extends AbstractState {
}
}
export class Mode extends AbstractMode<void> {
export class Mode extends AbstractMode {
public suggestSupport:Modes.ISuggestSupport;
public tokenizationSupport: Modes.ITokenizationSupport;
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(descriptor, instantiationService, threadService);
super(descriptor.id);
this.tokenizationSupport = new TokenizationSupport(this, {
getInitialState: () => new State(this)
}, false, false);
......
......@@ -11,7 +11,6 @@ import {createWordRegExp, ModeWorkerManager} from 'vs/editor/common/modes/abstra
import razorTokenTypes = require('vs/languages/razor/common/razorTokenTypes');
import {RAZORWorker} from 'vs/languages/razor/common/razorWorker';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {IModeService} from 'vs/editor/common/services/modeService';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {ILeavingNestedModeData} from 'vs/editor/common/modes/supports/tokenizationSupport';
......@@ -58,10 +57,9 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IModeService modeService: IModeService
) {
super(descriptor, instantiationService, threadService, modeService);
super(descriptor, instantiationService, modeService);
this.formattingSupport = null;
}
......
......@@ -278,7 +278,7 @@ export var language = <Types.ILanguage>{
}
};
export class SASSMode extends Monarch.MonarchMode<sassWorker.SassWorker> implements Modes.IExtraInfoSupport, Modes.IOutlineSupport {
export class SASSMode extends Monarch.MonarchMode implements Modes.IExtraInfoSupport, Modes.IOutlineSupport {
public inplaceReplaceSupport:Modes.IInplaceReplaceSupport;
public configSupport:Modes.IConfigurationSupport;
......@@ -291,6 +291,7 @@ export class SASSMode extends Monarch.MonarchMode<sassWorker.SassWorker> impleme
private modeService: IModeService;
private _modeWorkerManager: ModeWorkerManager<sassWorker.SassWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
......@@ -300,8 +301,9 @@ export class SASSMode extends Monarch.MonarchMode<sassWorker.SassWorker> impleme
@IModelService modelService: IModelService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(descriptor, Compile.compile(language), instantiationService, threadService, modeService, modelService, editorWorkerService);
super(descriptor.id, Compile.compile(language), modeService, modelService, editorWorkerService);
this._modeWorkerManager = new ModeWorkerManager<sassWorker.SassWorker>(descriptor, 'vs/languages/sass/common/sassWorker', 'SassWorker', 'vs/languages/css/common/cssWorker', instantiationService);
this._threadService = threadService;
this.modeService = modeService;
......
......@@ -128,7 +128,7 @@ class SemanticValidator {
}
}
export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extends AbstractMode<W> implements lifecycle.IDisposable {
export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extends AbstractMode implements lifecycle.IDisposable {
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
......@@ -151,6 +151,8 @@ export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extend
private _projectResolver: WinJS.TPromise<typescript.IProjectResolver2>;
private _semanticValidator: SemanticValidator;
private _modeWorkerManager: ModeWorkerManager<W>;
private _threadService:IThreadService;
private _instantiationService: IInstantiationService;
constructor(
descriptor:Modes.IModeDescriptor,
......@@ -158,7 +160,9 @@ export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extend
@IThreadService threadService: IThreadService,
@ITelemetryService telemetryService: ITelemetryService
) {
super(descriptor, instantiationService, threadService);
super(descriptor.id);
this._threadService = threadService;
this._instantiationService = instantiationService;
this._telemetryService = telemetryService;
this._modeWorkerManager = this._createModeWorkerManager(descriptor, instantiationService);
......
......@@ -9,7 +9,6 @@ import types = require('vs/editor/common/modes/monarch/monarchTypes');
import {compile} from 'vs/editor/common/modes/monarch/monarchCompile';
import {IModeDescriptor} from 'vs/editor/common/modes';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {OutputWorker} from 'vs/workbench/parts/output/common/outputWorker';
......@@ -44,7 +43,7 @@ export const language: types.ILanguage = {
}
};
export class OutputMode extends MonarchMode<OutputWorker> {
export class OutputMode extends MonarchMode {
public linkSupport:Modes.ILinkSupport;
......@@ -53,12 +52,11 @@ export class OutputMode extends MonarchMode<OutputWorker> {
constructor(
descriptor:IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IModeService modeService: IModeService,
@IModelService modelService: IModelService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(descriptor, compile(language), instantiationService, threadService, modeService, modelService, editorWorkerService);
super(descriptor.id, compile(language), modeService, modelService, editorWorkerService);
this._modeWorkerManager = new ModeWorkerManager<OutputWorker>(descriptor, 'vs/workbench/parts/output/common/outputWorker', 'OutputWorker', null, instantiationService);
this.linkSupport = this;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册