Skip to content

Commit

Permalink
Add API for setting kernelspec in ipynb files (microsoft#131219)
Browse files Browse the repository at this point in the history
* Add API for setting kernelspec in ipynb files

Fixes microsoft#130602

This adds a new API to the built-in ipynb extension that lets other extension set the kernelspec metadata on a notebook file

* Temporarily skip the notebook editor tests

We need the new webview content to be published before these can run

* Use `custom`  instead of top level property
  • Loading branch information
mjbvz authored Aug 25, 2021
1 parent d152e72 commit d082058
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion extensions/ipynb/src/ipynbMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@ export function activate(context: vscode.ExtensionContext) {
return {
exportNotebook: (notebook: vscode.NotebookData): string => {
return exportNotebook(notebook, serializer);
}
},
setKernelSpec: async (resource: vscode.Uri, kernelspec: unknown): 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 ?? {}),
kernelspec: kernelspec
}
});
return vscode.workspace.applyEdit(edit);
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as assert from 'assert';
import * as vscode from 'vscode';
import * as utils from '../utils';

suite('Notebook Editor', function () {
suite.skip('Notebook Editor', function () {

const contentSerializer = new class implements vscode.NotebookSerializer {
deserializeNotebook() {
Expand Down

0 comments on commit d082058

Please sign in to comment.