Theia API Documentation v1.65.0
    Preparing search index...
    • Opens a document. Will return early if this document is already open. Otherwise the document is loaded and the didOpen-event fires.

      The document is denoted by an Uri. Depending on the scheme the following rules apply:

      • file-scheme: Open a file on disk (openTextDocument(Uri.file(path))). Will be rejected if the file does not exist or cannot be loaded.
      • untitled-scheme: Open a blank untitled file with associated path (openTextDocument(Uri.file(path).with({ scheme: 'untitled' }))). The language will be derived from the file name.
      • For all other schemes contributed text document content providers and file system providers are consulted.

      Note that the lifecycle of the returned document is owned by the editor and not by the extension. That means an onDidClose-event can occur at any time after opening it.

      Parameters

      • uri: Uri

        Identifies the resource to open.

      • Optionaloptions: { encoding?: string }
        • Optional Readonlyencoding?: string

          The encoding of the document to use for decoding the underlying buffer to text. If omitted, the encoding will be guessed based on the file content and/or the editor settings unless the document is already opened.

          Opening a text document that was already opened with a different encoding has the potential of changing the text contents of the text document. Specifically, when the encoding results in a different set of characters than the previous encoding. As such, an error is thrown for dirty documents when the specified encoding is different from the encoding of the document.

          See TextDocument.encoding for more information about valid values for encoding. Using an unsupported encoding will fallback to the default encoding for the document.

          Note that if you open a document with an encoding that does not support decoding the underlying bytes, content may be replaced with substitution characters as appropriate.

      Returns Thenable<TextDocument>

      A promise that resolves to a document.

    • A short-hand for openTextDocument(Uri.file(path)).

      Parameters

      • path: string

        A path of a file on disk.

      • Optionaloptions: { encoding?: string }
        • Optional Readonlyencoding?: string

          The encoding of the document to use for decoding the underlying buffer to text. If omitted, the encoding will be guessed based on the file content and/or the editor settings unless the document is already opened.

          Opening a text document that was already opened with a different encoding has the potential of changing the text contents of the text document. Specifically, when the encoding results in a different set of characters than the previous encoding. As such, an error is thrown for dirty documents when the specified encoding is different from the encoding of the document.

          See TextDocument.encoding for more information about valid values for encoding. Using an unsupported encoding will fallback to the default encoding for the document.

          Note that if you open a document with an encoding that does not support decoding the underlying bytes, content may be replaced with substitution characters as appropriate.

      Returns Thenable<TextDocument>

      A promise that resolves to a document.

    • Opens an untitled text document. The editor will prompt the user for a file path when the document is to be saved. The options parameter allows to specify the language and/or the content of the document.

      Parameters

      • Optionaloptions: { content?: string; encoding?: string; language?: string }

        Options to control how the document will be created.

        • Optionalcontent?: string

          The initial contents of the document.

        • Optional Readonlyencoding?: string

          The encoding of the document.

          See TextDocument.encoding for more information about valid values for encoding. Using an unsupported encoding will fallback to the default encoding for the document.

        • Optionallanguage?: string

          The language of the document.

      Returns Thenable<TextDocument>

      A promise that resolves to a document.