model.ts 41.1 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import { Event } from 'vs/base/common/event';
7
import { IMarkdownString } from 'vs/base/common/htmlContent';
A
Alex Dima 已提交
8
import { IDisposable } from 'vs/base/common/lifecycle';
9
import { URI } from 'vs/base/common/uri';
10
import { LineTokens } from 'vs/editor/common/core/lineTokens';
A
Alex Dima 已提交
11 12
import { IPosition, Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
13
import { Selection } from 'vs/editor/common/core/selection';
A
Alex Dima 已提交
14
import { IModelContentChange, IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent, ModelRawContentChangedEvent } from 'vs/editor/common/model/textModelEvents';
P
Peng Lyu 已提交
15
import { SearchData } from 'vs/editor/common/model/textModelSearch';
16
import { LanguageId, LanguageIdentifier, FormattingOptions } from 'vs/editor/common/modes';
A
Alex Dima 已提交
17
import { ThemeColor } from 'vs/platform/theme/common/themeService';
A
Alexandru Dima 已提交
18
import { MultilineTokens, MultilineTokens2 } from 'vs/editor/common/model/tokensStore';
19
import { TextChange } from 'vs/editor/common/model/textChange';
20 21 22 23 24 25 26 27 28 29 30 31

/**
 * Vertical Lane in the overview ruler of the editor.
 */
export enum OverviewRulerLane {
	Left = 1,
	Center = 2,
	Right = 4,
	Full = 7
}

/**
32
 * Position in the minimap to render the decoration.
33
 */
34
export enum MinimapPosition {
35 36
	Inline = 1,
	Gutter = 2
37 38 39
}

export interface IDecorationOptions {
40
	/**
41
	 * CSS color to render.
42 43
	 * e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry
	 */
A
Alex Dima 已提交
44
	color: string | ThemeColor | undefined;
45
	/**
46
	 * CSS color to render.
47 48
	 * e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry
	 */
49
	darkColor?: string | ThemeColor;
50 51 52 53 54 55
}

/**
 * Options for rendering a model decoration in the overview ruler.
 */
export interface IModelDecorationOverviewRulerOptions extends IDecorationOptions {
56 57 58 59 60 61
	/**
	 * The position in the overview ruler.
	 */
	position: OverviewRulerLane;
}

62 63 64 65 66 67 68 69 70 71
/**
 * Options for rendering a model decoration in the overview ruler.
 */
export interface IModelDecorationMinimapOptions extends IDecorationOptions {
	/**
	 * The position in the overview ruler.
	 */
	position: MinimapPosition;
}

72 73 74 75 76 77 78 79 80 81 82 83
/**
 * Options for a model decoration.
 */
export interface IModelDecorationOptions {
	/**
	 * Customize the growing behavior of the decoration when typing at the edges of the decoration.
	 * Defaults to TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges
	 */
	stickiness?: TrackedRangeStickiness;
	/**
	 * CSS class name describing the decoration.
	 */
A
Alex Dima 已提交
84
	className?: string | null;
85 86 87
	/**
	 * Message to be rendered when hovering over the glyph margin decoration.
	 */
A
Alex Dima 已提交
88
	glyphMarginHoverMessage?: IMarkdownString | IMarkdownString[] | null;
89 90 91
	/**
	 * Array of MarkdownString to render as the decoration message.
	 */
A
Alex Dima 已提交
92
	hoverMessage?: IMarkdownString | IMarkdownString[] | null;
93 94 95 96 97 98 99 100
	/**
	 * Should the decoration expand to encompass a whole line.
	 */
	isWholeLine?: boolean;
	/**
	 * Always render the decoration (even when the range it encompasses is collapsed).
	 * @internal
	 */
101
	showIfCollapsed?: boolean;
102 103 104 105 106
	/**
	 * Collapse the decoration if its entire range is being replaced via an edit.
	 * @internal
	 */
	collapseOnReplaceEdit?: boolean;
107 108 109 110 111
	/**
	 * Specifies the stack order of a decoration.
	 * A decoration with greater stack order is always in front of a decoration with a lower stack order.
	 */
	zIndex?: number;
112 113 114
	/**
	 * If set, render this decoration in the overview ruler.
	 */
A
Alex Dima 已提交
115
	overviewRuler?: IModelDecorationOverviewRulerOptions | null;
116 117 118 119
	/**
	 * If set, render this decoration in the minimap.
	 */
	minimap?: IModelDecorationMinimapOptions | null;
120 121 122
	/**
	 * If set, the decoration will be rendered in the glyph margin with this CSS class name.
	 */
A
Alex Dima 已提交
123
	glyphMarginClassName?: string | null;
124 125 126
	/**
	 * If set, the decoration will be rendered in the lines decorations with this CSS class name.
	 */
A
Alex Dima 已提交
127
	linesDecorationsClassName?: string | null;
128
	/**
A
Alex Dima 已提交
129
	 * 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.
130
	 */
M
Martin Aeschlimann 已提交
131
	firstLineDecorationClassName?: string | null;
132 133 134
	/**
	 * If set, the decoration will be rendered in the margin (covering its full width) with this CSS class name.
	 */
A
Alex Dima 已提交
135
	marginClassName?: string | null;
136 137 138 139 140
	/**
	 * If set, the decoration will be rendered inline with the text with this CSS class name.
	 * Please use this only for CSS rules that must impact the text. For example, use `className`
	 * to have a background color decoration.
	 */
A
Alex Dima 已提交
141
	inlineClassName?: string | null;
A
Alex Dima 已提交
142 143 144 145
	/**
	 * If there is an `inlineClassName` which affects letter spacing.
	 */
	inlineClassNameAffectsLetterSpacing?: boolean;
146 147 148
	/**
	 * If set, the decoration will be rendered before the text with this CSS class name.
	 */
A
Alex Dima 已提交
149
	beforeContentClassName?: string | null;
150 151 152
	/**
	 * If set, the decoration will be rendered after the text with this CSS class name.
	 */
A
Alex Dima 已提交
153
	afterContentClassName?: string | null;
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
}

/**
 * New model decorations.
 */
export interface IModelDeltaDecoration {
	/**
	 * Range that this decoration covers.
	 */
	range: IRange;
	/**
	 * Options associated with this decoration.
	 */
	options: IModelDecorationOptions;
}

/**
 * A decoration in the model.
 */
export interface IModelDecoration {
	/**
	 * Identifier for a decoration.
	 */
	readonly id: string;
	/**
A
Alex Dima 已提交
179
	 * Identifier for a decoration's owner.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	 */
	readonly ownerId: number;
	/**
	 * Range that this decoration covers.
	 */
	readonly range: Range;
	/**
	 * Options associated with this decoration.
	 */
	readonly options: IModelDecorationOptions;
}

/**
 * An accessor that can add, change or remove model decorations.
 * @internal
 */
export interface IModelDecorationsChangeAccessor {
	/**
	 * Add a new decoration.
	 * @param range Range that this decoration covers.
	 * @param options Options associated with this decoration.
	 * @return An unique identifier associated with this decoration.
	 */
	addDecoration(range: IRange, options: IModelDecorationOptions): string;
	/**
	 * Change the range that an existing decoration covers.
	 * @param id The unique identifier associated with the decoration.
	 * @param newRange The new range that this decoration covers.
	 */
	changeDecoration(id: string, newRange: IRange): void;
	/**
	 * Change the options associated with an existing decoration.
	 * @param id The unique identifier associated with the decoration.
	 * @param newOptions The new options associated with this decoration.
	 */
	changeDecorationOptions(id: string, newOptions: IModelDecorationOptions): void;
	/**
	 * Remove an existing decoration.
	 * @param id The unique identifier associated with the decoration.
	 */
	removeDecoration(id: string): void;
	/**
A
Alex Dima 已提交
222
	 * Perform a minimum amount of operations, in order to transform the decorations
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
	 * identified by `oldDecorations` to the decorations described by `newDecorations`
	 * and returns the new identifiers associated with the resulting decorations.
	 *
	 * @param oldDecorations Array containing previous decorations identifiers.
	 * @param newDecorations Array describing what decorations should result after the call.
	 * @return An array containing the new decorations identifiers.
	 */
	deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[];
}

/**
 * Word inside a model.
 */
export interface IWordAtPosition {
	/**
	 * The word.
	 */
	readonly word: string;
	/**
	 * The column where the word starts.
	 */
	readonly startColumn: number;
	/**
	 * The column where the word ends.
	 */
	readonly endColumn: number;
}

/**
 * End of line character preference.
 */
254
export const enum EndOfLinePreference {
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
	/**
	 * Use the end of line character identified in the text buffer.
	 */
	TextDefined = 0,
	/**
	 * Use line feed (\n) as the end of line character.
	 */
	LF = 1,
	/**
	 * Use carriage return and line feed (\r\n) as the end of line character.
	 */
	CRLF = 2
}

/**
 * The default end of line to use when instantiating models.
 */
272
export const enum DefaultEndOfLine {
273 274 275 276 277 278 279 280 281 282 283 284 285
	/**
	 * Use line feed (\n) as the end of line character.
	 */
	LF = 1,
	/**
	 * Use carriage return and line feed (\r\n) as the end of line character.
	 */
	CRLF = 2
}

/**
 * End of line character preference.
 */
286
export const enum EndOfLineSequence {
287 288 289 290 291 292 293 294 295 296 297 298
	/**
	 * Use line feed (\n) as the end of line character.
	 */
	LF = 0,
	/**
	 * Use carriage return and line feed (\r\n) as the end of line character.
	 */
	CRLF = 1
}

/**
 * An identifier for a single edit operation.
A
Alex Dima 已提交
299
 * @internal
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
 */
export interface ISingleEditOperationIdentifier {
	/**
	 * Identifier major
	 */
	major: number;
	/**
	 * Identifier minor
	 */
	minor: number;
}

/**
 * A single edit operation, that acts as a simple replace.
 * i.e. Replace text at `range` with `text` in model.
 */
export interface ISingleEditOperation {
	/**
	 * The range to replace. This can be empty to emulate a simple insert.
	 */
	range: IRange;
	/**
	 * The text to replace with. This can be null to emulate a simple delete.
	 */
M
Matt Bierner 已提交
324
	text: string | null;
325 326 327 328 329 330 331 332 333 334 335 336 337
	/**
	 * This indicates that this operation has "insert" semantics.
	 * i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.
	 */
	forceMoveMarkers?: boolean;
}

/**
 * A single edit operation, that has an identifier.
 */
export interface IIdentifiedSingleEditOperation {
	/**
	 * An identifier associated with this single edit operation.
338
	 * @internal
339
	 */
A
Alex Dima 已提交
340
	identifier?: ISingleEditOperationIdentifier | null;
341 342 343
	/**
	 * The range to replace. This can be empty to emulate a simple insert.
	 */
344
	range: IRange;
345 346 347
	/**
	 * The text to replace with. This can be null to emulate a simple delete.
	 */
A
Alex Dima 已提交
348
	text: string | null;
349 350 351 352
	/**
	 * This indicates that this operation has "insert" semantics.
	 * i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.
	 */
353
	forceMoveMarkers?: boolean;
354 355 356
	/**
	 * This indicates that this operation is inserting automatic whitespace
	 * that can be removed on next model edit operation if `config.trimAutoWhitespace` is true.
357
	 * @internal
358 359 360 361 362 363 364 365 366
	 */
	isAutoWhitespaceEdit?: boolean;
	/**
	 * This indicates that this operation is in a set of operations that are tracked and should not be "simplified".
	 * @internal
	 */
	_isTracked?: boolean;
}

367 368 369 370 371 372 373 374 375 376 377
export interface IValidEditOperation {
	/**
	 * An identifier associated with this single edit operation.
	 * @internal
	 */
	identifier: ISingleEditOperationIdentifier | null;
	/**
	 * The range to replace. This can be empty to emulate a simple insert.
	 */
	range: Range;
	/**
378
	 * The text to replace with. This can be empty to emulate a simple delete.
379
	 */
380
	text: string;
381
	/**
382
	 * @internal
383
	 */
384
	textChange: TextChange;
385 386
}

387 388 389 390 391 392 393
/**
 * A callback that can compute the cursor state after applying a series of edit operations.
 */
export interface ICursorStateComputer {
	/**
	 * A callback that can compute the resulting cursors state after some edit operations have been executed.
	 */
394
	(inverseEditOperations: IValidEditOperation[]): Selection[] | null;
395 396 397 398 399 400
}

export class TextModelResolvedOptions {
	_textModelResolvedOptionsBrand: void;

	readonly tabSize: number;
D
David Lechner 已提交
401
	readonly indentSize: number;
402 403 404 405 406 407 408 409 410
	readonly insertSpaces: boolean;
	readonly defaultEOL: DefaultEndOfLine;
	readonly trimAutoWhitespace: boolean;

	/**
	 * @internal
	 */
	constructor(src: {
		tabSize: number;
D
David Lechner 已提交
411
		indentSize: number;
412 413 414 415
		insertSpaces: boolean;
		defaultEOL: DefaultEndOfLine;
		trimAutoWhitespace: boolean;
	}) {
416
		this.tabSize = Math.max(1, src.tabSize | 0);
417
		this.indentSize = src.tabSize | 0;
418 419 420 421 422 423 424 425 426 427 428
		this.insertSpaces = Boolean(src.insertSpaces);
		this.defaultEOL = src.defaultEOL | 0;
		this.trimAutoWhitespace = Boolean(src.trimAutoWhitespace);
	}

	/**
	 * @internal
	 */
	public equals(other: TextModelResolvedOptions): boolean {
		return (
			this.tabSize === other.tabSize
A
Alex Dima 已提交
429
			&& this.indentSize === other.indentSize
430 431 432 433 434 435 436 437 438 439 440 441
			&& this.insertSpaces === other.insertSpaces
			&& this.defaultEOL === other.defaultEOL
			&& this.trimAutoWhitespace === other.trimAutoWhitespace
		);
	}

	/**
	 * @internal
	 */
	public createChangeEvent(newOpts: TextModelResolvedOptions): IModelOptionsChangedEvent {
		return {
			tabSize: this.tabSize !== newOpts.tabSize,
D
David Lechner 已提交
442
			indentSize: this.indentSize !== newOpts.indentSize,
443 444 445 446 447 448 449 450 451 452 453
			insertSpaces: this.insertSpaces !== newOpts.insertSpaces,
			trimAutoWhitespace: this.trimAutoWhitespace !== newOpts.trimAutoWhitespace,
		};
	}
}

/**
 * @internal
 */
export interface ITextModelCreationOptions {
	tabSize: number;
D
David Lechner 已提交
454
	indentSize: number;
455 456 457 458
	insertSpaces: boolean;
	detectIndentation: boolean;
	trimAutoWhitespace: boolean;
	defaultEOL: DefaultEndOfLine;
459
	isForSimpleWidget: boolean;
460
	largeFileOptimizations: boolean;
461 462 463 464
}

export interface ITextModelUpdateOptions {
	tabSize?: number;
D
David Lechner 已提交
465
	indentSize?: number;
466 467 468 469 470 471 472 473
	insertSpaces?: boolean;
	trimAutoWhitespace?: boolean;
}

export class FindMatch {
	_findMatchBrand: void;

	public readonly range: Range;
A
Alex Dima 已提交
474
	public readonly matches: string[] | null;
475 476 477 478

	/**
	 * @internal
	 */
A
Alex Dima 已提交
479
	constructor(range: Range, matches: string[] | null) {
480 481 482 483 484 485 486 487 488 489
		this.range = range;
		this.matches = matches;
	}
}

/**
 * @internal
 */
export interface IFoundBracket {
	range: Range;
490 491
	open: string[];
	close: string[];
492 493 494 495 496 497 498
	isOpen: boolean;
}

/**
 * Describes the behavior of decorations when typing/editing near their edges.
 * Note: Please do not edit the values, as they very carefully match `DecorationRangeBehavior`
 */
499
export const enum TrackedRangeStickiness {
500 501 502 503 504 505
	AlwaysGrowsWhenTypingAtEdges = 0,
	NeverGrowsWhenTypingAtEdges = 1,
	GrowsOnlyWhenTypingBefore = 2,
	GrowsOnlyWhenTypingAfter = 3,
}

A
Alex Dima 已提交
506 507 508 509 510 511 512 513 514
/**
 * @internal
 */
export interface IActiveIndentGuideInfo {
	startLineNumber: number;
	endLineNumber: number;
	indent: number;
}

515 516 517 518 519 520 521 522 523 524 525
/**
 * Text snapshot that works like an iterator.
 * Will try to return chunks of roughly ~64KB size.
 * Will return null when finished.
 *
 * @internal
 */
export interface ITextSnapshot {
	read(): string | null;
}

526 527 528
/**
 * A model.
 */
A
Alex Dima 已提交
529 530 531 532 533 534 535 536 537 538 539
export interface ITextModel {

	/**
	 * Gets the resource associated with this editor model.
	 */
	readonly uri: URI;

	/**
	 * A unique identifier associated with this model.
	 */
	readonly id: string;
540

541 542 543 544 545 546
	/**
	 * This model is constructed for a simple widget code editor.
	 * @internal
	 */
	readonly isForSimpleWidget: boolean;

547 548 549 550 551 552 553
	/**
	 * If true, the text model might contain RTL.
	 * If false, the text model **contains only** contain LTR.
	 * @internal
	 */
	mightContainRTL(): boolean;

554
	/**
555
	 * If true, the text model might contain LINE SEPARATOR (LS), PARAGRAPH SEPARATOR (PS).
556 557 558 559 560 561 562 563 564 565
	 * If false, the text model definitely does not contain these.
	 * @internal
	 */
	mightContainUnusualLineTerminators(): boolean;

	/**
	 * @internal
	 */
	removeUnusualLineTerminators(selections?: Selection[]): void;

566 567 568 569 570 571 572 573 574 575 576 577
	/**
	 * If true, the text model might contain non basic ASCII.
	 * If false, the text model **contains only** basic ASCII.
	 * @internal
	 */
	mightContainNonBasicASCII(): boolean;

	/**
	 * Get the resolved options for this model.
	 */
	getOptions(): TextModelResolvedOptions;

578 579 580 581 582 583
	/**
	 * Get the formatting options for this model.
	 * @internal
	 */
	getFormattingOptions(): FormattingOptions;

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
	/**
	 * Get the current version id of the model.
	 * Anytime a change happens to the model (even undo/redo),
	 * the version id is incremented.
	 */
	getVersionId(): number;

	/**
	 * Get the alternative version id of the model.
	 * This alternative version id is not always incremented,
	 * it will return the same values in the case of undo-redo.
	 */
	getAlternativeVersionId(): number;

	/**
	 * Replace the entire text buffer value contained in this model.
	 */
	setValue(newValue: string): void;

	/**
	 * Replace the entire text buffer value contained in this model.
	 * @internal
	 */
607
	setValueFromTextBuffer(newValue: ITextBuffer): void;
608 609 610 611 612 613 614 615 616

	/**
	 * Get the text stored in this model.
	 * @param eol The end of line character preference. Defaults to `EndOfLinePreference.TextDefined`.
	 * @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.
	 * @return The text.
	 */
	getValue(eol?: EndOfLinePreference, preserveBOM?: boolean): string;

617 618 619 620 621 622 623 624
	/**
	 * Get the text stored in this model.
	 * @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.
	 * @return The text snapshot (it is safe to consume it asynchronously).
	 * @internal
	 */
	createSnapshot(preserveBOM?: boolean): ITextSnapshot;

625 626 627 628 629 630 631 632 633
	/**
	 * Get the length of the text stored in this model.
	 */
	getValueLength(eol?: EndOfLinePreference, preserveBOM?: boolean): number;

	/**
	 * Check if the raw text stored in this model equals another raw text.
	 * @internal
	 */
634
	equalsTextBuffer(other: ITextBuffer): boolean;
635

R
rebornix 已提交
636 637 638 639 640 641
	/**
	 * Get the underling text buffer.
	 * @internal
	 */
	getTextBuffer(): ITextBuffer;

642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
	/**
	 * Get the text in a certain range.
	 * @param range The range describing what text to get.
	 * @param eol The end of line character preference. This will only be used for multiline ranges. Defaults to `EndOfLinePreference.TextDefined`.
	 * @return The text.
	 */
	getValueInRange(range: IRange, eol?: EndOfLinePreference): string;

	/**
	 * Get the length of text in a certain range.
	 * @param range The range describing what text length to get.
	 * @return The text length.
	 */
	getValueLengthInRange(range: IRange): number;

657 658 659 660 661 662
	/**
	 * Get the character count of text in a certain range.
	 * @param range The range describing what text length to get.
	 */
	getCharacterCountInRange(range: IRange): number;

663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
	/**
	 * Splits characters in two buckets. First bucket (A) is of characters that
	 * sit in lines with length < `LONG_LINE_BOUNDARY`. Second bucket (B) is of
	 * characters that sit in lines with length >= `LONG_LINE_BOUNDARY`.
	 * If count(B) > count(A) return true. Returns false otherwise.
	 * @internal
	 */
	isDominatedByLongLines(): boolean;

	/**
	 * Get the number of lines in the model.
	 */
	getLineCount(): number;

	/**
	 * Get the text for a certain line.
	 */
	getLineContent(lineNumber: number): string;

A
Alex Dima 已提交
682 683 684 685
	/**
	 * Get the text length for a certain line.
	 */
	getLineLength(lineNumber: number): number;
686 687 688 689 690 691 692 693 694 695 696 697

	/**
	 * Get the text for all lines.
	 */
	getLinesContent(): string[];

	/**
	 * Get the end of line sequence predominantly used in the text buffer.
	 * @return EOL char sequence (e.g.: '\n' or '\r\n').
	 */
	getEOL(): string;

698 699 700 701 702
	/**
	 * Get the end of line sequence predominantly used in the text buffer.
	 */
	getEndOfLineSequence(): EndOfLineSequence;

703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
	/**
	 * Get the minimum legal column for line at `lineNumber`
	 */
	getLineMinColumn(lineNumber: number): number;

	/**
	 * Get the maximum legal column for line at `lineNumber`
	 */
	getLineMaxColumn(lineNumber: number): number;

	/**
	 * Returns the column before the first non whitespace character for line at `lineNumber`.
	 * Returns 0 if line is empty or contains only whitespace.
	 */
	getLineFirstNonWhitespaceColumn(lineNumber: number): number;

	/**
	 * Returns the column after the last non whitespace character for line at `lineNumber`.
	 * Returns 0 if line is empty or contains only whitespace.
	 */
	getLineLastNonWhitespaceColumn(lineNumber: number): number;

	/**
	 * Create a valid position,
	 */
	validatePosition(position: IPosition): Position;

	/**
A
Alex Dima 已提交
731
	 * Advances the given position by the given offset (negative offsets are also accepted)
732 733 734 735 736
	 * and returns it as a new valid position.
	 *
	 * If the offset and position are such that their combination goes beyond the beginning or
	 * end of the model, throws an exception.
	 *
A
Alex Dima 已提交
737
	 * If the offset is such that the new position would be in the middle of a multi-byte
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
	 * line terminator, throws an exception.
	 */
	modifyPosition(position: IPosition, offset: number): Position;

	/**
	 * Create a valid range.
	 */
	validateRange(range: IRange): Range;

	/**
	 * Converts the position to a zero-based offset.
	 *
	 * The position will be [adjusted](#TextDocument.validatePosition).
	 *
	 * @param position A position.
	 * @return A valid zero-based offset.
	 */
	getOffsetAt(position: IPosition): number;

	/**
	 * Converts a zero-based offset to a position.
	 *
	 * @param offset A zero-based offset.
	 * @return A valid [position](#Position).
	 */
	getPositionAt(offset: number): Position;

	/**
	 * Get a range covering the entire model
	 */
	getFullModelRange(): Range;

	/**
	 * Returns if the model was disposed or not.
	 */
	isDisposed(): boolean;

P
Peng Lyu 已提交
775 776 777 778 779
	/**
	 * @internal
	 */
	tokenizeViewport(startLineNumber: number, endLineNumber: number): void;

780
	/**
781 782
	 * This model is so large that it would not be a good idea to sync it over
	 * to web workers or other places.
783 784
	 * @internal
	 */
785
	isTooLargeForSyncing(): boolean;
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803

	/**
	 * The file is so large, that even tokenization is disabled.
	 * @internal
	 */
	isTooLargeForTokenization(): boolean;

	/**
	 * Search the model.
	 * @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
	 * @param searchOnlyEditableRange Limit the searching to only search inside the editable range of the model.
	 * @param isRegex Used to indicate that `searchString` is a regular expression.
	 * @param matchCase Force the matching to match lower/upper case exactly.
	 * @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
	 * @param captureMatches The result will contain the captured groups.
	 * @param limitResultCount Limit the number of results
	 * @return The ranges where the matches are. It is empty if not matches have been found.
	 */
804
	findMatches(searchString: string, searchOnlyEditableRange: boolean, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];
805 806 807
	/**
	 * Search the model.
	 * @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
808
	 * @param searchScope Limit the searching to only search inside these ranges.
809 810 811 812 813 814 815
	 * @param isRegex Used to indicate that `searchString` is a regular expression.
	 * @param matchCase Force the matching to match lower/upper case exactly.
	 * @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
	 * @param captureMatches The result will contain the captured groups.
	 * @param limitResultCount Limit the number of results
	 * @return The ranges where the matches are. It is empty if no matches have been found.
	 */
816
	findMatches(searchString: string, searchScope: IRange | IRange[], isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];
817 818 819 820 821 822 823 824 825 826
	/**
	 * Search the model for the next match. Loops to the beginning of the model if needed.
	 * @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
	 * @param searchStart Start the searching at the specified position.
	 * @param isRegex Used to indicate that `searchString` is a regular expression.
	 * @param matchCase Force the matching to match lower/upper case exactly.
	 * @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
	 * @param captureMatches The result will contain the captured groups.
	 * @return The range where the next match is. It is null if no next match has been found.
	 */
A
Alex Dima 已提交
827
	findNextMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;
828 829 830 831 832 833 834 835 836 837
	/**
	 * Search the model for the previous match. Loops to the end of the model if needed.
	 * @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
	 * @param searchStart Start the searching at the specified position.
	 * @param isRegex Used to indicate that `searchString` is a regular expression.
	 * @param matchCase Force the matching to match lower/upper case exactly.
	 * @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
	 * @param captureMatches The result will contain the captured groups.
	 * @return The range where the previous match is. It is null if no previous match has been found.
	 */
A
Alex Dima 已提交
838
	findPreviousMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;
839

A
Alex Dima 已提交
840 841 842 843 844
	/**
	 * @internal
	 */
	setTokens(tokens: MultilineTokens[]): void;

A
Alexandru Dima 已提交
845 846 847
	/**
	 * @internal
	 */
848 849 850 851 852
	setSemanticTokens(tokens: MultilineTokens2[] | null, isComplete: boolean): void;

	/**
	 * @internal
	 */
A
Alex Dima 已提交
853
	setPartialSemanticTokens(range: Range, tokens: MultilineTokens2[] | null): void;
854 855 856 857 858

	/**
	 * @internal
	 */
	hasSemanticTokens(): boolean;
A
Alexandru Dima 已提交
859

A
Alex Dima 已提交
860 861 862 863
	/**
	 * Flush all tokenization state.
	 * @internal
	 */
864
	resetTokenization(): void;
A
Alex Dima 已提交
865

866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
	/**
	 * Force tokenization information for `lineNumber` to be accurate.
	 * @internal
	 */
	forceTokenization(lineNumber: number): void;

	/**
	 * If it is cheap, force tokenization information for `lineNumber` to be accurate.
	 * This is based on a heuristic.
	 * @internal
	 */
	tokenizeIfCheap(lineNumber: number): void;

	/**
	 * Check if calling `forceTokenization` for this `lineNumber` will be cheap (time-wise).
	 * This is based on a heuristic.
	 * @internal
	 */
	isCheapToTokenize(lineNumber: number): boolean;

	/**
	 * Get the tokens for the line `lineNumber`.
	 * The tokens might be inaccurate. Use `forceTokenization` to ensure accurate tokens.
	 * @internal
	 */
	getLineTokens(lineNumber: number): LineTokens;

	/**
	 * Get the language associated with this model.
	 * @internal
	 */
	getLanguageIdentifier(): LanguageIdentifier;

	/**
	 * Get the language associated with this model.
	 */
	getModeId(): string;

	/**
	 * Set the current language mode associated with the model.
	 * @internal
	 */
	setMode(languageIdentifier: LanguageIdentifier): void;

	/**
	 * Returns the real (inner-most) language mode at a given position.
	 * The result might be inaccurate. Use `forceTokenization` to ensure accurate tokens.
	 * @internal
	 */
	getLanguageIdAtPosition(lineNumber: number, column: number): LanguageId;

	/**
	 * Get the word under or besides `position`.
	 * @param position The position to look for a word.
	 * @return The word under or besides `position`. Might be null.
	 */
A
Alex Dima 已提交
922
	getWordAtPosition(position: IPosition): IWordAtPosition | null;
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937

	/**
	 * Get the word under or besides `position` trimmed to `position`.column
	 * @param position The position to look for a word.
	 * @return The word under or besides `position`. Will never be null.
	 */
	getWordUntilPosition(position: IPosition): IWordAtPosition;

	/**
	 * Find the matching bracket of `request` up, counting brackets.
	 * @param request The bracket we're searching for
	 * @param position The position at which to start the search.
	 * @return The range of the matching bracket, or null if the bracket match was not found.
	 * @internal
	 */
A
Alex Dima 已提交
938
	findMatchingBracketUp(bracket: string, position: IPosition): Range | null;
939 940 941 942 943 944 945

	/**
	 * Find the first bracket in the model before `position`.
	 * @param position The position at which to start the search.
	 * @return The info for the first bracket before `position`, or null if there are no more brackets before `positions`.
	 * @internal
	 */
A
Alex Dima 已提交
946
	findPrevBracket(position: IPosition): IFoundBracket | null;
947 948 949 950 951 952 953

	/**
	 * Find the first bracket in the model after `position`.
	 * @param position The position at which to start the search.
	 * @return The info for the first bracket after `position`, or null if there are no more brackets after `positions`.
	 * @internal
	 */
A
Alex Dima 已提交
954
	findNextBracket(position: IPosition): IFoundBracket | null;
955

956 957 958 959 960
	/**
	 * Find the enclosing brackets that contain `position`.
	 * @param position The position at which to start the search.
	 * @internal
	 */
961
	findEnclosingBrackets(position: IPosition, maxDuration?: number): [Range, Range] | null;
962

963 964 965 966 967 968
	/**
	 * Given a `position`, if the position is on top or near a bracket,
	 * find the matching bracket of that bracket and return the ranges of both brackets.
	 * @param position The position at which to look for a bracket.
	 * @internal
	 */
A
Alex Dima 已提交
969
	matchBracket(position: IPosition): [Range, Range] | null;
970

A
Alex Dima 已提交
971 972 973
	/**
	 * @internal
	 */
974
	getActiveIndentGuide(lineNumber: number, minLineNumber: number, maxLineNumber: number): IActiveIndentGuideInfo;
A
Alex Dima 已提交
975

976 977 978 979 980 981 982 983 984 985 986 987 988
	/**
	 * @internal
	 */
	getLinesIndentGuides(startLineNumber: number, endLineNumber: number): number[];

	/**
	 * Change the decorations. The callback will be called with a change accessor
	 * that becomes invalid as soon as the callback finishes executing.
	 * This allows for all events to be queued up until the change
	 * is completed. Returns whatever the callback returns.
	 * @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.
	 * @internal
	 */
A
Alex Dima 已提交
989
	changeDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T, ownerId?: number): T | null;
990 991

	/**
A
Alex Dima 已提交
992
	 * Perform a minimum amount of operations, in order to transform the decorations
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
	 * identified by `oldDecorations` to the decorations described by `newDecorations`
	 * and returns the new identifiers associated with the resulting decorations.
	 *
	 * @param oldDecorations Array containing previous decorations identifiers.
	 * @param newDecorations Array describing what decorations should result after the call.
	 * @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.
	 * @return An array containing the new decorations identifiers.
	 */
	deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[], ownerId?: number): string[];

	/**
	 * Remove all decorations that have been added with this specific ownerId.
	 * @param ownerId The owner id to search for.
	 * @internal
	 */
	removeAllDecorationsWithOwnerId(ownerId: number): void;

	/**
	 * Get the options associated with a decoration.
	 * @param id The decoration id.
	 * @return The decoration options or null if the decoration was not found.
	 */
A
Alex Dima 已提交
1015
	getDecorationOptions(id: string): IModelDecorationOptions | null;
1016 1017 1018 1019 1020 1021

	/**
	 * Get the range associated with a decoration.
	 * @param id The decoration id.
	 * @return The decoration range or null if the decoration was not found.
	 */
A
Alex Dima 已提交
1022
	getDecorationRange(id: string): Range | null;
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043

	/**
	 * Gets all the decorations for the line `lineNumber` as an array.
	 * @param lineNumber The line number
	 * @param ownerId If set, it will ignore decorations belonging to other owners.
	 * @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
	 * @return An array with the decorations
	 */
	getLineDecorations(lineNumber: number, ownerId?: number, filterOutValidation?: boolean): IModelDecoration[];

	/**
	 * Gets all the decorations for the lines between `startLineNumber` and `endLineNumber` as an array.
	 * @param startLineNumber The start line number
	 * @param endLineNumber The end line number
	 * @param ownerId If set, it will ignore decorations belonging to other owners.
	 * @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
	 * @return An array with the decorations
	 */
	getLinesDecorations(startLineNumber: number, endLineNumber: number, ownerId?: number, filterOutValidation?: boolean): IModelDecoration[];

	/**
A
Alex Dima 已提交
1044
	 * Gets all the decorations in a range as an array. Only `startLineNumber` and `endLineNumber` from `range` are used for filtering.
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
	 * So for now it returns all the decorations on the same line as `range`.
	 * @param range The range to search in
	 * @param ownerId If set, it will ignore decorations belonging to other owners.
	 * @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
	 * @return An array with the decorations
	 */
	getDecorationsInRange(range: IRange, ownerId?: number, filterOutValidation?: boolean): IModelDecoration[];

	/**
	 * Gets all the decorations as an array.
	 * @param ownerId If set, it will ignore decorations belonging to other owners.
	 * @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
	 */
	getAllDecorations(ownerId?: number, filterOutValidation?: boolean): IModelDecoration[];

	/**
	 * Gets all the decorations that should be rendered in the overview ruler as an array.
	 * @param ownerId If set, it will ignore decorations belonging to other owners.
	 * @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
	 */
	getOverviewRulerDecorations(ownerId?: number, filterOutValidation?: boolean): IModelDecoration[];

	/**
	 * @internal
	 */
A
Alex Dima 已提交
1070
	_getTrackedRange(id: string): Range | null;
1071 1072 1073 1074

	/**
	 * @internal
	 */
A
Alex Dima 已提交
1075 1076 1077 1078 1079
	_setTrackedRange(id: string | null, newRange: null, newStickiness: TrackedRangeStickiness): null;
	/**
	 * @internal
	 */
	_setTrackedRange(id: string | null, newRange: Range, newStickiness: TrackedRangeStickiness): string;
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105

	/**
	 * Normalize a string containing whitespace according to indentation rules (converts to spaces or to tabs).
	 */
	normalizeIndentation(str: string): string;

	/**
	 * Change the options of this model.
	 */
	updateOptions(newOpts: ITextModelUpdateOptions): void;

	/**
	 * Detect the indentation options for this model from its content.
	 */
	detectIndentation(defaultInsertSpaces: boolean, defaultTabSize: number): void;

	/**
	 * Push a stack element onto the undo stack. This acts as an undo/redo point.
	 * The idea is to use `pushEditOperations` to edit the model and then to
	 * `pushStackElement` to create an undo/redo stop point.
	 */
	pushStackElement(): void;

	/**
	 * Push edit operations, basically editing the model. This is the preferred way
	 * of editing the model. The edit operations will land on the undo stack.
A
Alex Dima 已提交
1106
	 * @param beforeCursorState The cursor state before the edit operations. This cursor state will be returned when `undo` or `redo` are invoked.
1107 1108 1109 1110
	 * @param editOperations The edit operations.
	 * @param cursorStateComputer A callback that can compute the resulting cursors state after the edit operations have been executed.
	 * @return The cursor state returned by the `cursorStateComputer`.
	 */
A
Alex Dima 已提交
1111
	pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;
1112

A
Alex Dima 已提交
1113 1114 1115 1116 1117 1118
	/**
	 * Change the end of line sequence. This is the preferred way of
	 * changing the eol sequence. This will land on the undo stack.
	 */
	pushEOL(eol: EndOfLineSequence): void;

1119 1120 1121 1122
	/**
	 * Edit the model without adding the edits to the undo stack.
	 * This can have dire consequences on the undo stack! See @pushEditOperations for the preferred way.
	 * @param operations The edit operations.
1123
	 * @return If desired, the inverse edit operations, that, when applied, will bring the model back to the previous state.
1124
	 */
1125 1126 1127
	applyEdits(operations: IIdentifiedSingleEditOperation[]): void;
	applyEdits(operations: IIdentifiedSingleEditOperation[], computeUndoEdits: false): void;
	applyEdits(operations: IIdentifiedSingleEditOperation[], computeUndoEdits: true): IValidEditOperation[];
1128

A
Alex Dima 已提交
1129 1130 1131 1132 1133 1134
	/**
	 * Change the end of line sequence without recording in the undo stack.
	 * This can have dire consequences on the undo stack! See @pushEOL for the preferred way.
	 */
	setEOL(eol: EndOfLineSequence): void;

1135 1136 1137
	/**
	 * @internal
	 */
1138 1139 1140 1141 1142 1143
	_applyUndo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;

	/**
	 * @internal
	 */
	_applyRedo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;
1144

1145 1146 1147 1148 1149
	/**
	 * Undo edit operations until the first previous stop point created by `pushStackElement`.
	 * The inverse edit operations will be pushed on the redo stack.
	 * @internal
	 */
A
Alex Dima 已提交
1150
	undo(): void | Promise<void>;
1151

A
Alex Dima 已提交
1152 1153 1154 1155 1156 1157
	/**
	 * Is there anything in the undo stack?
	 * @internal
	 */
	canUndo(): boolean;

1158 1159 1160 1161 1162
	/**
	 * Redo edit operations until the next stop point created by `pushStackElement`.
	 * The inverse edit operations will be pushed on the undo stack.
	 * @internal
	 */
A
Alex Dima 已提交
1163
	redo(): void | Promise<void>;
1164

A
Alex Dima 已提交
1165 1166 1167 1168 1169 1170
	/**
	 * Is there anything in the redo stack?
	 * @internal
	 */
	canRedo(): boolean;

1171 1172 1173 1174 1175 1176 1177
	/**
	 * @deprecated Please use `onDidChangeContent` instead.
	 * An event emitted when the contents of the model have changed.
	 * @internal
	 * @event
	 */
	onDidChangeRawContentFast(listener: (e: ModelRawContentChangedEvent) => void): IDisposable;
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
	/**
	 * @deprecated Please use `onDidChangeContent` instead.
	 * An event emitted when the contents of the model have changed.
	 * @internal
	 * @event
	 */
	onDidChangeRawContent(listener: (e: ModelRawContentChangedEvent) => void): IDisposable;
	/**
	 * An event emitted when the contents of the model have changed.
	 * @event
	 */
	onDidChangeContent(listener: (e: IModelContentChangedEvent) => void): IDisposable;
	/**
	 * An event emitted when decorations of the model have changed.
	 * @event
	 */
	onDidChangeDecorations(listener: (e: IModelDecorationsChangedEvent) => void): IDisposable;
	/**
	 * An event emitted when the model options have changed.
	 * @event
	 */
	onDidChangeOptions(listener: (e: IModelOptionsChangedEvent) => void): IDisposable;
	/**
	 * An event emitted when the language associated with the model has changed.
	 * @event
	 */
	onDidChangeLanguage(listener: (e: IModelLanguageChangedEvent) => void): IDisposable;
	/**
	 * An event emitted when the language configuration associated with the model has changed.
	 * @event
	 */
	onDidChangeLanguageConfiguration(listener: (e: IModelLanguageConfigurationChangedEvent) => void): IDisposable;
	/**
	 * An event emitted when the tokens associated with the model have changed.
	 * @event
	 * @internal
	 */
	onDidChangeTokens(listener: (e: IModelTokensChangedEvent) => void): IDisposable;
1216 1217 1218 1219 1220 1221
	/**
	 * An event emitted when the model has been attached to the first editor or detached from the last editor.
	 * @event
	 * @internal
	 */
	onDidChangeAttached(listener: () => void): IDisposable;
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
	/**
	 * An event emitted right before disposing the model.
	 * @event
	 */
	onWillDispose(listener: () => void): IDisposable;

	/**
	 * Destroy this model. This will unbind the model from the mode
	 * and make all necessary clean-up to release this object to the GC.
	 */
	dispose(): void;

	/**
	 * @internal
	 */
	onBeforeAttached(): void;

	/**
	 * @internal
	 */
	onBeforeDetached(): void;

	/**
	 * Returns if this model is attached to an editor or not.
	 * @internal
	 */
	isAttachedToEditor(): boolean;
1249 1250 1251 1252 1253 1254

	/**
	 * Returns the count of editors this model is attached to.
	 * @internal
	 */
	getAttachedEditorCount(): number;
1255
}
A
Alex Dima 已提交
1256

A
Alex Dima 已提交
1257 1258 1259 1260
/**
 * @internal
 */
export interface ITextBufferBuilder {
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
	acceptChunk(chunk: string): void;
	finish(): ITextBufferFactory;
}

/**
 * @internal
 */
export interface ITextBufferFactory {
	create(defaultEOL: DefaultEndOfLine): ITextBuffer;
	getFirstLineText(lengthLimit: number): string;
A
Alex Dima 已提交
1271 1272
}

1273 1274 1275 1276 1277 1278 1279
/**
 * @internal
 */
export const enum ModelConstants {
	FIRST_LINE_DETECTION_LENGTH_LIMIT = 1000
}

1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
/**
 * @internal
 */
export class ValidAnnotatedEditOperation implements IIdentifiedSingleEditOperation {
	constructor(
		public readonly identifier: ISingleEditOperationIdentifier | null,
		public readonly range: Range,
		public readonly text: string | null,
		public readonly forceMoveMarkers: boolean,
		public readonly isAutoWhitespaceEdit: boolean,
		public readonly _isTracked: boolean,
	) { }
}

A
Alex Dima 已提交
1294 1295 1296
/**
 * @internal
 */
1297
export interface IReadonlyTextBuffer {
1298
	onDidChangeContent: Event<void>;
1299
	equals(other: ITextBuffer): boolean;
A
Alex Dima 已提交
1300
	mightContainRTL(): boolean;
1301 1302
	mightContainUnusualLineTerminators(): boolean;
	resetMightContainUnusualLineTerminators(): void;
A
Alex Dima 已提交
1303 1304 1305 1306 1307 1308 1309 1310 1311
	mightContainNonBasicASCII(): boolean;
	getBOM(): string;
	getEOL(): string;

	getOffsetAt(lineNumber: number, column: number): number;
	getPositionAt(offset: number): Position;
	getRangeAt(offset: number, length: number): Range;

	getValueInRange(range: Range, eol: EndOfLinePreference): string;
1312
	createSnapshot(preserveBOM: boolean): ITextSnapshot;
A
Alex Dima 已提交
1313
	getValueLengthInRange(range: Range, eol: EndOfLinePreference): number;
1314
	getCharacterCountInRange(range: Range, eol: EndOfLinePreference): number;
1315
	getLength(): number;
A
Alex Dima 已提交
1316 1317 1318 1319
	getLineCount(): number;
	getLinesContent(): string[];
	getLineContent(lineNumber: number): string;
	getLineCharCode(lineNumber: number, index: number): number;
R
rebornix 已提交
1320
	getCharCode(offset: number): number;
A
Alex Dima 已提交
1321 1322 1323
	getLineLength(lineNumber: number): number;
	getLineFirstNonWhitespaceColumn(lineNumber: number): number;
	getLineLastNonWhitespaceColumn(lineNumber: number): number;
1324 1325
	findMatchesLineByLine(searchRange: Range, searchData: SearchData, captureMatches: boolean, limitResultCount: number): FindMatch[];
}
A
Alex Dima 已提交
1326

1327 1328 1329
/**
 * @internal
 */
1330
export interface ITextBuffer extends IReadonlyTextBuffer {
A
Alex Dima 已提交
1331
	setEOL(newEOL: '\r\n' | '\n'): void;
1332
	applyEdits(rawOperations: ValidAnnotatedEditOperation[], recordTrimAutoWhitespace: boolean, computeUndoEdits: boolean): ApplyEditsResult;
A
Alex Dima 已提交
1333 1334 1335 1336 1337 1338 1339 1340
}

/**
 * @internal
 */
export class ApplyEditsResult {

	constructor(
1341
		public readonly reverseEdits: IValidEditOperation[] | null,
A
Alex Dima 已提交
1342
		public readonly changes: IInternalModelContentChange[],
A
Alex Dima 已提交
1343
		public readonly trimAutoWhitespaceLineNumbers: number[] | null
A
Alex Dima 已提交
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
	) { }

}

/**
 * @internal
 */
export interface IInternalModelContentChange extends IModelContentChange {
	range: Range;
	forceMoveMarkers: boolean;
}