diff --git a/extensions/vscode-notebook-tests/src/notebook.test.ts b/extensions/vscode-notebook-tests/src/notebook.test.ts index 25c2ea72daa052d453a74f15663ccf53bdd4b49b..658500995f74c0fa903b149d591b74764a28315e 100644 --- a/extensions/vscode-notebook-tests/src/notebook.test.ts +++ b/extensions/vscode-notebook-tests/src/notebook.test.ts @@ -321,6 +321,19 @@ suite('notebook working copy', () => { }); }); +suite('metadata', () => { + test('custom metadata should be supported', async function () { + const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb')); + await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); + + await waitFor(500); + assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.notebook.activeNotebookEditor!.document.metadata.custom['testMetadata'] as boolean, false); + assert.equal(vscode.notebook.activeNotebookEditor!.selection?.metadata.custom['testCellMetadata'] as boolean, true); + assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + }); +}); + suite('regression', () => { test('microsoft/vscode-github-issue-notebooks#26. Insert template cell in the new empty document', async function () { const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './empty.vsctestnb')); diff --git a/extensions/vscode-notebook-tests/src/notebookTestMain.ts b/extensions/vscode-notebook-tests/src/notebookTestMain.ts index 92abe38dfb7f5b01f7f7f57c6248f98c1cc73041..e7320ffa8bfb51a45ce32fa83b57b84320f0d756 100644 --- a/extensions/vscode-notebook-tests/src/notebookTestMain.ts +++ b/extensions/vscode-notebook-tests/src/notebookTestMain.ts @@ -17,19 +17,25 @@ export function activate(context: vscode.ExtensionContext): any { }; } - return { + const dto: vscode.NotebookData = { languages: ['typescript'], - metadata: {}, + metadata: { + custom: { testMetadata: false } + }, cells: [ { source: 'test', language: 'typescript', cellKind: vscode.CellKind.Code, outputs: [], - metadata: {} + metadata: { + custom: { testCellMetadata: true } + } } ] }; + + return dto; }, executeCell: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell | undefined, _token: vscode.CancellationToken) => { if (!_cell) { diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index e11b7113e44e74a1ff02acbb1dcee7910f565988..cbd20cb0a4893e9607046accfcaf2a8de5082639 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1590,6 +1590,11 @@ declare module 'vscode' { * The total duration of the cell's last run */ lastRunDuration?: number; + + /** + * Additional attributes of a cell metadata. + */ + [key: string]: any; } export interface NotebookCell { @@ -1635,6 +1640,11 @@ declare module 'vscode' { hasExecutionOrder?: boolean; displayOrder?: GlobPattern[]; + + /** + * Additional attributes of a cell metadata. + */ + [key: string]: any; } export interface NotebookDocument { diff --git a/src/vs/workbench/api/browser/mainThreadNotebook.ts b/src/vs/workbench/api/browser/mainThreadNotebook.ts index d4bdc4310f0c05a3dcee4b1a44cd2d0f64272893..9313542a8857d4c13266122d27dac95b9a1a4f4c 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebook.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebook.ts @@ -38,7 +38,7 @@ export class MainThreadNotebookDocument extends Disposable { })); this._register(this._textModel.onDidSelectionChange(e => { const selectionsChange = e ? { selections: e } : null; - this._proxy.$acceptEditorPropertiesChanged(uri, { selections: selectionsChange }); + this._proxy.$acceptEditorPropertiesChanged(uri, { selections: selectionsChange, metadata: null }); })); } @@ -250,6 +250,8 @@ export class MainThreadNotebookController implements IMainNotebookController { document.textModel.insertTemplateCell(mainCell); } + this._proxy.$acceptEditorPropertiesChanged(uri, { selections: null, metadata: document.textModel.metadata }); + return document.textModel; } @@ -285,7 +287,8 @@ export class MainThreadNotebookController implements IMainNotebookController { addedDocuments: [{ viewType: document.viewType, handle: document.handle, - uri: document.uri + uri: document.uri, + metadata: document.textModel.metadata }] }); } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 066b3cb24e5fbfe2ae1d00acd6853a85fc2d8e89..99fec99d3682c79b109a895e993b1e0d8bc66f23 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1539,6 +1539,7 @@ export interface INotebookSelectionChangeEvent { export interface INotebookEditorPropertiesChangeData { selections: INotebookSelectionChangeEvent | null; + metadata: NotebookDocumentMetadata | null; } export interface INotebookModelAddedData { @@ -1546,6 +1547,7 @@ export interface INotebookModelAddedData { handle: number; // versionId: number; viewType: string; + metadata?: NotebookDocumentMetadata; } export interface INotebookDocumentsAndEditorsDelta { diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index f8b29fd0fa704334ed1dec181b4458245d3bb8c0..bd56fb03304844d22c097ac358fa0c18cd8b7307 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -949,6 +949,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN editor.editor.selection = undefined; } } + + if (data.metadata) { + editor.editor.document.metadata = { + ...notebookDocumentMetadataDefaults, + ...data.metadata + }; + } } async $acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta) { @@ -978,6 +985,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN const viewType = modelData.viewType; if (!this._documents.has(revivedUri.toString())) { let document = new ExtHostNotebookDocument(this._proxy, this._documentsAndEditors, viewType, revivedUri, this); + if (modelData.metadata) { + document.metadata = { + ...notebookDocumentMetadataDefaults, + ...modelData.metadata + }; + } + this._documents.set(revivedUri.toString(), document); } diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 178e0d8bb8e891484e693b013acf2f6ae7f4ee8b..b34622ebc484bee6a5be5631e49996595cf0a333 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -55,7 +55,8 @@ export const notebookDocumentMetadataDefaults: Required