Skip to content

Commit

Permalink
Merge IState and IState2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Dec 21, 2016
1 parent b43b2c6 commit 3232075
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 48 deletions.
2 changes: 1 addition & 1 deletion build/monaco/monaco.d.ts.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
20 changes: 6 additions & 14 deletions src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand Down
38 changes: 5 additions & 33 deletions src/vs/editor/common/services/modeServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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') {
Expand All @@ -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 {
Expand Down

0 comments on commit 3232075

Please sign in to comment.