mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 09:38:38 +01:00
Merge branch 'notebook/dev' into main
This commit is contained in:
@@ -248,67 +248,6 @@ suite('Notebook Document', function () {
|
||||
assert.strictEqual(data.changes[0].items[1], document.cellAt(1));
|
||||
});
|
||||
|
||||
test('workspace edit API (appendNotebookCellOutput, replaceCellOutput, event)', async function () {
|
||||
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const document = await vscode.notebook.openNotebookDocument(uri);
|
||||
|
||||
const outputChangeEvent = utils.asPromise<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs);
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
const firstCellOutput = new vscode.NotebookCellOutput([new vscode.NotebookCellOutputItem('foo', 'bar')]);
|
||||
edit.appendNotebookCellOutput(document.uri, 0, [firstCellOutput]);
|
||||
const success = await vscode.workspace.applyEdit(edit);
|
||||
const data = await outputChangeEvent;
|
||||
|
||||
assert.strictEqual(success, true);
|
||||
assert.strictEqual(document.cellCount, 1);
|
||||
assert.strictEqual(document.cellAt(0).outputs.length, 1);
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs, [firstCellOutput]);
|
||||
|
||||
assert.strictEqual(data.document === document, true);
|
||||
assert.strictEqual(data.cells.length, 1);
|
||||
assert.strictEqual(data.cells[0].outputs.length, 1);
|
||||
assert.deepStrictEqual(data.cells[0].outputs, [firstCellOutput]);
|
||||
|
||||
|
||||
{
|
||||
const outputChangeEvent = utils.asPromise<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs);
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
const secondCellOutput = new vscode.NotebookCellOutput([new vscode.NotebookCellOutputItem('foo', 'baz')]);
|
||||
edit.appendNotebookCellOutput(document.uri, 0, [secondCellOutput]);
|
||||
const success = await vscode.workspace.applyEdit(edit);
|
||||
const data = await outputChangeEvent;
|
||||
|
||||
assert.strictEqual(success, true);
|
||||
assert.strictEqual(document.cellCount, 1);
|
||||
assert.strictEqual(document.cellAt(0).outputs.length, 2);
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs, [firstCellOutput, secondCellOutput]);
|
||||
|
||||
assert.strictEqual(data.document === document, true);
|
||||
assert.strictEqual(data.cells.length, 1);
|
||||
assert.strictEqual(data.cells[0].outputs.length, 2);
|
||||
assert.deepStrictEqual(data.cells[0].outputs, [firstCellOutput, secondCellOutput]);
|
||||
}
|
||||
|
||||
{
|
||||
const outputChangeEvent = utils.asPromise<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs);
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
const thirdOutput = new vscode.NotebookCellOutput([new vscode.NotebookCellOutputItem('foo', 'baz1')]);
|
||||
edit.replaceNotebookCellOutput(document.uri, 0, [thirdOutput]);
|
||||
const success = await vscode.workspace.applyEdit(edit);
|
||||
const data = await outputChangeEvent;
|
||||
|
||||
assert.strictEqual(success, true);
|
||||
assert.strictEqual(document.cellCount, 1);
|
||||
assert.strictEqual(document.cellAt(0).outputs.length, 1);
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs, [thirdOutput]);
|
||||
|
||||
assert.strictEqual(data.document === document, true);
|
||||
assert.strictEqual(data.cells.length, 1);
|
||||
assert.strictEqual(data.cells[0].outputs.length, 1);
|
||||
assert.deepStrictEqual(data.cells[0].outputs, [thirdOutput]);
|
||||
}
|
||||
});
|
||||
|
||||
test('document save API', async function () {
|
||||
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const notebook = await vscode.notebook.openNotebookDocument(uri);
|
||||
@@ -375,45 +314,6 @@ suite('Notebook Document', function () {
|
||||
assert.strictEqual(cellDoc.languageId, 'css');
|
||||
});
|
||||
|
||||
test('#117273, Add multiple outputs', async function () {
|
||||
|
||||
const resource = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const document = await vscode.notebook.openNotebookDocument(resource);
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.replaceNotebookCellOutput(document.uri, 0, [
|
||||
new vscode.NotebookCellOutput(
|
||||
[new vscode.NotebookCellOutputItem('application/x.notebook.stream', '1', { outputType: 'stream', streamName: 'stdout' })],
|
||||
{ outputType: 'stream', streamName: 'stdout' }
|
||||
)
|
||||
]);
|
||||
let success = await vscode.workspace.applyEdit(edit);
|
||||
|
||||
assert.ok(success);
|
||||
assert.strictEqual(document.cellAt(0).outputs.length, 1);
|
||||
assert.strictEqual(document.cellAt(0).outputs[0].outputs.length, 1);
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
|
||||
|
||||
const edit2 = new vscode.WorkspaceEdit();
|
||||
edit2.appendNotebookCellOutput(document.uri, 0, [
|
||||
new vscode.NotebookCellOutput(
|
||||
[new vscode.NotebookCellOutputItem('hello', '1', { outputType: 'stream', streamName: 'stderr' })],
|
||||
{ outputType: 'stream', streamName: 'stderr' }
|
||||
)
|
||||
]);
|
||||
success = await vscode.workspace.applyEdit(edit2);
|
||||
assert.ok(success);
|
||||
|
||||
assert.strictEqual(document.cellAt(0).outputs.length, 2);
|
||||
assert.strictEqual(document.cellAt(0).outputs[0].outputs.length, 1);
|
||||
assert.strictEqual(document.cellAt(0).outputs[1].outputs.length, 1);
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs[1].metadata, { outputType: 'stream', streamName: 'stderr' });
|
||||
assert.deepStrictEqual(document.cellAt(0).outputs[1].outputs[0].metadata, { outputType: 'stream', streamName: 'stderr' });
|
||||
});
|
||||
|
||||
test('dirty state - complex', async function () {
|
||||
const resource = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const document = await vscode.notebook.openNotebookDocument(resource);
|
||||
|
||||
@@ -9,22 +9,15 @@ 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> {
|
||||
const contentSerializer = new class implements vscode.NotebookSerializer {
|
||||
deserializeNotebook() {
|
||||
return new vscode.NotebookData(
|
||||
[new vscode.NotebookCellData(vscode.NotebookCellKind.Code, uri.toString(), 'javascript')],
|
||||
[new vscode.NotebookCellData(vscode.NotebookCellKind.Code, '// code cell', 'javascript')],
|
||||
new vscode.NotebookDocumentMetadata()
|
||||
);
|
||||
|
||||
}
|
||||
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() { } };
|
||||
serializeNotebook() {
|
||||
return new Uint8Array();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,7 +36,7 @@ suite('Notebook Editor', function () {
|
||||
});
|
||||
|
||||
suiteSetup(function () {
|
||||
disposables.push(vscode.notebook.registerNotebookContentProvider('notebook.nbdtest', contentProvider));
|
||||
disposables.push(vscode.notebook.registerNotebookSerializer('notebook.nbdtest', contentSerializer));
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -1169,33 +1169,6 @@ suite('Notebook API tests', function () {
|
||||
await closeAllEditors();
|
||||
});
|
||||
|
||||
test('#116598, output items change event.', async function () {
|
||||
|
||||
const resource = await createRandomNotebookFile();
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.appendNotebookCellOutput(resource, 0, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('application/foo', 'bar'),
|
||||
new vscode.NotebookCellOutputItem('application/json', { data: true }, { metadata: true }),
|
||||
])]);
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0).outputs.length, 1);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0).outputs[0].outputs.length, 2);
|
||||
|
||||
const appendEdit = new vscode.WorkspaceEdit();
|
||||
const newItem = new vscode.NotebookCellOutputItem('text/plain', '1');
|
||||
appendEdit.appendNotebookCellOutputItems(
|
||||
resource,
|
||||
0,
|
||||
vscode.window.activeNotebookEditor!.document.cellAt(0).outputs[0].id,
|
||||
[newItem]
|
||||
);
|
||||
await vscode.workspace.applyEdit(appendEdit);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0).outputs[0].outputs.length, 3);
|
||||
assert.deepStrictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0).outputs[0].outputs[2], newItem);
|
||||
});
|
||||
|
||||
test('#115855 onDidSaveNotebookDocument', async function () {
|
||||
const resource = await createRandomNotebookFile();
|
||||
const notebook = await vscode.notebook.openNotebookDocument(resource);
|
||||
|
||||
Reference in New Issue
Block a user