From 3232075311424c8951635f36f902423f2cc3f3ac Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 21 Dec 2016 13:03:31 +0200 Subject: [PATCH] Merge IState and IState2 --- build/monaco/monaco.d.ts.recipe | 2 +- src/vs/editor/common/modes.ts | 20 +++------- .../editor/common/services/modeServiceImpl.ts | 38 +++---------------- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/build/monaco/monaco.d.ts.recipe b/build/monaco/monaco.d.ts.recipe index ffb18784c3b..bb7ad20348c 100644 --- a/build/monaco/monaco.d.ts.recipe +++ b/build/monaco/monaco.d.ts.recipe @@ -71,7 +71,7 @@ declare module monaco.languages { #includeAll(vs/editor/browser/standalone/standaloneLanguages;modes.=>;editorCommon.=>editor.;IMarkerData=>editor.IMarkerData): #includeAll(vs/editor/common/modes/languageConfiguration): -#includeAll(vs/editor/common/modes;editorCommon.IRange=>IRange;editorCommon.IPosition=>IPosition;editorCommon.=>editor.;IToken2=>IToken;ILineTokens2=>ILineTokens;IState2=>IState): +#includeAll(vs/editor/common/modes;editorCommon.IRange=>IRange;editorCommon.IPosition=>IPosition;editorCommon.=>editor.;IToken2=>IToken;ILineTokens2=>ILineTokens): #include(vs/editor/common/services/modeService): ILanguageExtensionPoint #includeAll(vs/editor/common/modes/monarch/monarchTypes): diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 590f47eaccc..8d9f31a71ea 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -17,14 +17,6 @@ import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; import Event, { Emitter } from 'vs/base/common/event'; -/** - * @internal - */ -export interface IState { - clone(): IState; - equals(other: IState): boolean; -} - /** * @internal */ @@ -82,16 +74,16 @@ export interface ILineTokens2 { * The tokenization end state. * A pointer will be held to this and the object should not be modified by the tokenizer after the pointer is returned. */ - endState: IState2; + endState: IState; } /** * The state of the tokenizer between two lines. * It is useful to store flags such as in multiline comment, etc. * The model will clone the previous line's state and pass it in to tokenize the next line. */ -export interface IState2 { - clone(): IState2; - equals(other: IState2): boolean; +export interface IState { + clone(): IState; + equals(other: IState): boolean; } /** * A "manual" provider of tokens. @@ -100,11 +92,11 @@ export interface TokensProvider { /** * The initial state of a language. Will be the state passed in to tokenize the first line. */ - getInitialState(): IState2; + getInitialState(): IState; /** * Tokenize a line given the state at the beginning of the line. */ - tokenize(line: string, state: IState2): ILineTokens2; + tokenize(line: string, state: IState): ILineTokens2; } /** diff --git a/src/vs/editor/common/services/modeServiceImpl.ts b/src/vs/editor/common/services/modeServiceImpl.ts index d7e35b4e281..6eb37814174 100644 --- a/src/vs/editor/common/services/modeServiceImpl.ts +++ b/src/vs/editor/common/services/modeServiceImpl.ts @@ -305,30 +305,6 @@ export class ModeServiceImpl implements IModeService { } } -export class TokenizationState2Adapter implements modes.IState { - - public readonly actual: modes.IState2; - - constructor(actual: modes.IState2) { - this.actual = actual; - } - - public clone(): TokenizationState2Adapter { - let actualClone = this.actual.clone(); - if (actualClone === this.actual) { - return this; - } - return new TokenizationState2Adapter(actualClone); - } - - public equals(other: modes.IState): boolean { - return ( - other instanceof TokenizationState2Adapter - && this.actual.equals(other.actual) - ); - } -} - export class TokenizationSupport2Adapter implements modes.ITokenizationSupport { private _modeId: string; @@ -340,15 +316,11 @@ export class TokenizationSupport2Adapter implements modes.ITokenizationSupport { } public getInitialState(): modes.IState { - return new TokenizationState2Adapter(this._actual.getInitialState()); + return this._actual.getInitialState(); } public tokenize(line: string, state: modes.IState, offsetDelta: number = 0, stopAtOffset?: number): modes.ILineTokens { - if (!(state instanceof TokenizationState2Adapter)) { - throw new Error('Unexpected state to tokenize with!'); - } - - let actualResult = this._actual.tokenize(line, state.actual); + let actualResult = this._actual.tokenize(line, state); let tokens: Token[] = []; actualResult.tokens.forEach((t) => { if (typeof t.scopes === 'string') { @@ -360,12 +332,12 @@ export class TokenizationSupport2Adapter implements modes.ITokenizationSupport { } }); - let endState: TokenizationState2Adapter; + let endState: modes.IState; // try to save an object if possible - if (actualResult.endState.equals(state.actual)) { + if (actualResult.endState.equals(state)) { endState = state; } else { - endState = new TokenizationState2Adapter(actualResult.endState); + endState = actualResult.endState; } return { -- GitLab