/*---------------------------------------------------------------------------------------------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, InternalModelContentChangeEvent, ModelFontChangedEvent, ModelInjectedTextChangedEvent, 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';3031/**32* Vertical Lane in the overview ruler of the editor.33*/34export enum OverviewRulerLane {35Left = 1,36Center = 2,37Right = 4,38Full = 739}4041/**42* Vertical Lane in the glyph margin of the editor.43*/44export enum GlyphMarginLane {45Left = 1,46Center = 2,47Right = 3,48}4950export interface IGlyphMarginLanesModel {51/**52* The number of lanes that should be rendered in the editor.53*/54readonly requiredLanes: number;5556/**57* Gets the lanes that should be rendered starting at a given line number.58*/59getLanesAtLine(lineNumber: number): GlyphMarginLane[];6061/**62* Resets the model and ensures it can contain at least `maxLine` lines.63*/64reset(maxLine: number): void;6566/**67* Registers that a lane should be visible at the Range in the model.68* @param persist - if true, notes that the lane should always be visible,69* even on lines where there's no specific request for that lane.70*/71push(lane: GlyphMarginLane, range: Range, persist?: boolean): void;72}7374/**75* Position in the minimap to render the decoration.76*/77export const enum MinimapPosition {78Inline = 1,79Gutter = 280}8182/**83* Section header style.84*/85export const enum MinimapSectionHeaderStyle {86Normal = 1,87Underlined = 288}8990export interface IDecorationOptions {91/**92* CSS color to render.93* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry94*/95color: string | ThemeColor | undefined;96/**97* CSS color to render.98* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry99*/100darkColor?: string | ThemeColor;101}102103export interface IModelDecorationGlyphMarginOptions {104/**105* The position in the glyph margin.106*/107position: GlyphMarginLane;108109/**110* Whether the glyph margin lane in {@link position} should be rendered even111* outside of this decoration's range.112*/113persistLane?: boolean;114}115116/**117* Options for rendering a model decoration in the overview ruler.118*/119export interface IModelDecorationOverviewRulerOptions extends IDecorationOptions {120/**121* The position in the overview ruler.122*/123position: OverviewRulerLane;124}125126/**127* Options for rendering a model decoration in the minimap.128*/129export interface IModelDecorationMinimapOptions extends IDecorationOptions {130/**131* The position in the minimap.132*/133position: MinimapPosition;134/**135* If the decoration is for a section header, which header style.136*/137sectionHeaderStyle?: MinimapSectionHeaderStyle | null;138/**139* If the decoration is for a section header, the header text.140*/141sectionHeaderText?: string | null;142}143144/**145* Options for a model decoration.146*/147export interface IModelDecorationOptions {148/**149* A debug description that can be used for inspecting model decorations.150* @internal151*/152description: string;153/**154* Customize the growing behavior of the decoration when typing at the edges of the decoration.155* Defaults to TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges156*/157stickiness?: TrackedRangeStickiness;158/**159* CSS class name describing the decoration.160*/161className?: string | null;162/**163* Indicates whether the decoration should span across the entire line when it continues onto the next line.164*/165shouldFillLineOnLineBreak?: boolean | null;166blockClassName?: string | null;167/**168* Indicates if this block should be rendered after the last line.169* In this case, the range must be empty and set to the last line.170*/171blockIsAfterEnd?: boolean | null;172blockDoesNotCollapse?: boolean | null;173blockPadding?: [top: number, right: number, bottom: number, left: number] | null;174175/**176* Message to be rendered when hovering over the glyph margin decoration.177*/178glyphMarginHoverMessage?: IMarkdownString | IMarkdownString[] | null;179/**180* Array of MarkdownString to render as the decoration message.181*/182hoverMessage?: IMarkdownString | IMarkdownString[] | null;183/**184* Array of MarkdownString to render as the line number message.185*/186lineNumberHoverMessage?: IMarkdownString | IMarkdownString[] | null;187/**188* Should the decoration expand to encompass a whole line.189*/190isWholeLine?: boolean;191/**192* Always render the decoration (even when the range it encompasses is collapsed).193*/194showIfCollapsed?: boolean;195/**196* Collapse the decoration if its entire range is being replaced via an edit.197* @internal198*/199collapseOnReplaceEdit?: boolean;200/**201* Specifies the stack order of a decoration.202* A decoration with greater stack order is always in front of a decoration with203* a lower stack order when the decorations are on the same line.204*/205zIndex?: number;206/**207* If set, render this decoration in the overview ruler.208*/209overviewRuler?: IModelDecorationOverviewRulerOptions | null;210/**211* If set, render this decoration in the minimap.212*/213minimap?: IModelDecorationMinimapOptions | null;214/**215* If set, the decoration will be rendered in the glyph margin with this CSS class name.216*/217glyphMarginClassName?: string | null;218/**219* If set and the decoration has {@link glyphMarginClassName} set, render this decoration220* with the specified {@link IModelDecorationGlyphMarginOptions} in the glyph margin.221*/222glyphMargin?: IModelDecorationGlyphMarginOptions | null;223/**224* If set, the decoration will override the line height of the lines it spans. Maximum value is 300px.225*/226lineHeight?: number | null;227/**228* Font family229*/230fontFamily?: string | null;231/**232* Font size233*/234fontSize?: string | null;235/**236* Font weight237*/238fontWeight?: string | null;239/**240* Font style241*/242fontStyle?: string | null;243/**244* If set, the decoration will be rendered in the lines decorations with this CSS class name.245*/246linesDecorationsClassName?: string | null;247/**248* Controls the tooltip text of the line decoration.249*/250linesDecorationsTooltip?: string | null;251/**252* If set, the decoration will be rendered on the line number.253*/254lineNumberClassName?: string | null;255/**256* 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.257*/258firstLineDecorationClassName?: string | null;259/**260* If set, the decoration will be rendered in the margin (covering its full width) with this CSS class name.261*/262marginClassName?: string | null;263/**264* If set, the decoration will be rendered inline with the text with this CSS class name.265* Please use this only for CSS rules that must impact the text. For example, use `className`266* to have a background color decoration.267*/268inlineClassName?: string | null;269/**270* If there is an `inlineClassName` which affects letter spacing.271*/272inlineClassNameAffectsLetterSpacing?: boolean;273/**274* If set, the decoration will be rendered before the text with this CSS class name.275*/276beforeContentClassName?: string | null;277/**278* If set, the decoration will be rendered after the text with this CSS class name.279*/280afterContentClassName?: string | null;281/**282* If set, text will be injected in the view after the range.283*/284after?: InjectedTextOptions | null;285286/**287* If set, text will be injected in the view before the range.288*/289before?: InjectedTextOptions | null;290291/**292* If set, this decoration will not be rendered for comment tokens.293* @internal294*/295hideInCommentTokens?: boolean | null;296297/**298* If set, this decoration will not be rendered for string tokens.299* @internal300*/301hideInStringTokens?: boolean | null;302303/**304* Whether the decoration affects the font.305* @internal306*/307affectsFont?: boolean | null;308309/**310* The text direction of the decoration.311*/312textDirection?: TextDirection | null;313}314315/**316* Text Direction for a decoration.317*/318export enum TextDirection {319LTR = 0,320321RTL = 1,322}323324/**325* Configures text that is injected into the view without changing the underlying document.326*/327export interface InjectedTextOptions {328/**329* Sets the text to inject. Must be a single line.330*/331readonly content: string;332333/**334* @internal335*/336readonly tokens?: TokenArray | null;337338/**339* If set, the decoration will be rendered inline with the text with this CSS class name.340*/341readonly inlineClassName?: string | null;342343/**344* If there is an `inlineClassName` which affects letter spacing.345*/346readonly inlineClassNameAffectsLetterSpacing?: boolean;347348/**349* This field allows to attach data to this injected text.350* The data can be read when injected texts at a given position are queried.351*/352readonly attachedData?: unknown;353354/**355* Configures cursor stops around injected text.356* Defaults to {@link InjectedTextCursorStops.Both}.357*/358readonly cursorStops?: InjectedTextCursorStops | null;359}360361export enum InjectedTextCursorStops {362Both,363Right,364Left,365None366}367368/**369* New model decorations.370*/371export interface IModelDeltaDecoration {372/**373* Range that this decoration covers.374*/375range: IRange;376/**377* Options associated with this decoration.378*/379options: IModelDecorationOptions;380}381382/**383* A decoration in the model.384*/385export interface IModelDecoration {386/**387* Identifier for a decoration.388*/389readonly id: string;390/**391* Identifier for a decoration's owner.392*/393readonly ownerId: number;394/**395* Range that this decoration covers.396*/397readonly range: Range;398/**399* Options associated with this decoration.400*/401readonly options: IModelDecorationOptions;402}403404/**405* An accessor that can add, change or remove model decorations.406* @internal407*/408export interface IModelDecorationsChangeAccessor {409/**410* Add a new decoration.411* @param range Range that this decoration covers.412* @param options Options associated with this decoration.413* @return An unique identifier associated with this decoration.414*/415addDecoration(range: IRange, options: IModelDecorationOptions): string;416/**417* Change the range that an existing decoration covers.418* @param id The unique identifier associated with the decoration.419* @param newRange The new range that this decoration covers.420*/421changeDecoration(id: string, newRange: IRange): void;422/**423* Change the options associated with an existing decoration.424* @param id The unique identifier associated with the decoration.425* @param newOptions The new options associated with this decoration.426*/427changeDecorationOptions(id: string, newOptions: IModelDecorationOptions): void;428/**429* Remove an existing decoration.430* @param id The unique identifier associated with the decoration.431*/432removeDecoration(id: string): void;433/**434* Perform a minimum amount of operations, in order to transform the decorations435* identified by `oldDecorations` to the decorations described by `newDecorations`436* and returns the new identifiers associated with the resulting decorations.437*438* @param oldDecorations Array containing previous decorations identifiers.439* @param newDecorations Array describing what decorations should result after the call.440* @return An array containing the new decorations identifiers.441*/442deltaDecorations(oldDecorations: readonly string[], newDecorations: readonly IModelDeltaDecoration[]): string[];443}444445/**446* End of line character preference.447*/448export const enum EndOfLinePreference {449/**450* Use the end of line character identified in the text buffer.451*/452TextDefined = 0,453/**454* Use line feed (\n) as the end of line character.455*/456LF = 1,457/**458* Use carriage return and line feed (\r\n) as the end of line character.459*/460CRLF = 2461}462463/**464* The default end of line to use when instantiating models.465*/466export const enum DefaultEndOfLine {467/**468* Use line feed (\n) as the end of line character.469*/470LF = 1,471/**472* Use carriage return and line feed (\r\n) as the end of line character.473*/474CRLF = 2475}476477/**478* End of line character preference.479*/480export const enum EndOfLineSequence {481/**482* Use line feed (\n) as the end of line character.483*/484LF = 0,485/**486* Use carriage return and line feed (\r\n) as the end of line character.487*/488CRLF = 1489}490491/**492* An identifier for a single edit operation.493* @internal494*/495export interface ISingleEditOperationIdentifier {496/**497* Identifier major498*/499major: number;500/**501* Identifier minor502*/503minor: number;504}505506/**507* A single edit operation, that has an identifier.508*/509export interface IIdentifiedSingleEditOperation extends ISingleEditOperation {510/**511* An identifier associated with this single edit operation.512* @internal513*/514identifier?: ISingleEditOperationIdentifier | null;515/**516* This indicates that this operation is inserting automatic whitespace517* that can be removed on next model edit operation if `config.trimAutoWhitespace` is true.518* @internal519*/520isAutoWhitespaceEdit?: boolean;521/**522* This indicates that this operation is in a set of operations that are tracked and should not be "simplified".523* @internal524*/525_isTracked?: boolean;526}527528export interface IValidEditOperation {529/**530* An identifier associated with this single edit operation.531* @internal532*/533identifier: ISingleEditOperationIdentifier | null;534/**535* The range to replace. This can be empty to emulate a simple insert.536*/537range: Range;538/**539* The text to replace with. This can be empty to emulate a simple delete.540*/541text: string;542/**543* @internal544*/545textChange: TextChange;546}547548/**549* A callback that can compute the cursor state after applying a series of edit operations.550*/551export interface ICursorStateComputer {552/**553* A callback that can compute the resulting cursors state after some edit operations have been executed.554*/555(inverseEditOperations: IValidEditOperation[]): Selection[] | null;556}557558export class TextModelResolvedOptions {559_textModelResolvedOptionsBrand: void = undefined;560561readonly tabSize: number;562readonly indentSize: number;563private readonly _indentSizeIsTabSize: boolean;564readonly insertSpaces: boolean;565readonly defaultEOL: DefaultEndOfLine;566readonly trimAutoWhitespace: boolean;567readonly bracketPairColorizationOptions: BracketPairColorizationOptions;568569public get originalIndentSize(): number | 'tabSize' {570return this._indentSizeIsTabSize ? 'tabSize' : this.indentSize;571}572573/**574* @internal575*/576constructor(src: {577tabSize: number;578indentSize: number | 'tabSize';579insertSpaces: boolean;580defaultEOL: DefaultEndOfLine;581trimAutoWhitespace: boolean;582bracketPairColorizationOptions: BracketPairColorizationOptions;583}) {584this.tabSize = Math.max(1, src.tabSize | 0);585if (src.indentSize === 'tabSize') {586this.indentSize = this.tabSize;587this._indentSizeIsTabSize = true;588} else {589this.indentSize = Math.max(1, src.indentSize | 0);590this._indentSizeIsTabSize = false;591}592this.insertSpaces = Boolean(src.insertSpaces);593this.defaultEOL = src.defaultEOL | 0;594this.trimAutoWhitespace = Boolean(src.trimAutoWhitespace);595this.bracketPairColorizationOptions = src.bracketPairColorizationOptions;596}597598/**599* @internal600*/601public equals(other: TextModelResolvedOptions): boolean {602return (603this.tabSize === other.tabSize604&& this._indentSizeIsTabSize === other._indentSizeIsTabSize605&& this.indentSize === other.indentSize606&& this.insertSpaces === other.insertSpaces607&& this.defaultEOL === other.defaultEOL608&& this.trimAutoWhitespace === other.trimAutoWhitespace609&& equals(this.bracketPairColorizationOptions, other.bracketPairColorizationOptions)610);611}612613/**614* @internal615*/616public createChangeEvent(newOpts: TextModelResolvedOptions): IModelOptionsChangedEvent {617return {618tabSize: this.tabSize !== newOpts.tabSize,619indentSize: this.indentSize !== newOpts.indentSize,620insertSpaces: this.insertSpaces !== newOpts.insertSpaces,621trimAutoWhitespace: this.trimAutoWhitespace !== newOpts.trimAutoWhitespace,622};623}624}625626/**627* @internal628*/629export interface ITextModelCreationOptions {630tabSize: number;631indentSize: number | 'tabSize';632insertSpaces: boolean;633detectIndentation: boolean;634trimAutoWhitespace: boolean;635defaultEOL: DefaultEndOfLine;636isForSimpleWidget: boolean;637largeFileOptimizations: boolean;638bracketPairColorizationOptions: BracketPairColorizationOptions;639}640641export interface BracketPairColorizationOptions {642enabled: boolean;643independentColorPoolPerBracketType: boolean;644}645646export interface ITextModelUpdateOptions {647tabSize?: number;648indentSize?: number | 'tabSize';649insertSpaces?: boolean;650trimAutoWhitespace?: boolean;651bracketColorizationOptions?: BracketPairColorizationOptions;652}653654export class FindMatch {655_findMatchBrand: void = undefined;656657public readonly range: Range;658public readonly matches: string[] | null;659660/**661* @internal662*/663constructor(range: Range, matches: string[] | null) {664this.range = range;665this.matches = matches;666}667}668669/**670* Describes the behavior of decorations when typing/editing near their edges.671* Note: Please do not edit the values, as they very carefully match `DecorationRangeBehavior`672*/673export const enum TrackedRangeStickiness {674AlwaysGrowsWhenTypingAtEdges = 0,675NeverGrowsWhenTypingAtEdges = 1,676GrowsOnlyWhenTypingBefore = 2,677GrowsOnlyWhenTypingAfter = 3,678}679680/**681* Text snapshot that works like an iterator.682* Will try to return chunks of roughly ~64KB size.683* Will return null when finished.684*/685export interface ITextSnapshot {686read(): string | null;687}688689/**690* @internal691*/692export function isITextSnapshot(obj: any): obj is ITextSnapshot {693return (obj && typeof obj.read === 'function');694}695696/**697* A model.698*/699export interface ITextModel {700701/**702* Gets the resource associated with this editor model.703*/704readonly uri: URI;705706/**707* A unique identifier associated with this model.708*/709readonly id: string;710711/**712* This model is constructed for a simple widget code editor.713* @internal714*/715readonly isForSimpleWidget: boolean;716717/**718* If true, the text model might contain RTL.719* If false, the text model **contains only** contain LTR.720* @internal721*/722mightContainRTL(): boolean;723724/**725* If true, the text model might contain LINE SEPARATOR (LS), PARAGRAPH SEPARATOR (PS).726* If false, the text model definitely does not contain these.727* @internal728*/729mightContainUnusualLineTerminators(): boolean;730731/**732* @internal733*/734removeUnusualLineTerminators(selections?: Selection[]): void;735736/**737* If true, the text model might contain non basic ASCII.738* If false, the text model **contains only** basic ASCII.739* @internal740*/741mightContainNonBasicASCII(): boolean;742743/**744* Get the resolved options for this model.745*/746getOptions(): TextModelResolvedOptions;747748/**749* Get the formatting options for this model.750* @internal751*/752getFormattingOptions(): FormattingOptions;753754/**755* Get the current version id of the model.756* Anytime a change happens to the model (even undo/redo),757* the version id is incremented.758*/759getVersionId(): number;760761/**762* Get the alternative version id of the model.763* This alternative version id is not always incremented,764* it will return the same values in the case of undo-redo.765*/766getAlternativeVersionId(): number;767768/**769* Replace the entire text buffer value contained in this model.770*/771setValue(newValue: string | ITextSnapshot): void;772773/**774* Get the text stored in this model.775* @param eol The end of line character preference. Defaults to `EndOfLinePreference.TextDefined`.776* @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.777* @return The text.778*/779getValue(eol?: EndOfLinePreference, preserveBOM?: boolean): string;780781/**782* Get the text stored in this model.783* @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.784* @return The text snapshot (it is safe to consume it asynchronously).785*/786createSnapshot(preserveBOM?: boolean): ITextSnapshot;787788/**789* Get the length of the text stored in this model.790*/791getValueLength(eol?: EndOfLinePreference, preserveBOM?: boolean): number;792793/**794* Check if the raw text stored in this model equals another raw text.795* @internal796*/797equalsTextBuffer(other: ITextBuffer): boolean;798799/**800* Get the underling text buffer.801* @internal802*/803getTextBuffer(): ITextBuffer;804805/**806* Get the text in a certain range.807* @param range The range describing what text to get.808* @param eol The end of line character preference. This will only be used for multiline ranges. Defaults to `EndOfLinePreference.TextDefined`.809* @return The text.810*/811getValueInRange(range: IRange, eol?: EndOfLinePreference): string;812813/**814* Get the length of text in a certain range.815* @param range The range describing what text length to get.816* @return The text length.817*/818getValueLengthInRange(range: IRange, eol?: EndOfLinePreference): number;819820/**821* Get the character count of text in a certain range.822* @param range The range describing what text length to get.823*/824getCharacterCountInRange(range: IRange, eol?: EndOfLinePreference): number;825826/**827* Splits characters in two buckets. First bucket (A) is of characters that828* sit in lines with length < `LONG_LINE_BOUNDARY`. Second bucket (B) is of829* characters that sit in lines with length >= `LONG_LINE_BOUNDARY`.830* If count(B) > count(A) return true. Returns false otherwise.831* @internal832*/833isDominatedByLongLines(): boolean;834835/**836* Get the number of lines in the model.837*/838getLineCount(): number;839840/**841* Get the text for a certain line.842*/843getLineContent(lineNumber: number): string;844845/**846* Get the text length for a certain line.847*/848getLineLength(lineNumber: number): number;849850/**851* Get the text for all lines.852*/853getLinesContent(): string[];854855/**856* Get the end of line sequence predominantly used in the text buffer.857* @return EOL char sequence (e.g.: '\n' or '\r\n').858*/859getEOL(): string;860861/**862* Get the end of line sequence predominantly used in the text buffer.863*/864getEndOfLineSequence(): EndOfLineSequence;865866/**867* Get the minimum legal column for line at `lineNumber`868*/869getLineMinColumn(lineNumber: number): number;870871/**872* Get the maximum legal column for line at `lineNumber`873*/874getLineMaxColumn(lineNumber: number): number;875876/**877* Returns the column before the first non whitespace character for line at `lineNumber`.878* Returns 0 if line is empty or contains only whitespace.879*/880getLineFirstNonWhitespaceColumn(lineNumber: number): number;881882/**883* Returns the column after the last non whitespace character for line at `lineNumber`.884* Returns 0 if line is empty or contains only whitespace.885*/886getLineLastNonWhitespaceColumn(lineNumber: number): number;887888/**889* Create a valid position.890*/891validatePosition(position: IPosition): Position;892893/**894* Advances the given position by the given offset (negative offsets are also accepted)895* and returns it as a new valid position.896*897* If the offset and position are such that their combination goes beyond the beginning or898* end of the model, throws an exception.899*900* If the offset is such that the new position would be in the middle of a multi-byte901* line terminator, throws an exception.902*/903modifyPosition(position: IPosition, offset: number): Position;904905/**906* Create a valid range.907*/908validateRange(range: IRange): Range;909910/**911* Verifies the range is valid.912*/913isValidRange(range: IRange): boolean;914915/**916* Converts the position to a zero-based offset.917*918* The position will be [adjusted](#TextDocument.validatePosition).919*920* @param position A position.921* @return A valid zero-based offset.922*/923getOffsetAt(position: IPosition): number;924925/**926* Converts a zero-based offset to a position.927*928* @param offset A zero-based offset.929* @return A valid [position](#Position).930*/931getPositionAt(offset: number): Position;932933/**934* Get a range covering the entire model.935*/936getFullModelRange(): Range;937938/**939* Returns if the model was disposed or not.940*/941isDisposed(): boolean;942943/**944* This model is so large that it would not be a good idea to sync it over945* to web workers or other places.946* @internal947*/948isTooLargeForSyncing(): boolean;949950/**951* The file is so large, that even tokenization is disabled.952* @internal953*/954isTooLargeForTokenization(): boolean;955956/**957* The file is so large, that operations on it might be too large for heap958* and can lead to OOM crashes so they should be disabled.959* @internal960*/961isTooLargeForHeapOperation(): boolean;962963/**964* Search the model.965* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.966* @param searchOnlyEditableRange Limit the searching to only search inside the editable range of the model.967* @param isRegex Used to indicate that `searchString` is a regular expression.968* @param matchCase Force the matching to match lower/upper case exactly.969* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.970* @param captureMatches The result will contain the captured groups.971* @param limitResultCount Limit the number of results972* @return The ranges where the matches are. It is empty if not matches have been found.973*/974findMatches(searchString: string, searchOnlyEditableRange: boolean, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];975/**976* Search the model.977* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.978* @param searchScope Limit the searching to only search inside these ranges.979* @param isRegex Used to indicate that `searchString` is a regular expression.980* @param matchCase Force the matching to match lower/upper case exactly.981* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.982* @param captureMatches The result will contain the captured groups.983* @param limitResultCount Limit the number of results984* @return The ranges where the matches are. It is empty if no matches have been found.985*/986findMatches(searchString: string, searchScope: IRange | IRange[], isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];987/**988* Search the model for the next match. Loops to the beginning of the model if needed.989* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.990* @param searchStart Start the searching at the specified position.991* @param isRegex Used to indicate that `searchString` is a regular expression.992* @param matchCase Force the matching to match lower/upper case exactly.993* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.994* @param captureMatches The result will contain the captured groups.995* @return The range where the next match is. It is null if no next match has been found.996*/997findNextMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;998/**999* Search the model for the previous match. Loops to the end of the model if needed.1000* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.1001* @param searchStart Start the searching at the specified position.1002* @param isRegex Used to indicate that `searchString` is a regular expression.1003* @param matchCase Force the matching to match lower/upper case exactly.1004* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.1005* @param captureMatches The result will contain the captured groups.1006* @return The range where the previous match is. It is null if no previous match has been found.1007*/1008findPreviousMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;100910101011/**1012* Get the language associated with this model.1013*/1014getLanguageId(): string;10151016/**1017* Set the current language mode associated with the model.1018* @param languageId The new language.1019* @param source The source of the call that set the language.1020* @internal1021*/1022setLanguage(languageId: string, source?: string): void;10231024/**1025* Set the current language mode associated with the model.1026* @param languageSelection The new language selection.1027* @param source The source of the call that set the language.1028* @internal1029*/1030setLanguage(languageSelection: ILanguageSelection, source?: string): void;10311032/**1033* Returns the real (inner-most) language mode at a given position.1034* The result might be inaccurate. Use `forceTokenization` to ensure accurate tokens.1035* @internal1036*/1037getLanguageIdAtPosition(lineNumber: number, column: number): string;10381039/**1040* Get the word under or besides `position`.1041* @param position The position to look for a word.1042* @return The word under or besides `position`. Might be null.1043*/1044getWordAtPosition(position: IPosition): IWordAtPosition | null;10451046/**1047* Get the word under or besides `position` trimmed to `position`.column1048* @param position The position to look for a word.1049* @return The word under or besides `position`. Will never be null.1050*/1051getWordUntilPosition(position: IPosition): IWordAtPosition;10521053/**1054* Change the decorations. The callback will be called with a change accessor1055* that becomes invalid as soon as the callback finishes executing.1056* This allows for all events to be queued up until the change1057* is completed. Returns whatever the callback returns.1058* @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.1059* @internal1060*/1061changeDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T, ownerId?: number): T | null;10621063/**1064* Perform a minimum amount of operations, in order to transform the decorations1065* identified by `oldDecorations` to the decorations described by `newDecorations`1066* and returns the new identifiers associated with the resulting decorations.1067*1068* @param oldDecorations Array containing previous decorations identifiers.1069* @param newDecorations Array describing what decorations should result after the call.1070* @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.1071* @return An array containing the new decorations identifiers.1072*/1073deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[], ownerId?: number): string[];10741075/**1076* Remove all decorations that have been added with this specific ownerId.1077* @param ownerId The owner id to search for.1078* @internal1079*/1080removeAllDecorationsWithOwnerId(ownerId: number): void;10811082/**1083* Get the options associated with a decoration.1084* @param id The decoration id.1085* @return The decoration options or null if the decoration was not found.1086*/1087getDecorationOptions(id: string): IModelDecorationOptions | null;10881089/**1090* Get the range associated with a decoration.1091* @param id The decoration id.1092* @return The decoration range or null if the decoration was not found.1093*/1094getDecorationRange(id: string): Range | null;10951096/**1097* Gets all the decorations for the line `lineNumber` as an array.1098* @param lineNumber The line number1099* @param ownerId If set, it will ignore decorations belonging to other owners.1100* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1101* @param filterFontDecorations If set, it will ignore font decorations.1102* @return An array with the decorations1103*/1104getLineDecorations(lineNumber: number, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11051106/**1107* Gets all the font decorations for the line `lineNumber` as an array.1108* @param ownerId If set, it will ignore decorations belonging to other owners.1109* @internal1110*/1111getFontDecorationsInRange(range: IRange, ownerId?: number): IModelDecoration[];11121113/**1114* Gets all the decorations for the lines between `startLineNumber` and `endLineNumber` as an array.1115* @param startLineNumber The start line number1116* @param endLineNumber The end line number1117* @param ownerId If set, it will ignore decorations belonging to other owners.1118* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1119* @param filterFontDecorations If set, it will ignore font decorations.1120* @return An array with the decorations1121*/1122getLinesDecorations(startLineNumber: number, endLineNumber: number, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11231124/**1125* Gets all the decorations in a range as an array. Only `startLineNumber` and `endLineNumber` from `range` are used for filtering.1126* So for now it returns all the decorations on the same line as `range`.1127* @param range The range to search in1128* @param ownerId If set, it will ignore decorations belonging to other owners.1129* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1130* @param filterFontDecorations If set, it will ignore font decorations.1131* @param onlyMinimapDecorations If set, it will return only decorations that render in the minimap.1132* @param onlyMarginDecorations If set, it will return only decorations that render in the glyph margin.1133* @return An array with the decorations1134*/1135getDecorationsInRange(range: IRange, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean, onlyMinimapDecorations?: boolean, onlyMarginDecorations?: boolean): IModelDecoration[];11361137/**1138* Gets all the decorations as an array.1139* @param ownerId If set, it will ignore decorations belonging to other owners.1140* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1141* @param filterFontDecorations If set, it will ignore font decorations.1142*/1143getAllDecorations(ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11441145/**1146* Gets all decorations that render in the glyph margin as an array.1147* @param ownerId If set, it will ignore decorations belonging to other owners.1148*/1149getAllMarginDecorations(ownerId?: number): IModelDecoration[];11501151/**1152* Gets all the decorations that should be rendered in the overview ruler as an array.1153* @param ownerId If set, it will ignore decorations belonging to other owners.1154* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).1155* @param filterFontDecorations If set, it will ignore font decorations.1156*/1157getOverviewRulerDecorations(ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];11581159/**1160* Gets all the decorations that contain injected text.1161* @param ownerId If set, it will ignore decorations belonging to other owners.1162*/1163getInjectedTextDecorations(ownerId?: number): IModelDecoration[];11641165/**1166* Gets all the decorations that contain custom line heights.1167* @param ownerId If set, it will ignore decorations belonging to other owners.1168*/1169getCustomLineHeightsDecorations(ownerId?: number): IModelDecoration[];11701171/**1172* @internal1173*/1174_getTrackedRange(id: string): Range | null;11751176/**1177* @internal1178*/1179_setTrackedRange(id: string | null, newRange: null, newStickiness: TrackedRangeStickiness): null;1180/**1181* @internal1182*/1183_setTrackedRange(id: string | null, newRange: Range, newStickiness: TrackedRangeStickiness): string;11841185/**1186* Normalize a string containing whitespace according to indentation rules (converts to spaces or to tabs).1187*/1188normalizeIndentation(str: string): string;11891190/**1191* Change the options of this model.1192*/1193updateOptions(newOpts: ITextModelUpdateOptions): void;11941195/**1196* Detect the indentation options for this model from its content.1197*/1198detectIndentation(defaultInsertSpaces: boolean, defaultTabSize: number): void;11991200/**1201* Close the current undo-redo element.1202* This offers a way to create an undo/redo stop point.1203*/1204pushStackElement(): void;12051206/**1207* Open the current undo-redo element.1208* This offers a way to remove the current undo/redo stop point.1209*/1210popStackElement(): void;12111212/**1213* @internal1214*/1215edit(edit: TextEdit, options?: { reason?: TextModelEditSource }): void;12161217/**1218* Push edit operations, basically editing the model. This is the preferred way1219* of editing the model. The edit operations will land on the undo stack.1220* @param beforeCursorState The cursor state before the edit operations. This cursor state will be returned when `undo` or `redo` are invoked.1221* @param editOperations The edit operations.1222* @param cursorStateComputer A callback that can compute the resulting cursors state after the edit operations have been executed.1223* @return The cursor state returned by the `cursorStateComputer`.1224*/1225pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;1226/**1227* @internal1228*/1229pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer, group?: UndoRedoGroup, reason?: TextModelEditSource): Selection[] | null;12301231/**1232* Change the end of line sequence. This is the preferred way of1233* changing the eol sequence. This will land on the undo stack.1234*/1235pushEOL(eol: EndOfLineSequence): void;12361237/**1238* Edit the model without adding the edits to the undo stack.1239* This can have dire consequences on the undo stack! See @pushEditOperations for the preferred way.1240* @param operations The edit operations.1241* @return If desired, the inverse edit operations, that, when applied, will bring the model back to the previous state.1242*/1243applyEdits(operations: readonly IIdentifiedSingleEditOperation[]): void;1244/** @internal */1245applyEdits(operations: readonly IIdentifiedSingleEditOperation[], reason: TextModelEditSource): void;1246applyEdits(operations: readonly IIdentifiedSingleEditOperation[], computeUndoEdits: false): void;1247applyEdits(operations: readonly IIdentifiedSingleEditOperation[], computeUndoEdits: true): IValidEditOperation[];12481249/**1250* Change the end of line sequence without recording in the undo stack.1251* This can have dire consequences on the undo stack! See @pushEOL for the preferred way.1252*/1253setEOL(eol: EndOfLineSequence): void;12541255/**1256* @internal1257*/1258_applyUndo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;12591260/**1261* @internal1262*/1263_applyRedo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;12641265/**1266* Undo edit operations until the previous undo/redo point.1267* The inverse edit operations will be pushed on the redo stack.1268*/1269undo(): void | Promise<void>;12701271/**1272* Is there anything in the undo stack?1273*/1274canUndo(): boolean;12751276/**1277* Redo edit operations until the next undo/redo point.1278* The inverse edit operations will be pushed on the undo stack.1279*/1280redo(): void | Promise<void>;12811282/**1283* Is there anything in the redo stack?1284*/1285canRedo(): boolean;12861287/**1288* @deprecated Please use `onDidChangeContent` instead.1289* An event emitted when the contents of the model have changed.1290* @internal1291* @event1292*/1293readonly onDidChangeContentOrInjectedText: Event<InternalModelContentChangeEvent | ModelInjectedTextChangedEvent>;1294/**1295* An event emitted when the contents of the model have changed.1296* @event1297*/1298onDidChangeContent(listener: (e: IModelContentChangedEvent) => void): IDisposable;1299/**1300* An event emitted when decorations of the model have changed.1301* @event1302*/1303readonly onDidChangeDecorations: Event<IModelDecorationsChangedEvent>;1304/**1305* An event emitted when line heights from decorations changes.1306* This event is emitted only when adding, removing or changing a decoration1307* and not when doing edits in the model (i.e. when decoration ranges change)1308* @internal1309* @event1310*/1311readonly onDidChangeLineHeight: Event<ModelLineHeightChangedEvent>;1312/**1313* An event emitted when the font from decorations changes.1314* This event is emitted only when adding, removing or changing a decoration1315* and not when doing edits in the model (i.e. when decoration ranges change)1316* @internal1317* @event1318*/1319readonly onDidChangeFont: Event<ModelFontChangedEvent>;1320/**1321* An event emitted when the model options have changed.1322* @event1323*/1324readonly onDidChangeOptions: Event<IModelOptionsChangedEvent>;1325/**1326* An event emitted when the language associated with the model has changed.1327* @event1328*/1329readonly onDidChangeLanguage: Event<IModelLanguageChangedEvent>;1330/**1331* An event emitted when the language configuration associated with the model has changed.1332* @event1333*/1334readonly onDidChangeLanguageConfiguration: Event<IModelLanguageConfigurationChangedEvent>;1335/**1336* An event emitted when the tokens associated with the model have changed.1337* @event1338* @internal1339*/1340readonly onDidChangeTokens: Event<IModelTokensChangedEvent>;1341/**1342* An event emitted when the model has been attached to the first editor or detached from the last editor.1343* @event1344*/1345readonly onDidChangeAttached: Event<void>;1346/**1347* An event emitted right before disposing the model.1348* @event1349*/1350readonly onWillDispose: Event<void>;13511352/**1353* Destroy this model.1354*/1355dispose(): void;13561357/**1358* @internal1359*/1360onBeforeAttached(): IAttachedView;13611362/**1363* @internal1364*/1365onBeforeDetached(view: IAttachedView): void;13661367/**1368* Returns if this model is attached to an editor or not.1369*/1370isAttachedToEditor(): boolean;13711372/**1373* Returns the count of editors this model is attached to.1374* @internal1375*/1376getAttachedEditorCount(): number;13771378/**1379* Among all positions that are projected to the same position in the underlying text model as1380* the given position, select a unique position as indicated by the affinity.1381*1382* PositionAffinity.Left:1383* The normalized position must be equal or left to the requested position.1384*1385* PositionAffinity.Right:1386* The normalized position must be equal or right to the requested position.1387*1388* @internal1389*/1390normalizePosition(position: Position, affinity: PositionAffinity): Position;13911392/**1393* Gets the column at which indentation stops at a given line.1394* @internal1395*/1396getLineIndentColumn(lineNumber: number): number;13971398/**1399* Returns an object that can be used to query brackets.1400* @internal1401*/1402readonly bracketPairs: IBracketPairsTextModelPart;14031404/**1405* Returns an object that can be used to query indent guides.1406* @internal1407*/1408readonly guides: IGuidesTextModelPart;14091410/**1411* @internal1412*/1413readonly tokenization: ITokenizationTextModelPart;1414}14151416/**1417* @internal1418*/1419export function isITextModel(obj: IEditorModel): obj is ITextModel {1420return Boolean(obj && (obj as ITextModel).uri);1421}14221423/**1424* @internal1425*/1426export interface IAttachedView {1427/**1428* @param stabilized Indicates if the visible lines are probably going to change soon or can be considered stable.1429* Is true on reveal range and false on scroll.1430* Tokenizers should tokenize synchronously if stabilized is true.1431*/1432setVisibleLines(visibleLines: { startLineNumber: number; endLineNumber: number }[], stabilized: boolean): void;1433}14341435export const enum PositionAffinity {1436/**1437* Prefers the left most position.1438*/1439Left = 0,14401441/**1442* Prefers the right most position.1443*/1444Right = 1,14451446/**1447* No preference.1448*/1449None = 2,14501451/**1452* If the given position is on injected text, prefers the position left of it.1453*/1454LeftOfInjectedText = 3,14551456/**1457* If the given position is on injected text, prefers the position right of it.1458*/1459RightOfInjectedText = 4,1460}14611462/**1463* @internal1464*/1465export interface ITextBufferBuilder {1466acceptChunk(chunk: string): void;1467finish(): ITextBufferFactory;1468}14691470/**1471* @internal1472*/1473export interface ITextBufferFactory {1474create(defaultEOL: DefaultEndOfLine): { textBuffer: ITextBuffer; disposable: IDisposable };1475getFirstLineText(lengthLimit: number): string;1476}14771478/**1479* @internal1480*/1481export const enum ModelConstants {1482FIRST_LINE_DETECTION_LENGTH_LIMIT = 10001483}14841485/**1486* @internal1487*/1488export class ValidAnnotatedEditOperation implements IIdentifiedSingleEditOperation {1489constructor(1490public readonly identifier: ISingleEditOperationIdentifier | null,1491public readonly range: Range,1492public readonly text: string | null,1493public readonly forceMoveMarkers: boolean,1494public readonly isAutoWhitespaceEdit: boolean,1495public readonly _isTracked: boolean,1496) { }1497}14981499/**1500* @internal1501*1502* `lineNumber` is 1 based.1503*/1504export interface IReadonlyTextBuffer {1505onDidChangeContent: Event<void>;1506equals(other: ITextBuffer): boolean;1507mightContainRTL(): boolean;1508mightContainUnusualLineTerminators(): boolean;1509resetMightContainUnusualLineTerminators(): void;1510mightContainNonBasicASCII(): boolean;1511getBOM(): string;1512getEOL(): string;15131514getOffsetAt(lineNumber: number, column: number): number;1515getPositionAt(offset: number): Position;1516getRangeAt(offset: number, length: number): Range;15171518getValueInRange(range: Range, eol: EndOfLinePreference): string;1519createSnapshot(preserveBOM: boolean): ITextSnapshot;1520getValueLengthInRange(range: Range, eol: EndOfLinePreference): number;1521getCharacterCountInRange(range: Range, eol: EndOfLinePreference): number;1522getLength(): number;1523getLineCount(): number;1524getLinesContent(): string[];1525getLineContent(lineNumber: number): string;1526getLineCharCode(lineNumber: number, index: number): number;1527getCharCode(offset: number): number;1528getLineLength(lineNumber: number): number;1529getLineMinColumn(lineNumber: number): number;1530getLineMaxColumn(lineNumber: number): number;1531getLineFirstNonWhitespaceColumn(lineNumber: number): number;1532getLineLastNonWhitespaceColumn(lineNumber: number): number;1533findMatchesLineByLine(searchRange: Range, searchData: SearchData, captureMatches: boolean, limitResultCount: number): FindMatch[];15341535/**1536* Get nearest chunk of text after `offset` in the text buffer.1537*/1538getNearestChunk(offset: number): string;1539}15401541/**1542* @internal1543*/1544export class SearchData {15451546/**1547* The regex to search for. Always defined.1548*/1549public readonly regex: RegExp;1550/**1551* The word separator classifier.1552*/1553public readonly wordSeparators: WordCharacterClassifier | null;1554/**1555* The simple string to search for (if possible).1556*/1557public readonly simpleSearch: string | null;15581559constructor(regex: RegExp, wordSeparators: WordCharacterClassifier | null, simpleSearch: string | null) {1560this.regex = regex;1561this.wordSeparators = wordSeparators;1562this.simpleSearch = simpleSearch;1563}1564}15651566/**1567* @internal1568*/1569export interface ITextBuffer extends IReadonlyTextBuffer, IDisposable {1570setEOL(newEOL: '\r\n' | '\n'): void;1571applyEdits(rawOperations: ValidAnnotatedEditOperation[], recordTrimAutoWhitespace: boolean, computeUndoEdits: boolean): ApplyEditsResult;1572}15731574/**1575* @internal1576*/1577export class ApplyEditsResult {15781579constructor(1580public readonly reverseEdits: IValidEditOperation[] | null,1581public readonly changes: IInternalModelContentChange[],1582public readonly trimAutoWhitespaceLineNumbers: number[] | null1583) { }15841585}15861587/**1588* @internal1589*/1590export interface IInternalModelContentChange extends IModelContentChange {1591range: Range;1592forceMoveMarkers: boolean;1593}15941595/**1596* @internal1597*/1598export function shouldSynchronizeModel(model: ITextModel): boolean {1599return (1600!model.isTooLargeForSyncing() && !model.isForSimpleWidget1601);1602}160316041605