Skip to content

Commit

Permalink
Compute TextModel limits before initializing the tokenizer (#240919)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestut authored Feb 19, 2025
1 parent 94af5df commit e1c80bc
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/vs/editor/common/model/textModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,23 +320,6 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati
this._buffer = textBuffer;
this._bufferDisposable = disposable;

this._options = TextModel.resolveOptions(this._buffer, creationOptions);

const languageId = (typeof languageIdOrSelection === 'string' ? languageIdOrSelection : languageIdOrSelection.languageId);
if (typeof languageIdOrSelection !== 'string') {
this._languageSelectionListener.value = languageIdOrSelection.onDidChange(() => this._setLanguage(languageIdOrSelection.languageId));
}

this._bracketPairs = this._register(new BracketPairsTextModelPart(this, this._languageConfigurationService));
this._guidesTextModelPart = this._register(new GuidesTextModelPart(this, this._languageConfigurationService));
this._decorationProvider = this._register(new ColorizedBracketPairsDecorationProvider(this));
this._tokenizationTextModelPart = this.instantiationService.createInstance(TokenizationTextModelPart,
this,
this._bracketPairs,
languageId,
this._attachedViews
);

const bufferLineCount = this._buffer.getLineCount();
const bufferTextLength = this._buffer.getValueLengthInRange(new Range(1, 1, bufferLineCount, this._buffer.getLineLength(bufferLineCount) + 1), model.EndOfLinePreference.TextDefined);

Expand All @@ -355,6 +338,23 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati
this._isTooLargeForHeapOperation = false;
}

this._options = TextModel.resolveOptions(this._buffer, creationOptions);

const languageId = (typeof languageIdOrSelection === 'string' ? languageIdOrSelection : languageIdOrSelection.languageId);
if (typeof languageIdOrSelection !== 'string') {
this._languageSelectionListener.value = languageIdOrSelection.onDidChange(() => this._setLanguage(languageIdOrSelection.languageId));
}

this._bracketPairs = this._register(new BracketPairsTextModelPart(this, this._languageConfigurationService));
this._guidesTextModelPart = this._register(new GuidesTextModelPart(this, this._languageConfigurationService));
this._decorationProvider = this._register(new ColorizedBracketPairsDecorationProvider(this));
this._tokenizationTextModelPart = this.instantiationService.createInstance(TokenizationTextModelPart,
this,
this._bracketPairs,
languageId,
this._attachedViews
);

this._isTooLargeForSyncing = (bufferTextLength > TextModel._MODEL_SYNC_LIMIT);

this._versionId = 1;
Expand Down

0 comments on commit e1c80bc

Please sign in to comment.