import * as vscode from 'vscode' ; import { ensureAllNewCellsHaveCellIds } from './cellIdService' ; import { NotebookSerializer } from './notebookSerializer' ; type NotebookMetadata = { kernelspec ? : { name : string ; display_name : string ; [ propName ] : unknown ; } ; language_info ? : { name : string ; codemirror_mode ? : string | { } ; file_extension ? : string ; mimetype ? : string ; pygments_lexer ? : string ; [ propName ] : unknown ; } ; orig_nbformat : number ; [ propName ] : unknown ; } ; export function activate ( context ) { const serializer = new NotebookSerializer ( context ) ; ensureAllNewCellsHaveCellIds ( context ) ; context . subscriptions . push ( vscode . workspace . registerNotebookSerializer ( 'jupyter-notebook' , serializer , { transientOutputs : false , transientCellMetadata : { breakpointMargin : true , custom : false } } ) ) ; return { exportNotebook : ( notebook ) : string => { return exportNotebook ( notebook , serializer ) ; } , setNotebookMetadata : async ( resource , metadata ) : Promise < boolean > => { const document = vscode . workspace . notebookDocuments . find ( doc => doc . uri . toString ( ) === resource . toString ( ) ) ; if ( ! document ) { return false ; } const edit = new vscode . WorkspaceEdit ( ) ; edit . replaceNotebookMetadata ( resource , { ... document . metadata , custom : { ... ( document . metadata . custom ?? { } ) , metadata : < NotebookMetadata > { ... ( document . metadata . custom ?. metadata ?? { } ) , ... metadata } , } } ) ; return vscode . workspace . applyEdit ( edit ) ; } , } ; } function exportNotebook ( notebook , serializer ) { return serializer . serializeNotebookToString ( notebook ) ; } export function deactivate ( ) { }