add showNotebookDocument overload or uri

This commit is contained in:
Johannes Rieken
2021-03-05 14:50:42 +01:00
parent ae2f3e07e1
commit 997c9f2930
4 changed files with 82 additions and 7 deletions

View File

@@ -0,0 +1,69 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as vscode from 'vscode';
import * as utils from '../utils';
suite('Notebook Editor', function () {
const contentProvider = new class implements vscode.NotebookContentProvider {
async openNotebook(uri: vscode.Uri, _openContext: vscode.NotebookDocumentOpenContext): Promise<vscode.NotebookData> {
return {
cells: [{ cellKind: vscode.NotebookCellKind.Code, source: uri.toString(), language: 'javascript', metadata: new vscode.NotebookCellMetadata(), outputs: [] }],
metadata: new vscode.NotebookDocumentMetadata()
};
}
async resolveNotebook(_document: vscode.NotebookDocument, _webview: vscode.NotebookCommunication) {
//
}
async saveNotebook(_document: vscode.NotebookDocument, _cancellation: vscode.CancellationToken) {
//
}
async saveNotebookAs(_targetResource: vscode.Uri, _document: vscode.NotebookDocument, _cancellation: vscode.CancellationToken) {
//
}
async backupNotebook(_document: vscode.NotebookDocument, _context: vscode.NotebookDocumentBackupContext, _cancellation: vscode.CancellationToken) {
return { id: '', delete() { } };
}
};
const disposables: vscode.Disposable[] = [];
suiteTeardown(async function () {
utils.assertNoRpc();
await utils.revertAllDirty();
await utils.closeAllEditors();
utils.disposeAll(disposables);
disposables.length = 0;
for (let doc of vscode.notebook.notebookDocuments) {
assert.strictEqual(doc.isDirty, false, doc.uri.toString());
}
});
suiteSetup(function () {
disposables.push(vscode.notebook.registerNotebookContentProvider('notebook.nbdtest', contentProvider));
});
test('showNotebookDocment', async function () {
const count1 = vscode.notebook.notebookDocuments.length;
const p = utils.asPromise(vscode.notebook.onDidOpenNotebookDocument);
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const editor = await vscode.window.showNotebookDocument(uri);
assert.strictEqual(uri.toString(), editor.document.uri.toString());
const event = await p;
assert.strictEqual(event.uri.toString(), uri.toString());
const count2 = vscode.notebook.notebookDocuments.length;
assert.strictEqual(count1 + 1, count2);
});
});