Merge pull request #151377 from rchiodo/rchiodo/fix_notebook_metadata

Fix new notebook metadata API to update metadata
pull/151383/head
Rich Chiodo 2022-06-06 17:17:03 -07:00 committed by GitHub
commit 41317f9ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -263,14 +263,25 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
const editor = await vscode.window.showNotebookDocument(notebook);
const notebookChangeEvent = asPromise<vscode.NotebookDocumentChangeEvent>(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 metdataEdit = vscode.NotebookEdit.updateNotebookMetadata({ ...notebook.metadata, custom: { ...(notebook.metadata.custom || {}), extraNotebookMetadata: true } });
edit.set(notebook.uri, [cellEdit, metdataEdit]);
await vscode.workspace.applyEdit(edit);
await notebookChangeEvent;
assert.strictEqual(version + 1, editor.document.version);
const notebookChangeEvent2 = asPromise<vscode.NotebookDocumentChangeEvent>(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`);
});
test('edit API batch edits undo/redo', async function () {

View File

@ -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);
}