Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface TextDocument

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

Hierarchy

  • TextDocument

索引

Properties

Readonly uri

uri: Uri

The associated uri for this document.

Note that most documents use the file-scheme, which means they are files on disk. However, not all documents are saved on disk and therefore the scheme must be checked before trying to access the underlying file or siblings on disk.

see

FileSystemProvider

see

TextDocumentContentProvider

Readonly fileName

fileName: string

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

Readonly isUntitled

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.

Readonly languageId

languageId: string

The identifier of the language associated with this document.

Readonly version

version: number

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

Readonly isDirty

isDirty: boolean

true if there are unpersisted changes.

Readonly isClosed

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.

Readonly eol

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

Readonly lineCount

lineCount: number

The number of lines in this document.

Methods

save

  • Save the underlying file.

    Returns Thenable<boolean>

    A promise that will resolve to true when the file has been saved. If the file was not dirty or the save failed, will return false.

lineAt

  • 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.

    Parameters

    • line: number

      A line number in [0, lineCount).

    Returns TextLine

    A line.

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

    The position will be adjusted.

    see

    TextDocument.lineAt

    Parameters

    Returns TextLine

    A line.

offsetAt

  • Converts the position to a zero-based offset.

    The position will be adjusted.

    Parameters

    Returns number

    A valid zero-based offset.

positionAt

getText

  • getText(range?: Range): string
  • Get the text of this document. A substring can be retrieved by providing a range. The range will be adjusted.

    Parameters

    • Optional range: Range

      Include only the text included by the range.

    Returns string

    The text inside the provided range or the entire text.

getWordRangeAtPosition

  • getWordRangeAtPosition(position: Position, regex?: RegExp): undefined | 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.

    • Note 1: A custom regular expression must not match the empty string and if it does, it will be ignored.
    • Note 2: A custom regular expression will fail to match multiline strings and in the name of speed regular expressions should not match words with spaces. Use TextLine.text for more complex, non-wordy, scenarios.

    The position will be adjusted.

    Parameters

    • position: Position

      A position.

    • Optional regex: RegExp

      Optional regular expression that describes what a word is.

    Returns undefined | Range

    A range spanning a word, or undefined.

validateRange

  • Ensure a range is completely contained in this document.

    Parameters

    Returns Range

    The given range or a new, adjusted range.

validatePosition

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

    Parameters

    Returns Position

    The given position or a new, adjusted position.

Generated by TypeDoc