From 2b71d110407705edaf3bf8a2db9b02291189ed78 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Mon, 6 Jun 2022 16:06:21 -0700 Subject: [PATCH 1/4] Fix for 151376 --- src/vs/workbench/api/common/extHostTypes.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index a1c2a3ea107..b5e2cd04ef9 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -807,6 +807,8 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { if (NotebookEdit.isNotebookCellEdit(edit)) { if (edit.newCellMetadata) { this.replaceNotebookCellMetadata(uri, edit.range.start, edit.newCellMetadata); + } else if (edit.newNotebookMetadata) { + this.replaceNotebookMetadata(uri, edit.newNotebookMetadata); } else { this.replaceNotebookCells(uri, edit.range, edit.newCells); } From 8f345dea8e227d8fba6e8f6bae0d7bc0db37e74c Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Mon, 6 Jun 2022 16:14:14 -0700 Subject: [PATCH 2/4] Add unit test --- .../src/singlefolder-tests/notebook.test.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts index 33cad6edb97..5f46ef80a56 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts @@ -263,14 +263,17 @@ const apiTestContentProvider: vscode.NotebookContentProvider = { const editor = await vscode.window.showNotebookDocument(notebook); const notebookChangeEvent = asPromise(vscode.workspace.onDidChangeNotebookDocument); - const version = editor.document.version; - await editor.edit(editBuilder => { - editBuilder.replaceCells(1, 0, [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]); - editBuilder.replaceCellMetadata(0, { inputCollapsed: false }); - }); - + const version = editor.notebook.version; + const edit = new vscode.WorkspaceEdit(); + const cellEdit = vscode.NotebookEdit.replaceCells(new vscode.NotebookRange(1, 0), [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]); + const cellMetadataEdit = vscode.NotebookEdit.updateCellMetadata(0, { inputCollapsed: false }); + const metdataEdit = vscode.NotebookEdit.updateNotebookMetadata({ testMetadata: false }); + edit.set(notebook.uri, [cellEdit, cellMetadataEdit, metdataEdit]); + await vscode.workspace.applyEdit(edit); await notebookChangeEvent; - assert.strictEqual(version + 1, editor.document.version); + assert.strictEqual(version + 1, editor.notebook.version); + assert.strictEqual(cellMetadataEdit.newCellMetadata, editor.notebook.cellAt(0).metadata); + assert.strictEqual(metdataEdit.newNotebookMetadata, editor.notebook.metadata); }); test('edit API batch edits undo/redo', async function () { From 416ad2cbc6c2d80855df9292e0e50022227bf9f2 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Mon, 6 Jun 2022 16:48:56 -0700 Subject: [PATCH 3/4] Can't get tests to run with local bits, try submitting --- .../src/singlefolder-tests/notebook.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts index 5f46ef80a56..0a6e9aa4b96 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts @@ -266,14 +266,16 @@ const apiTestContentProvider: vscode.NotebookContentProvider = { const version = editor.notebook.version; const edit = new vscode.WorkspaceEdit(); const cellEdit = vscode.NotebookEdit.replaceCells(new vscode.NotebookRange(1, 0), [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]); - const cellMetadataEdit = vscode.NotebookEdit.updateCellMetadata(0, { inputCollapsed: false }); - const metdataEdit = vscode.NotebookEdit.updateNotebookMetadata({ testMetadata: false }); + const cellMetadataEdit = vscode.NotebookEdit.updateCellMetadata(0, { extraCellMetadata: true }); + const metdataEdit = vscode.NotebookEdit.updateNotebookMetadata({ ...notebook.metadata, custom: { ...(notebook.metadata.custom || {}), extraNotebookMetadata: true } }); edit.set(notebook.uri, [cellEdit, cellMetadataEdit, metdataEdit]); await vscode.workspace.applyEdit(edit); await notebookChangeEvent; + assert.strictEqual(version + 1, editor.notebook.version); - assert.strictEqual(cellMetadataEdit.newCellMetadata, editor.notebook.cellAt(0).metadata); - assert.strictEqual(metdataEdit.newNotebookMetadata, editor.notebook.metadata); + const cell = editor.notebook.cellAt(0); + assert.ok(editor.notebook.metadata.custom.extraNotebookMetadata, `Test metadata not found`); + assert.ok(cell.metadata.extraCellMetadata, `Test cell metdata not found`); }); test('edit API batch edits undo/redo', async function () { From b658848c9b65b0d329442628870de5ada87847a6 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Mon, 6 Jun 2022 17:04:26 -0700 Subject: [PATCH 4/4] Fix test to work --- .../src/singlefolder-tests/notebook.test.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts index 0a6e9aa4b96..f863bf014b6 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts @@ -266,13 +266,19 @@ const apiTestContentProvider: vscode.NotebookContentProvider = { const version = editor.notebook.version; const edit = new vscode.WorkspaceEdit(); const cellEdit = vscode.NotebookEdit.replaceCells(new vscode.NotebookRange(1, 0), [{ kind: vscode.NotebookCellKind.Code, languageId: 'javascript', value: 'test 2', outputs: [], metadata: undefined }]); - const cellMetadataEdit = vscode.NotebookEdit.updateCellMetadata(0, { extraCellMetadata: true }); const metdataEdit = vscode.NotebookEdit.updateNotebookMetadata({ ...notebook.metadata, custom: { ...(notebook.metadata.custom || {}), extraNotebookMetadata: true } }); - edit.set(notebook.uri, [cellEdit, cellMetadataEdit, metdataEdit]); + edit.set(notebook.uri, [cellEdit, metdataEdit]); await vscode.workspace.applyEdit(edit); await notebookChangeEvent; - assert.strictEqual(version + 1, editor.notebook.version); + const notebookChangeEvent2 = asPromise(vscode.workspace.onDidChangeNotebookDocument); + const edit2 = new vscode.WorkspaceEdit(); + const cellMetadataEdit = vscode.NotebookEdit.updateCellMetadata(0, { extraCellMetadata: true }); + edit2.set(notebook.uri, [cellMetadataEdit]); + await vscode.workspace.applyEdit(edit2); + await notebookChangeEvent2; + + assert.strictEqual(version + 2, editor.notebook.version); const cell = editor.notebook.cellAt(0); assert.ok(editor.notebook.metadata.custom.extraNotebookMetadata, `Test metadata not found`); assert.ok(cell.metadata.extraCellMetadata, `Test cell metdata not found`);