/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Event } from '../../base/common/event.js';6import { IMarkdownString } from '../../base/common/htmlContent.js';7import { IDisposable } from '../../base/common/lifecycle.js';8import { equals } from '../../base/common/objects.js';9import { ThemeColor } from '../../base/common/themables.js';10import { URI } from '../../base/common/uri.js';11import { ISingleEditOperation } from './core/editOperation.js';12import { IPosition, Position } from './core/position.js';13import { IRange, Range } from './core/range.js';14import { Selection } from './core/selection.js';15import { TextChange } from './core/textChange.js';16import { WordCharacterClassifier } from './core/wordCharacterClassifier.js';17import { IWordAtPosition } from './core/wordHelper.js';18import { FormattingOptions } from './languages.js';19import { ILanguageSelection } from './languages/language.js';20import { IBracketPairsTextModelPart } from './textModelBracketPairs.js';21import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent, ModelFontChangedEvent, ModelLineHeightChangedEvent } from './textModelEvents.js';22import { IModelContentChange } from './model/mirrorTextModel.js';23import { IGuidesTextModelPart } from './textModelGuides.js';24import { ITokenizationTextModelPart } from './tokenizationTextModelPart.js';25import { UndoRedoGroup } from '../../platform/undoRedo/common/undoRedo.js';26import { TokenArray } from './tokens/lineTokens.js';27import { IEditorModel } from './editorCommon.js';28import { TextModelEditSource } from './textModelEditSource.js';29import { TextEdit } from './core/edits/textEdit.js';30import { IViewModel } from './viewModel.js';3132/**33* Vertical Lane in the overview ruler of the editor.34*/35export enum OverviewRulerLane {36Left = 1,37Center = 2,38Right = 4,39Full = 740}4142/**43* Vertical Lane in the glyph margin of the editor.44*/45export enum GlyphMarginLane {46Left = 1,47Center = 2,48Right = 3,49}5051export interface IGlyphMarginLanesModel {52/**53* The number of lanes that should be rendered in the editor.54*/55readonly requiredLanes: number;5657/**58* Gets the lanes that should be rendered starting at a given line number.59*/60getLanesAtLine(lineNumber: number): GlyphMarginLane[];6162/**63* Resets the model and ensures it can contain at least `maxLine` lines.64*/65reset(maxLine: number): void;6667/**68* Registers that a lane should be visible at the Range in the model.69* @param persist - if true, notes that the lane should always be visible,70* even on lines where there's no specific request for that lane.71*/72push(lane: GlyphMarginLane, range: Range, persist?: boolean): void;73}7475/**76* Position in the minimap to render the decoration.77*/78export const enum MinimapPosition {79Inline = 1,80Gutter = 281}8283/**84* Section header style.85*/86export const enum MinimapSectionHeaderStyle {87Normal = 1,88Underlined = 289}9091export interface IDecorationOptions {92/**93* CSS color to render.94* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry95*/96color: string | ThemeColor | undefined;97/**98* CSS color to render.99* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry100*/101darkColor?: string | ThemeColor;102}103104export interface IModelDecorationGlyphMarginOptions {105/**106* The position in the glyph margin.107*/108position: GlyphMarginLane;109110/**111* Whether the glyph margin lane in {@link position} should be rendered even112* outside of this decoration's range.113*/114persistLane?: boolean;115}116117/**118* Options for rendering a model decoration in the overview ruler.119*/120export interface IModelDecorationOverviewRulerOptions extends IDecorationOptions {121/**122* The position in the overview ruler.123*/124position: OverviewRulerLane;125}126127/**128* Options for rendering a model decoration in the minimap.129*/130export interface IModelDecorationMinimapOptions extends IDecorationOptions {131/**132* The position in the minimap.133*/134position: MinimapPosition;135/**136* If the decoration is for a section header, which header style.137*/138sectionHeaderStyle?: MinimapSectionHeaderStyle | null;139/**140* If the decoration is for a section header, the header text.141*/142sectionHeaderText?: string | null;143}144145/**146* Options for a model decoration.147*/148export interface IModelDecorationOptions {149/**150* A debug description that can be used for inspecting model decorations.151* @internal152*/153description: string;154/**155* Customize the growing behavior of the decoration when typing at the edges of the decoration.156* Defaults to TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges157*/158stickiness?: TrackedRangeStickiness;159/**160* CSS class name describing the decoration.161*/162className?: string | null;163/**164* Indicates whether the decoration should span across the entire line when it continues onto the next line.165*/166shouldFillLineOnLineBreak?: boolean | null;167blockClassName?: string | null;168/**169* Indicates if this block should be rendered after the last line.170* In this case, the range must be empty and set to the last line.171*/172blockIsAfterEnd?: boolean | null;173blockDoesNotCollapse?: boolean | null;174blockPadding?: [top: number, right: number, bottom: number, left: number] | null;175176/**177* Message to be rendered when hovering over the glyph margin decoration.178*/179glyphMarginHoverMessage?: IMarkdownString | IMarkdownString[] | null;180/**181* Array of MarkdownString to render as the decoration message.182*/183hoverMessage?: IMarkdownString | IMarkdownString[] | null;184/**185* Array of MarkdownString to render as the line number message.186*/187lineNumberHoverMessage?: IMarkdownString | IMarkdownString[] | null;188/**189* Should the decoration expand to encompass a whole line.190*/191isWholeLine?: boolean;192/**193* Always render the decoration (even when the range it encompasses is collapsed).194*/195showIfCollapsed?: boolean;196/**197* Collapse the decoration if its entire range is being replaced via an edit.198* @internal199*/200collapseOnReplaceEdit?: boolean;201/**202* Specifies the stack order of a decoration.203* A decoration with greater stack order is always in front of a decoration with204* a lower stack order when the decorations are on the same line.205*/206zIndex?: number;207/**208* If set, render this decoration in the overview ruler.209*/210overviewRuler?: IModelDecorationOverviewRulerOptions | null;211/**212* If set, render this decoration in the minimap.213*/214minimap?: IModelDecorationMinimapOptions | null;215/**216* If set, the decoration will be rendered in the glyph margin with this CSS class name.217*/218glyphMarginClassName?: string | null;219/**220* If set and the decoration has {@link glyphMarginClassName} set, render this decoration221* with the specified {@link IModelDecorationGlyphMarginOptions} in the glyph margin.222*/223glyphMargin?: IModelDecorationGlyphMarginOptions | null;224/**225* If set, the decoration will override the line height of the lines it spans. This value is a multiplier to the default line height.226*/227lineHeight?: number | null;228/**229* Font family230*/231fontFamily?: string | null;232/**233* Font size234*/235fontSize?: string | null;236/**237* Font weight238*/239fontWeight?: string | null;240/**241* Font style242*/243fontStyle?: string | null;244/**245* If set, the decoration will be rendered in the lines decorations with this CSS class name.246*/247linesDecorationsClassName?: string | null;248/**249* Controls the tooltip text of the line decoration.250*/251linesDecorationsTooltip?: string | null;252/**253* If set, the decoration will be rendered on the line number.254*/255lineNumberClassName?: string | null;256/**257* If set, the decoration will be rendered in the lines decorations with this CSS class name, but only for the first line in case of line wrapping.258*/259firstLineDecorationClassName?: string | null;260/**261* If set, the decoration will be rendered in the margin (covering its full width) with this CSS class name.262*/263marginClassName?: string | null;264/**265* If set, the decoration will be rendered inline with the text with this CSS class name.266* Please use this only for CSS rules that must impact the text. For example, use `className`267* to have a background color decoration.268*/269inlineClassName?: string | null;270/**271* If there is an `inlineClassName` which affects letter spacing.272*/273inlineClassNameAffectsLetterSpacing?: boolean;274/**275* If set, the decoration will be rendered before the text with this CSS class name.276*/277beforeContentClassName?: string | null;278/**279* If set, the decoration will be rendered after the text with this CSS class name.280*/281afterContentClassName?: string | null;282/**283* If set, text will be injected in the view after the range.284*/285after?: InjectedTextOptions | null;286287/**288* If set, text will be injected in the view before the range.289*/290before?: InjectedTextOptions | null;291292/**293* If set, this decoration will not be rendered for comment tokens.294* @internal295*/296hideInCommentTokens?: boolean | null;297298/**299* If set, this decoration will not be rendered for string tokens.300* @internal301*/302hideInStringTokens?: boolean | null;303304/**305* Whether the decoration affects the font.306* @internal307*/308affectsFont?: boolean | null;309310/**311* The text direction of the decoration.312*/313textDirection?: TextDirection | null;314}315316/**317* Text Direction for a decoration.318*/319export enum TextDirection {320LTR = 0,321322RTL = 1,323}324325/**326* Configures text that is injected into the view without changing the underlying document.327*/328export interface InjectedTextOptions {329/**330* Sets the text to inject. Must be a single line.331*/332readonly content: string;333334/**335* @internal336*/337readonly tokens?: TokenArray | null;338339/**340* If set, the decoration will be rendered inline with the text with this CSS class name.341*/342readonly inlineClassName?: string | null;343344/**345* If there is an `inlineClassName` which affects letter spacing.346*/347readonly inlineClassNameAffectsLetterSpacing?: boolean;348349/**350* This field allows to attach data to this injected text.351* The data can be read when injected texts at a given position are queried.352*/353readonly attachedData?: unknown;354355/**356* Configures cursor stops around injected text.357* Defaults to {@link InjectedTextCursorStops.Both}.358*/359readonly cursorStops?: InjectedTextCursorStops | null;360}361362export enum InjectedTextCursorStops {363Both,364Right,365Left,366None367}368369/**370* New model decorations.371*/372export interface IModelDeltaDecoration {373/**374* Range that this decoration covers.375*/376range: IRange;377/**378* Options associated with this decoration.379*/380options: IModelDecorationOptions;381}382383/**384* A decoration in the model.385*/386export interface IModelDecoration {387/**388* Identifier for a decoration.389*/390readonly id: string;391/**392* Identifier for a decoration's owner.393*/394readonly ownerId: number;395/**396* Range that this decoration covers.397*/398readonly range: Range;399/**400* Options associated with this decoration.401*/402readonly options: IModelDecorationOptions;403}404405/**406* An accessor that can add, change or remove model decorations.407* @internal408*/409export interface IModelDecorationsChangeAccessor {410/**411* Add a new decoration.412* @param range Range that this decoration covers.413* @param options Options associated with this decoration.414* @return An unique identifier associated with this decoration.415*/416addDecoration(range: IRange, options: IModelDecorationOptions): string;417/**418* Change the range that an existing decoration covers.419* @param id The unique identifier associated with the decoration.420* @param newRange The new range that this decoration covers.421*/422changeDecoration(id: string, newRange: IRange): void;423/**424* Change the options associated with an existing decoration.425* @param id The unique identifier associated with the decoration.426* @param newOptions The new options associated with this decoration.427*/428changeDecorationOptions(id: string, newOptions: IModelDecorationOptions): void;429/**430* Remove an existing decoration.431* @param id The unique identifier associated with the decoration.432*/433removeDecoration(id: string): void;434/**435* Perform a minimum amount of operations, in order to transform the decorations436* identified by `oldDecorations` to the decorations described by `newDecorations`437* and returns the new identifiers associated with the resulting decorations.438*439* @param oldDecorations Array containing previous decorations identifiers.440* @param newDecorations Array describing what decorations should result after the call.441* @return An array containing the new decorations identifiers.442*/443deltaDecorations(oldDecorations: readonly string[], newDecorations: readonly IModelDeltaDecoration[]): string[];444}445446/**447* End of line character preference.448*/449export const enum EndOfLinePreference {450/**451* Use the end of line character identified in the text buffer.452*/453TextDefined = 0,454/**455* Use line feed (\n) as the end of line character.456*/457LF = 1,458/**459* Use carriage return and line feed (\r\n) as the end of line character.460*/461CRLF = 2462}463464/**465* The default end of line to use when instantiating models.466*/467export const enum DefaultEndOfLine {468/**469* Use line feed (\n) as the end of line character.470*/471LF = 1,472/**473* Use carriage return and line feed (\r\n) as the end of line character.474*/475CRLF = 2476}477478/**479* End of line character preference.480*/481export const enum EndOfLineSequence {482/**483* Use line feed (\n) as the end of line character.484*/485LF = 0,486/**487* Use carriage return and line feed (\r\n) as the end of line character.488*/489CRLF = 1490}491492/**493* An identifier for a single edit operation.494* @internal495*/496export interface ISingleEditOperationIdentifier {497/**498* Identifier major499*/500major: number;501/**502* Identifier minor503*/504minor: number;505}506507/**508* A single edit operation, that has an identifier.509*/510export interface IIdentifiedSingleEditOperation extends ISingleEditOperation {511/**512* An identifier associated with this single edit operation.513* @internal514*/515identifier?: ISingleEditOperationIdentifier | null;516/**517* This indicates that this operation is inserting automatic whitespace518* that can be removed on next model edit operation if `config.trimAutoWhitespace` is true.519* @internal520*/521isAutoWhitespaceEdit?: boolean;522/**523* This indicates that this operation is in a set of operations that are tracked and should not be "simplified".524* @internal525*/526_isTracked?: boolean;527}528529export interface IValidEditOperation {530/**531* An identifier associated with this single edit operation.532* @internal533*/534identifier: ISingleEditOperationIdentifier | null;535/**536* The range to replace. This can be empty to emulate a simple insert.537*/538range: Range;539/**540* The text to replace with. This can be empty to emulate a simple delete.541*/542text: string;543/**544* @internal545*/546textChange: TextChange;547}548549/**550* A callback that can compute the cursor state after applying a series of edit operations.551*/552export interface ICursorStateComputer {553/**554* A callback that can compute the resulting cursors state after some edit operations have been executed.555*/556(inverseEditOperations: IValidEditOperation[]): Selection[] | null;557}558559export class TextModelResolvedOptions {560_textModelResolvedOptionsBrand: void = undefined;561562readonly tabSize: number;563readonly indentSize: number;564private readonly _indentSizeIsTabSize: boolean;565readonly insertSpaces: boolean;566readonly defaultEOL: DefaultEndOfLine;567readonly trimAutoWhitespace: boolean;568readonly bracketPairColorizationOptions: BracketPairColorizationOptions;569570public get originalIndentSize(): number | 'tabSize' {571return this._indentSizeIsTabSize ? 'tabSize' : this.indentSize;572}573574/**575* @internal576*/577constructor(src: {578tabSize: number;579indentSize: number | 'tabSize';580insertSpaces: boolean;581defaultEOL: DefaultEndOfLine;582trimAutoWhitespace: boolean;583bracketPairColorizationOptions: BracketPairColorizationOptions;584}) {585this.tabSize = Math.max(1, src.tabSize | 0);586if (src.indentSize === 'tabSize') {587this.indentSize = this.tabSize;588this._indentSizeIsTabSize = true;589} else {590this.indentSize = Math.max(1, src.indentSize | 0);591this._indentSizeIsTabSize = false;592}593this.insertSpaces = Boolean(src.insertSpaces);594this.defaultEOL = src.defaultEOL | 0;595this.trimAutoWhitespace = Boolean(src.trimAutoWhitespace);596this.bracketPairColorizationOptions = src.bracketPairColorizationOptions;597}598599/**600* @internal601*/602public equals(other: TextModelResolvedOptions): boolean {603return (604this.tabSize === other.tabSize605&& this._indentSizeIsTabSize === other._indentSizeIsTabSize606&& this.indentSize === other.indentSize607&& this.insertSpaces === other.insertSpaces608&& this.defaultEOL === other.defaultEOL609&& this.trimAutoWhitespace === other.trimAutoWhitespace610&& equals(this.bracketPairColorizationOptions, other.bracketPairColorizationOptions)611);612}613614/**615* @internal616*/617public createChangeEvent(newOpts: TextModelResolvedOptions): IModelOptionsChangedEvent {618return {619tabSize: this.tabSize !== newOpts.tabSize,620indentSize: this.indentSize !== newOpts.indentSize,621insertSpaces: this.insertSpaces !== newOpts.insertSpaces,622trimAutoWhitespace: this.trimAutoWhitespace !== newOpts.trimAutoWhitespace,623};624}625}626627/**628* @internal629*/630export interface ITextModelCreationOptions {631tabSize: number;632indentSize: number | 'tabSize';633insertSpaces: boolean;634detectIndentation: boolean;635trimAutoWhitespace: boolean;636defaultEOL: DefaultEndOfLine;637isForSimpleWidget: boolean;638largeFileOptimizations: boolean;639bracketPairColorizationOptions: BracketPairColorizationOptions;640}641642export interface BracketPairColorizationOptions {643enabled: boolean;644independentColorPoolPerBracketType: boolean;645}646647export interface ITextModelUpdateOptions {648tabSize?: number;649indentSize?: number | 'tabSize';650insertSpaces?: boolean;651trimAutoWhitespace?: boolean;652bracketColorizationOptions?: BracketPairColorizationOptions;653}654655export class FindMatch {656_findMatchBrand: void = undefined;657658public readonly range: Range;659public readonly matches: string[] | null;660661/**662* @internal663*/664constructor(range: Range, matches: string[] | null) {665this.range = range;666this.matches = matches;667}668}669670/**671* Describes the behavior of decorations when typing/editing near their edges.672* Note: Please do not edit the values, as they very carefully match `DecorationRangeBehavior`673*/674export const enum TrackedRangeStickiness {675AlwaysGrowsWhenTypingAtEdges = 0,676NeverGrowsWhenTypingAtEdges = 1,677GrowsOnlyWhenTypingBefore = 2,678GrowsOnlyWhenTypingAfter = 3,679}680681/**682* Text snapshot that works like an iterator.683* Will try to return chunks of roughly ~64KB size.684* Will return null when finished.685*/686export interface ITextSnapshot {687read(): string | null;688}689690/**691* @internal692*/693export function isITextSnapshot(obj: unknown): obj is ITextSnapshot {694return (!!obj && typeof (obj as ITextSnapshot).read === 'function');695}696697/**698* A model.699*/700export interface ITextModel {701702/**703* Gets the resource associated with this editor model.704*/705readonly uri: URI;706707/**708* A unique identifier associated with this model.709*/710readonly id: string;711712/**713* This model is constructed for a simple widget code editor.714* @internal715*/716readonly isForSimpleWidget: boolean;717718/**719* Method to register a view model on a model720* @internal721*/722registerViewModel(viewModel: IViewModel): void;723724/**725* Method which unregister a view model on a model726* @internal727*/728unregisterViewModel(viewModel: IViewModel): void;729730/**731* If true, the text model might contain RTL.732* If false, the text model **contains only** contain LTR.733* @internal734*/735mightContainRTL(): boolean;736737/**738* If true, the text model might contain LINE SEPARATOR (LS), PARAGRAPH SEPARATOR (PS).739* If false, the text model definitely does not contain these.740* @internal741*/742mightContainUnusualLineTerminators(): boolean;743744/**745* @internal746*/747removeUnusualLineTerminators(selections?: Selection[]): void;748749/**750* If true, the text model might contain non basic ASCII.751* If false, the text model **contains only** basic ASCII.752* @internal753*/754mightContainNonBasicASCII(): boolean;755756/**757* Get the resolved options for this model.758*/759getOptions(): TextModelResolvedOptions;760761/**762* Get the formatting options for this model.763* @internal764*/765getFormattingOptions(): FormattingOptions;766767/**768* Get the current version id of the model.769* Anytime a change happens to the model (even undo/redo),770* the version id is incremented.771*/772getVersionId(): number;773774/**775* Get the alternative version id of the model.776* This alternative version id is not always incremented,777* it will return the same values in the case of undo-redo.778*/779getAlternativeVersionId(): number;780781/**782* Replace the entire text buffer value contained in this model.783*/784setValue(newValue: string | ITextSnapshot): void;785786/**787* Get the text stored in this model.788* @param eol The end of line character preference. Defaults to `EndOfLinePreference.TextDefined`.789* @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.790* @return The text.791*/792getValue(eol?: EndOfLinePreference, preserveBOM?: boolean): string;793794/**795* Get the text stored in this model.796* @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.797* @return The text snapshot (it is safe to consume it asynchronously).798*/799createSnapshot(preserveBOM?: boolean): ITextSnapshot;800801/**802* Get the length of the text stored in this model.803*/804getValueLength(eol?: EndOfLinePreference, preserveBOM?: boolean): number;805806/**807* Check if the raw text stored in this model equals another raw text.808* @internal809*/810equalsTextBuffer(other: ITextBuffer): boolean;811812/**813* Get the underling text buffer.814* @internal815*/816getTextBuffer(): ITextBuffer;817818/**819* Get the text in a certain range.820* @param range The range describing what text to get.821* @param eol The end of line character preference. This will only be used for multiline ranges. Defaults to `EndOfLinePreference.TextDefined`.822* @return The text.823*/824getValueInRange(range: IRange, eol?: EndOfLinePreference): string;825826/**827* Get the length of text in a certain range.828* @param range The range describing what text length to get.829* @return The text length.830*/831getValueLengthInRange(range: IRange, eol?: EndOfLinePreference): number;832833/**834* Get the character count of text in a certain range.835* @param range The range describing what text length to get.836*/837getCharacterCountInRange(range: IRange, eol?: EndOfLinePreference): number;838839/**840* Splits characters in two buckets. First bucket (A) is of characters that841* sit in lines with length < `LONG_LINE_BOUNDARY`. Second bucket (B) is of842* characters that sit in lines with length >= `LONG_LINE_BOUNDARY`.843* If count(B) > count(A) return true. Returns false otherwise.844* @internal845*/846isDominatedByLongLines(): boolean;847848/**849* Get the number of lines in the model.850*/851getLineCount(): number;852853/**854* Get the text for a certain line.855*/856getLineContent(lineNumber: number): string;857858/**859* Get the text length for a certain line.860*/861getLineLength(lineNumber: number): number;862863/**864* Get the text for all lines.865*/866getLinesContent(): string[];867868/**869* Get the end of line sequence predominantly used in the text buffer.870* @return EOL char sequence (e.g.: '\n' or '\r\n').871*/872getEOL(): string;873874/**875* Get the end of line sequence predominantly used in the text buffer.876*/877getEndOfLineSequence(): EndOfLineSequence;878879/**880* Get the minimum legal column for line at `lineNumber`881*/882getLineMinColumn(lineNumber: number): number;883884/**885* Get the maximum legal column for line at `lineNumber`886*/887getLineMaxColumn(lineNumber: number): number;888889/**890* Returns the column before the first non whitespace character for line at `lineNumber`.891* Returns 0 if line is empty or contains only whitespace.892*/893getLineFirstNonWhitespaceColumn(lineNumber: number): number;894895/**896* Returns the column after the last non whitespace character for line at `lineNumber`.897* Returns 0 if line is empty or contains only whitespace.898*/899getLineLastNonWhitespaceColumn(lineNumber: number): number;900901/**902* Create a valid position.903*/904validatePosition(position: IPosition): Position;905906/**907* Advances the given position by the given offset (negative offsets are also accepted)908* and returns it as a new valid position.909*910* If the offset and position are such that their combination goes beyond the beginning or911* end of the model, throws an exception.912*913* If the offset is such that the new position would be in the middle of a multi-byte914* line terminator, throws an exception.915*/916modifyPosition(position: IPosition, offset: number): Position;917918/**919* Create a valid range.920*/921validateRange(range: IRange): Range;922923/**924* Verifies the range is valid.925*/926isValidRange(range: IRange): boolean;927928/**929* Converts the position to a zero-based offset.930*931* The position will be [adjusted](#TextDocument.validatePosition).932*933* @param position A position.934* @return A valid zero-based offset.935*/936getOffsetAt(position: IPosition): number;937938/**939* Converts a zero-based offset to a position.940*941* @param offset A zero-based offset.942* @return A valid [position](#Position).943*/944getPositionAt(offset: number): Position;945946/**947* Get a range covering the entire model.948*/949getFullModelRange(): Range;950951/**952* Returns if the model was disposed or not.953*/954isDisposed(): boolean;955956/**957* This model is so large that it would not be a good idea to sync it over958* to web workers or other places.959* @internal960*/961isTooLargeForSyncing(): boolean;962963/**964* The file is so large, that even tokenization is disabled.965* @internal966*/967isTooLargeForTokenization(): boolean;968969/**970* The file is so large, that operations on it might be too large for heap971* and can lead to OOM crashes so they should be disabled.972* @internal973*/974isTooLargeForHeapOperation(): boolean;975976/**977* Search the model.978* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.979* @param searchOnlyEditableRange Limit the searching to only search inside the editable range of the model.980* @param isRegex Used to indicate that `searchString` is a regular expression.981* @param matchCase Force the matching to match lower/upper case exactly.982* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.983* @param captureMatches The result will contain the captured groups.984* @param limitResultCount Limit the number of results985* @return The ranges where the matches are. It is empty if not matches have been found.986*/987findMatches(searchString: string, searchOnlyEditableRange: boolean, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];988/**989* Search the model.990* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.991* @param searchScope Limit the searching to only search inside these ranges.992* @param isRegex Used to indicate that `searchString` is a regular expression.993* @param matchCase Force the matching to match lower/upper case exactly.994* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.995* @param captureMatches The result will contain the captured groups.996* @param limitResultCount Limit the number of results997* @return The ranges where the matches are. It is empty if no matches have been found.998*/999findMatches(searchString: string, searchScope: IRange | IRange[], isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];1000/**1001* Search the model for the next match. Loops to the beginning of the model if needed.1002* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.1003* @param searchStart Start the searching at the specified position.1004* @param isRegex Used to indicate that `searchString` is a regular expression.1005* @param matchCase Force the matching to match lower/upper case exactly.1006* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.1007* @param captureMatches The result will contain the captured groups.1008* @return The range where the next match is. It is null if no next match has been found.1009*/1010findNextMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;1011/**1012* Search the model for the previous match. Loops to the end of the model if needed.1013* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.1014* @param searchStart Start the searching at the specified position.1015* @param isRegex Used to indicate that `searchString` is a regular expression.1016* @param matchCase Force the matching to match lower/upper case exactly.1017* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.1018* @param captureMatches The result will contain the captured groups.1019* @return The range where the previous match is. It is null if no previous match has been found.1020*/1021findPreviousMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;102210231024/**1025* Get the language associated with this model.1026*/1027getLanguageId(): string;10281029/**1030* Set the current language mode associated with the model.1031* @param languageId The new language.1032* @param source The source of the call that set the language.1033* @internal1034*/1035setLanguage(languageId: string, source?: string): void;10361037/**1038* Set the current language mode associated with the model.1039* @param languageSelection The new language selection.1040* @param source The source of the call that set the language.1041* @internal1042*/1043setLanguage(languageSelection: ILanguageSelection, source?: string): void;10441045/**1046* Returns the real (inner-most) language mode at a given position.1047* The result might be inaccurate. Use `forceTokenization` to ensure accurate tokens.1048* @internal1049*/1050getLanguageIdAtPosition(lineNumber: number, column: number): string;10511052/**1053* Get the word under or besides `position`.1054* @param position The position to look for a word.1055* @return The word under or besides `position`. Might be null.1056*/1057getWordAtPosition(position: IPosition): IWordAtPosition | null;10581059/**1060* Get the word under or besides `position` trimmed to `position`.column1061* @param position The position to look for a word.1062* @return The word under or besides `position`. Will never be null.1063*/1064getWordUntilPosition(position: IPosition): IWordAtPosition;10651066/**1067* Change the decorations. The callback will be called with a change accessor1068* that becomes invalid as soon as the callback finishes executing.1069* This allows for all events to be queued up until the change1070* is completed. Returns whatever the callback returns.1071* @param ownerId Identifies the editor id in which these decorations should appear. If no `ownerId` is provided, the decorations will appear in all editors that attach this model.1072* @internal1073*/1074changeDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T, ownerId?: number): T | null;10751076/**1077* Perform a minimum amount of operations, in order to transform the decorations1078* identified by `oldDecorations` to the decorations described by `newDecorations`1079* and returns the new identifiers associated with the resulting decorations.1080*1081* @param oldDecorations Array containing previous decorations identifiers.1082* @param newDecorations Array describing what decorations should result after the call.1083* @param ownerId Identifies the editor id in which these decorations should appear. If no `ownerId` is provided, the decorations will appear in all editors that attach this model.1084* @return An array containing the new decorations identifiers.1085*/1086deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[], ownerId?: number): string[];10871088/**1089* Remove all decorations that have been added with this specific ownerId.1090* @param ownerId The owner id to search for.1091* @internal1092*/1093removeAllDecorationsWithOwnerId(ownerId: number): void;10941095/**1096* Get the options associated with a decoration.1097* @param id The decoration id.1098* @return The decoration options or null if the decoration was not found.1099*/1100getDecorationOptions(id: string): IModelDecorationOptions | null;11011102/**1103* Get the range associated with a decoration.1104* @param id The decoration id.1105* @return The decoration range or null if the decoration was not found.1106*/1107getDecorationRange(id: string): Range | null;11081109/**1110* Gets all the decorations for the line `lineNumber` as an array.1111* @param lineNumber The line number1112* @param ownerId If set, it will ignore decorations belonging to other owners.1113* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1114* @param filterFontDecorations If set, it will ignore font decorations.1115* @return An array with the decorations1116*/1117getLineDecorations(lineNumber: number, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11181119/**1120* Gets all the font decorations for the line `lineNumber` as an array.1121* @param ownerId If set, it will ignore decorations belonging to other owners.1122* @internal1123*/1124getFontDecorationsInRange(range: IRange, ownerId?: number): IModelDecoration[];11251126/**1127* Gets all the decorations for the lines between `startLineNumber` and `endLineNumber` as an array.1128* @param startLineNumber The start line number1129* @param endLineNumber The end line number1130* @param ownerId If set, it will ignore decorations belonging to other owners.1131* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1132* @param filterFontDecorations If set, it will ignore font decorations.1133* @return An array with the decorations1134*/1135getLinesDecorations(startLineNumber: number, endLineNumber: number, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11361137/**1138* Gets all the decorations in a range as an array. Only `startLineNumber` and `endLineNumber` from `range` are used for filtering.1139* So for now it returns all the decorations on the same line as `range`.1140* @param range The range to search in1141* @param ownerId If set, it will ignore decorations belonging to other owners.1142* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1143* @param filterFontDecorations If set, it will ignore font decorations.1144* @param onlyMinimapDecorations If set, it will return only decorations that render in the minimap.1145* @param onlyMarginDecorations If set, it will return only decorations that render in the glyph margin.1146* @return An array with the decorations1147*/1148getDecorationsInRange(range: IRange, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean, onlyMinimapDecorations?: boolean, onlyMarginDecorations?: boolean): IModelDecoration[];11491150/**1151* Gets all the decorations as an array.1152* @param ownerId If set, it will ignore decorations belonging to other owners.1153* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1154* @param filterFontDecorations If set, it will ignore font decorations.1155*/1156getAllDecorations(ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11571158/**1159* Gets all decorations that render in the glyph margin as an array.1160* @param ownerId If set, it will ignore decorations belonging to other owners.1161*/1162getAllMarginDecorations(ownerId?: number): IModelDecoration[];11631164/**1165* Gets all the decorations that should be rendered in the overview ruler as an array.1166* @param ownerId If set, it will ignore decorations belonging to other owners.1167* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1168* @param filterFontDecorations If set, it will ignore font decorations.1169*/1170getOverviewRulerDecorations(ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11711172/**1173* Gets all the decorations that contain injected text.1174* @param ownerId If set, it will ignore decorations belonging to other owners.1175*/1176getInjectedTextDecorations(ownerId?: number): IModelDecoration[];11771178/**1179* Gets all the decorations that contain custom line heights.1180* @param ownerId If set, it will ignore decorations belonging to other owners.1181*/1182getCustomLineHeightsDecorations(ownerId?: number): IModelDecoration[];11831184/**1185* @internal1186*/1187_getTrackedRange(id: string): Range | null;11881189/**1190* @internal1191*/1192_setTrackedRange(id: string | null, newRange: null, newStickiness: TrackedRangeStickiness): null;1193/**1194* @internal1195*/1196_setTrackedRange(id: string | null, newRange: Range, newStickiness: TrackedRangeStickiness): string;11971198/**1199* Normalize a string containing whitespace according to indentation rules (converts to spaces or to tabs).1200*/1201normalizeIndentation(str: string): string;12021203/**1204* Change the options of this model.1205*/1206updateOptions(newOpts: ITextModelUpdateOptions): void;12071208/**1209* Detect the indentation options for this model from its content.1210*/1211detectIndentation(defaultInsertSpaces: boolean, defaultTabSize: number): void;12121213/**1214* Close the current undo-redo element.1215* This offers a way to create an undo/redo stop point.1216*/1217pushStackElement(): void;12181219/**1220* Open the current undo-redo element.1221* This offers a way to remove the current undo/redo stop point.1222*/1223popStackElement(): void;12241225/**1226* @internal1227*/1228edit(edit: TextEdit, options?: { reason?: TextModelEditSource }): void;12291230/**1231* Push edit operations, basically editing the model. This is the preferred way1232* of editing the model. The edit operations will land on the undo stack.1233* @param beforeCursorState The cursor state before the edit operations. This cursor state will be returned when `undo` or `redo` are invoked.1234* @param editOperations The edit operations.1235* @param cursorStateComputer A callback that can compute the resulting cursors state after the edit operations have been executed.1236* @return The cursor state returned by the `cursorStateComputer`.1237*/1238pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;1239/**1240* @internal1241*/1242pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer, group?: UndoRedoGroup, reason?: TextModelEditSource): Selection[] | null;12431244/**1245* Change the end of line sequence. This is the preferred way of1246* changing the eol sequence. This will land on the undo stack.1247*/1248pushEOL(eol: EndOfLineSequence): void;12491250/**1251* Edit the model without adding the edits to the undo stack.1252* This can have dire consequences on the undo stack! See @pushEditOperations for the preferred way.1253* @param operations The edit operations.1254* @return If desired, the inverse edit operations, that, when applied, will bring the model back to the previous state.1255*/1256applyEdits(operations: readonly IIdentifiedSingleEditOperation[]): void;1257/** @internal */1258applyEdits(operations: readonly IIdentifiedSingleEditOperation[], reason: TextModelEditSource): void;1259applyEdits(operations: readonly IIdentifiedSingleEditOperation[], computeUndoEdits: false): void;1260applyEdits(operations: readonly IIdentifiedSingleEditOperation[], computeUndoEdits: true): IValidEditOperation[];12611262/**1263* Change the end of line sequence without recording in the undo stack.1264* This can have dire consequences on the undo stack! See @pushEOL for the preferred way.1265*/1266setEOL(eol: EndOfLineSequence): void;12671268/**1269* @internal1270*/1271_applyUndo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;12721273/**1274* @internal1275*/1276_applyRedo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;12771278/**1279* Undo edit operations until the previous undo/redo point.1280* The inverse edit operations will be pushed on the redo stack.1281*/1282undo(): void | Promise<void>;12831284/**1285* Is there anything in the undo stack?1286*/1287canUndo(): boolean;12881289/**1290* Redo edit operations until the next undo/redo point.1291* The inverse edit operations will be pushed on the undo stack.1292*/1293redo(): void | Promise<void>;12941295/**1296* Is there anything in the redo stack?1297*/1298canRedo(): boolean;12991300/**1301* An event emitted when the contents of the model have changed.1302* @event1303*/1304onDidChangeContent(listener: (e: IModelContentChangedEvent) => void): IDisposable;1305/**1306* An event emitted when decorations of the model have changed.1307* @event1308*/1309readonly onDidChangeDecorations: Event<IModelDecorationsChangedEvent>;1310/**1311* An event emitted when line heights from decorations changes.1312* This event is emitted only when adding, removing or changing a decoration1313* and not when doing edits in the model (i.e. when decoration ranges change)1314* @internal1315* @event1316*/1317readonly onDidChangeLineHeight: Event<ModelLineHeightChangedEvent>;1318/**1319* An event emitted when the font from decorations changes.1320* This event is emitted only when adding, removing or changing a decoration1321* and not when doing edits in the model (i.e. when decoration ranges change)1322* @internal1323* @event1324*/1325readonly onDidChangeFont: Event<ModelFontChangedEvent>;1326/**1327* An event emitted when the model options have changed.1328* @event1329*/1330readonly onDidChangeOptions: Event<IModelOptionsChangedEvent>;1331/**1332* An event emitted when the language associated with the model has changed.1333* @event1334*/1335readonly onDidChangeLanguage: Event<IModelLanguageChangedEvent>;1336/**1337* An event emitted when the language configuration associated with the model has changed.1338* @event1339*/1340readonly onDidChangeLanguageConfiguration: Event<IModelLanguageConfigurationChangedEvent>;1341/**1342* An event emitted when the tokens associated with the model have changed.1343* @event1344* @internal1345*/1346readonly onDidChangeTokens: Event<IModelTokensChangedEvent>;1347/**1348* An event emitted when the model has been attached to the first editor or detached from the last editor.1349* @event1350*/1351readonly onDidChangeAttached: Event<void>;1352/**1353* An event emitted right before disposing the model.1354* @event1355*/1356readonly onWillDispose: Event<void>;13571358/**1359* Destroy this model.1360*/1361dispose(): void;13621363/**1364* @internal1365*/1366onBeforeAttached(): IAttachedView;13671368/**1369* @internal1370*/1371onBeforeDetached(view: IAttachedView): void;13721373/**1374* Returns if this model is attached to an editor or not.1375*/1376isAttachedToEditor(): boolean;13771378/**1379* Returns the count of editors this model is attached to.1380* @internal1381*/1382getAttachedEditorCount(): number;13831384/**1385* Among all positions that are projected to the same position in the underlying text model as1386* the given position, select a unique position as indicated by the affinity.1387*1388* PositionAffinity.Left:1389* The normalized position must be equal or left to the requested position.1390*1391* PositionAffinity.Right:1392* The normalized position must be equal or right to the requested position.1393*1394* @internal1395*/1396normalizePosition(position: Position, affinity: PositionAffinity): Position;13971398/**1399* Gets the column at which indentation stops at a given line.1400* @internal1401*/1402getLineIndentColumn(lineNumber: number): number;14031404/**1405* Returns an object that can be used to query brackets.1406* @internal1407*/1408readonly bracketPairs: IBracketPairsTextModelPart;14091410/**1411* Returns an object that can be used to query indent guides.1412* @internal1413*/1414readonly guides: IGuidesTextModelPart;14151416/**1417* @internal1418*/1419readonly tokenization: ITokenizationTextModelPart;1420}14211422/**1423* @internal1424*/1425export function isITextModel(obj: IEditorModel): obj is ITextModel {1426return Boolean(obj && (obj as ITextModel).uri);1427}14281429/**1430* @internal1431*/1432export interface IAttachedView {1433/**1434* @param stabilized Indicates if the visible lines are probably going to change soon or can be considered stable.1435* Is true on reveal range and false on scroll.1436* Tokenizers should tokenize synchronously if stabilized is true.1437*/1438setVisibleLines(visibleLines: { startLineNumber: number; endLineNumber: number }[], stabilized: boolean): void;1439}14401441export const enum PositionAffinity {1442/**1443* Prefers the left most position.1444*/1445Left = 0,14461447/**1448* Prefers the right most position.1449*/1450Right = 1,14511452/**1453* No preference.1454*/1455None = 2,14561457/**1458* If the given position is on injected text, prefers the position left of it.1459*/1460LeftOfInjectedText = 3,14611462/**1463* If the given position is on injected text, prefers the position right of it.1464*/1465RightOfInjectedText = 4,1466}14671468/**1469* @internal1470*/1471export interface ITextBufferBuilder {1472acceptChunk(chunk: string): void;1473finish(): ITextBufferFactory;1474}14751476/**1477* @internal1478*/1479export interface ITextBufferFactory {1480create(defaultEOL: DefaultEndOfLine): { textBuffer: ITextBuffer; disposable: IDisposable };1481getFirstLineText(lengthLimit: number): string;1482}14831484/**1485* @internal1486*/1487export const enum ModelConstants {1488FIRST_LINE_DETECTION_LENGTH_LIMIT = 10001489}14901491/**1492* @internal1493*/1494export class ValidAnnotatedEditOperation implements IIdentifiedSingleEditOperation {1495constructor(1496public readonly identifier: ISingleEditOperationIdentifier | null,1497public readonly range: Range,1498public readonly text: string | null,1499public readonly forceMoveMarkers: boolean,1500public readonly isAutoWhitespaceEdit: boolean,1501public readonly _isTracked: boolean,1502) { }1503}15041505/**1506* @internal1507*1508* `lineNumber` is 1 based.1509*/1510export interface IReadonlyTextBuffer {1511readonly onDidChangeContent: Event<void>;1512equals(other: ITextBuffer): boolean;1513mightContainRTL(): boolean;1514mightContainUnusualLineTerminators(): boolean;1515resetMightContainUnusualLineTerminators(): void;1516mightContainNonBasicASCII(): boolean;1517getBOM(): string;1518getEOL(): string;15191520getOffsetAt(lineNumber: number, column: number): number;1521getPositionAt(offset: number): Position;1522getRangeAt(offset: number, length: number): Range;15231524getValueInRange(range: Range, eol: EndOfLinePreference): string;1525createSnapshot(preserveBOM: boolean): ITextSnapshot;1526getValueLengthInRange(range: Range, eol: EndOfLinePreference): number;1527getCharacterCountInRange(range: Range, eol: EndOfLinePreference): number;1528getLength(): number;1529getLineCount(): number;1530getLinesContent(): string[];1531getLineContent(lineNumber: number): string;1532getLineCharCode(lineNumber: number, index: number): number;1533getCharCode(offset: number): number;1534getLineLength(lineNumber: number): number;1535getLineMinColumn(lineNumber: number): number;1536getLineMaxColumn(lineNumber: number): number;1537getLineFirstNonWhitespaceColumn(lineNumber: number): number;1538getLineLastNonWhitespaceColumn(lineNumber: number): number;1539findMatchesLineByLine(searchRange: Range, searchData: SearchData, captureMatches: boolean, limitResultCount: number): FindMatch[];15401541/**1542* Get nearest chunk of text after `offset` in the text buffer.1543*/1544getNearestChunk(offset: number): string;1545}15461547/**1548* @internal1549*/1550export class SearchData {15511552/**1553* The regex to search for. Always defined.1554*/1555public readonly regex: RegExp;1556/**1557* The word separator classifier.1558*/1559public readonly wordSeparators: WordCharacterClassifier | null;1560/**1561* The simple string to search for (if possible).1562*/1563public readonly simpleSearch: string | null;15641565constructor(regex: RegExp, wordSeparators: WordCharacterClassifier | null, simpleSearch: string | null) {1566this.regex = regex;1567this.wordSeparators = wordSeparators;1568this.simpleSearch = simpleSearch;1569}1570}15711572/**1573* @internal1574*/1575export interface ITextBuffer extends IReadonlyTextBuffer, IDisposable {1576setEOL(newEOL: '\r\n' | '\n'): void;1577applyEdits(rawOperations: ValidAnnotatedEditOperation[], recordTrimAutoWhitespace: boolean, computeUndoEdits: boolean): ApplyEditsResult;1578}15791580/**1581* @internal1582*/1583export class ApplyEditsResult {15841585constructor(1586public readonly reverseEdits: IValidEditOperation[] | null,1587public readonly changes: IInternalModelContentChange[],1588public readonly trimAutoWhitespaceLineNumbers: number[] | null1589) { }15901591}15921593/**1594* @internal1595*/1596export interface IInternalModelContentChange extends IModelContentChange {1597range: Range;1598forceMoveMarkers: boolean;1599}16001601/**1602* @internal1603*/1604export function shouldSynchronizeModel(model: ITextModel): boolean {1605return (1606!model.isTooLargeForSyncing() && !model.isForSimpleWidget1607);1608}160916101611