From 30347c04f5869e45592fce0b2ee5e9f56c7d83d5 Mon Sep 17 00:00:00 2001 From: Konstantin Solomatov Date: Tue, 10 Sep 2019 22:38:48 -0700 Subject: [PATCH] findDocument API (work in progress) --- src/vs/vscode.d.ts | 8 ++++++++ src/vs/workbench/api/common/extHost.api.impl.ts | 4 ++++ .../workbench/test/common/editor/untitledEditor.test.ts | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index ab7024c4c862f..2fbe35f4b26f1 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -8050,6 +8050,14 @@ declare module 'vscode' { */ export const textDocuments: TextDocument[]; + /** + * Find a text document known to the system and return it or undefined if there's no such + * a document. + * + * @param uri Identifies the resource to open. + */ + export function findDocument(uri: Uri): TextDocument | undefined; + /** * Opens a document. Will return early if this document is already open. Otherwise * the document is loaded and the [didOpen](#workspace.onDidOpenTextDocument)-event fires. diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 8ad00122b890a..309dfbb301a26 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -617,6 +617,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I set textDocuments(value) { throw errors.readonly(); }, + findDocument(uri: vscode.Uri): vscode.TextDocument | undefined { + const documentData = extHostDocuments.getDocumentData(uri); + return documentData ? documentData.document : undefined; + }, openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) { let uriPromise: Thenable; diff --git a/src/vs/workbench/test/common/editor/untitledEditor.test.ts b/src/vs/workbench/test/common/editor/untitledEditor.test.ts index 001ad7a6a2bc3..5ce3d25064305 100644 --- a/src/vs/workbench/test/common/editor/untitledEditor.test.ts +++ b/src/vs/workbench/test/common/editor/untitledEditor.test.ts @@ -308,4 +308,4 @@ suite('Workbench untitled editors', () => { input.dispose(); assert.equal(counter, 1); }); -}); \ No newline at end of file +});