Skip to content

Commit

Permalink
Merge pull request #132298 from davidanthoff/setKernelSpecAndLanguage…
Browse files Browse the repository at this point in the history
…Info

Add setKernelSpecAndLanguageInfo to ipynb ext
  • Loading branch information
DonJayamanne authored Sep 7, 2021
2 parents 30399ea + c962433 commit 2581658
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions extensions/ipynb/src/ipynbMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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<boolean> => {
setNotebookMetadata: async (resource: vscode.Uri, metadata: Partial<NotebookMetadata>): Promise<boolean> => {
const document = vscode.workspace.notebookDocuments.find(doc => doc.uri.toString() === resource.toString());
if (!document) {
return false;
Expand All @@ -33,9 +52,9 @@ export function activate(context: vscode.ExtensionContext) {
...document.metadata,
custom: {
...(document.metadata.custom ?? {}),
metadata: {
metadata: <NotebookMetadata>{
...(document.metadata.custom?.metadata ?? {}),
kernelspec: kernelspec
...metadata
},
}
});
Expand Down

0 comments on commit 2581658

Please sign in to comment.