diff --git a/extensions/ipynb/src/ipynbMain.ts b/extensions/ipynb/src/ipynbMain.ts index 25aa98af6fcb2..5ac60c568e5d7 100644 --- a/extensions/ipynb/src/ipynbMain.ts +++ b/extensions/ipynb/src/ipynbMain.ts @@ -6,6 +6,25 @@ import * as vscode from 'vscode'; import { NotebookSerializer } from './notebookSerializer'; +// From {nbformat.INotebookMetadata} in @jupyterlab/coreutils +type NotebookMetadata = { + kernelspec?: { + name: string; + display_name: string; + [propName: string]: unknown; + }; + language_info?: { + name: string; + codemirror_mode?: string | {}; + file_extension?: string; + mimetype?: string; + pygments_lexer?: string; + [propName: string]: unknown; + }; + orig_nbformat: number; + [propName: string]: unknown; +}; + export function activate(context: vscode.ExtensionContext) { const serializer = new NotebookSerializer(context); context.subscriptions.push(vscode.workspace.registerNotebookSerializer('jupyter-notebook', serializer, { @@ -22,7 +41,7 @@ export function activate(context: vscode.ExtensionContext) { exportNotebook: (notebook: vscode.NotebookData): string => { return exportNotebook(notebook, serializer); }, - setKernelSpec: async (resource: vscode.Uri, kernelspec: unknown): Promise => { + setNotebookMetadata: async (resource: vscode.Uri, metadata: Partial): Promise => { const document = vscode.workspace.notebookDocuments.find(doc => doc.uri.toString() === resource.toString()); if (!document) { return false; @@ -33,9 +52,9 @@ export function activate(context: vscode.ExtensionContext) { ...document.metadata, custom: { ...(document.metadata.custom ?? {}), - metadata: { + metadata: { ...(document.metadata.custom?.metadata ?? {}), - kernelspec: kernelspec + ...metadata }, } });