Closed
Description
As an extension developer, I sometimes want to get the content of a textDocument identified by a URI from VS Code, but without opening it and triggering onDidOpen
events.
My use case is extending the LanguageClient
to support the textDocument/xfiles
extension. Language servers in isolated environments need a way to request file contents without accessing the file system directly, and there should be a way to extend the LanguageClient
to support these requests as well. I cannot read from disk because the URI could also be the URI of an in-memory document.
There are probably other use cases where an extension needs to inspect file contents without wanting VS Code to open them.
Current API:
/**
* All text documents currently known to the system.
*
* @readonly
*/
export let textDocuments: TextDocument[];
/**
* Opens the denoted document from disk. Will return early if the
* document is already open, otherwise the document is loaded and the
* [open document](#workspace.onDidOpenTextDocument)-event fires.
* The document to open is denoted by the [uri](#Uri). Two schemes are supported:
*
* file: A file on disk, will be rejected if the file does not exist or cannot be loaded, e.g. `file:///Users/frodo/r.ini`.
* untitled: A new file that should be saved on disk, e.g. `untitled:c:\frodo\new.js`. The language will be derived from the file name.
*
* Uris with other schemes will make this method return a rejected promise.
*
* @param uri Identifies the resource to open.
* @return A promise that resolves to a [document](#TextDocument).
*/
export function openTextDocument(uri: Uri): Thenable<TextDocument>;
Proposal:
/**
* Like openTextDocument(), but does not fire an didOpen event and does not add the document to the textDocuments array.
*
* @param uri Identifies the resource to open.
* @return A promise that resolves to a [document](#TextDocument).
*/
export function getTextDocument(uri: Uri): Thenable<TextDocument>;