Skip to content

Commit

Permalink
Explicit getters and setters for IModelLine.isInvalid (#30180)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jul 6, 2017
1 parent c851d5d commit 08f5e5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/vs/editor/common/model/modelLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ function computePlusOneIndentLevel(line: string, tabSize: number): number {

export interface IModelLine {
readonly text: string;
isInvalid: boolean;

// --- markers
addMarker(marker: LineMarker): void;
Expand All @@ -171,6 +170,8 @@ export interface IModelLine {

// --- tokenization
resetTokenizationState(): void;
isInvalid(): boolean;
setIsInvalid(isInvalid: boolean): void;
getState(): IState;
setState(state: IState): void;
getTokens(topLevelLanguageId: LanguageId): LineTokens;
Expand Down Expand Up @@ -198,12 +199,12 @@ export class ModelLine implements IModelLine {
*/
private _metadata: number;

public get isInvalid(): boolean {
public isInvalid(): boolean {
return (this._metadata & 0x00000001) ? true : false;
}

public set isInvalid(value: boolean) {
this._metadata = (this._metadata & 0xfffffffe) | (value ? 1 : 0);
public setIsInvalid(isInvalid: boolean): void {
this._metadata = (this._metadata & 0xfffffffe) | (isInvalid ? 1 : 0);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/vs/editor/common/model/textModelWithTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
}

protected _invalidateLine(lineIndex: number): void {
this._lines[lineIndex].isInvalid = true;
this._lines[lineIndex].setIsInvalid(true);
if (lineIndex < this._invalidLineStartIndex) {
if (this._invalidLineStartIndex < this._lines.length) {
this._lines[this._invalidLineStartIndex].isInvalid = true;
this._lines[this._invalidLineStartIndex].setIsInvalid(true);
}
this._invalidLineStartIndex = lineIndex;
this._beginBackgroundTokenization();
Expand Down Expand Up @@ -353,14 +353,14 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
}
this._lines[lineIndex].setTokens(this._languageIdentifier.id, r.tokens);
eventBuilder.registerChangedTokens(lineIndex + 1);
this._lines[lineIndex].isInvalid = false;
this._lines[lineIndex].setIsInvalid(false);

if (endStateIndex < linesLength) {
if (this._lines[endStateIndex].getState() !== null && r.endState.equals(this._lines[endStateIndex].getState())) {
// The end state of this line remains the same
let nextInvalidLineIndex = lineIndex + 1;
while (nextInvalidLineIndex < linesLength) {
if (this._lines[nextInvalidLineIndex].isInvalid) {
if (this._lines[nextInvalidLineIndex].isInvalid()) {
break;
}
if (nextInvalidLineIndex + 1 < linesLength) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/test/common/model/model.modes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ suite('Editor Model - Model Modes 2', () => {
function invalidEqual(model: Model, expected: number[]): void {
let actual: number[] = [];
for (let i = 0, len = model.getLineCount(); i < len; i++) {
if (model._lines[i].isInvalid) {
if (model._lines[i].isInvalid()) {
actual.push(i);
}
}
Expand Down

0 comments on commit 08f5e5d

Please sign in to comment.