mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Add API for setting kernelspec in ipynb files (#131219)
* Add API for setting kernelspec in ipynb files Fixes #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
This commit is contained in:
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user