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

Merge IState and IState2

上级 b43b2c6f
......@@ -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):
......
......@@ -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;
}
/**
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册