TextDocument

interface TextDocument(source)

Represents a text document, such as a source file. Text documents have lines and knowledge about an underlying resource like a file.

Online Documentation

Properties

Link copied to clipboard
abstract val encoding: String

The file encoding of this document that will be used when the document is saved.

Link copied to clipboard
abstract val eol: EndOfLine

The end of line sequence that is predominately used in this document.

Link copied to clipboard
abstract val fileName: String

The file system path of the associated resource. Shorthand notation for TextDocument.uri.fsPath. Independent of the uri scheme.

Link copied to clipboard
abstract val isClosed: Boolean

true if the document has been closed. A closed document isn't synchronized anymore and won't be re-used when the same resource is opened again.

Link copied to clipboard
abstract val isDirty: Boolean

true if there are unpersisted changes.

Link copied to clipboard
abstract val isUntitled: Boolean

Is this document representing an untitled file which has never been saved yet. Note that this does not mean the document will be saved to disk, use Uri.scheme to figure out where a document will be saved, e.g. file, ftp etc.

Link copied to clipboard
abstract val languageId: String

The identifier of the language associated with this document.

Link copied to clipboard
abstract val lineCount: Int

The number of lines in this document.

Link copied to clipboard
abstract val uri: Uri

The associated uri for this document.

Link copied to clipboard
abstract val version: Int

The version number of this document (it will strictly increase after each change, including undo/redo).

Functions

Link copied to clipboard
abstract fun getText(range: Range = definedExternally): String

Get the text of this document. A substring can be retrieved by providing a range. The range will be adjusted.

Link copied to clipboard
abstract fun getWordRangeAtPosition(position: Position, regex: RegExp = definedExternally): Range?

Get a word-range at the given position. By default words are defined by common separators, like space, -, _, etc. In addition, per language custom word definitions can be defined. It is also possible to provide a custom regular expression.

Link copied to clipboard
abstract fun lineAt(line: Int): TextLine

Returns a text line denoted by the line number. Note that the returned object is not live and changes to the document are not reflected.

abstract fun lineAt(position: Position): TextLine

Returns a text line denoted by the position. Note that the returned object is not live and changes to the document are not reflected.

Link copied to clipboard
abstract fun offsetAt(position: Position): Int

Converts the position to a zero-based offset.

Link copied to clipboard
abstract fun positionAt(offset: Int): Position

Converts a zero-based offset to a position.

Link copied to clipboard
abstract fun save(): PromiseLike<JsBoolean>

Save the underlying file.

Link copied to clipboard
abstract fun validatePosition(position: Position): Position

Ensure a position is contained in the range of this document.

Link copied to clipboard
abstract fun validateRange(range: Range): Range

Ensure a range is completely contained in this document.