re #142872. Contribute ipynb notebook to File -> New when no Jupyter extension enabled.

This commit is contained in:
rebornix 2022-02-16 11:42:34 -08:00
parent 8e3c41760e
commit 4b17d05668
No known key found for this signature in database
GPG key ID: 181FC90D15393C20
2 changed files with 40 additions and 2 deletions

View file

@ -13,7 +13,7 @@
"notebookEditorEdit"
],
"activationEvents": [
"onNotebook:jupyter-notebook"
"*"
],
"extensionKind": [
"workspace",
@ -28,6 +28,12 @@
}
},
"contributes": {
"commands": [
{
"command": "ipynb.newUntitledIpynb",
"title": "Jupyter Notebook"
}
],
"notebooks": [
{
"type": "jupyter-notebook",
@ -39,7 +45,15 @@
],
"priority": "default"
}
]
],
"menus": {
"file/newFile": [
{
"command": "ipynb.newUntitledIpynb",
"when": "!jupyterEnabled"
}
]
}
},
"scripts": {
"compile": "npx gulp compile-extension:ipynb",

View file

@ -37,6 +37,30 @@ export function activate(context: vscode.ExtensionContext) {
}
}));
context.subscriptions.push(vscode.commands.registerCommand('ipynb.newUntitledIpynb', async () => {
const language = 'python';
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, '', language);
const data = new vscode.NotebookData([cell]);
data.metadata = {
custom: {
cells: [],
metadata: {
orig_nbformat: 4
},
nbformat: 4,
nbformat_minor: 2
}
};
const doc = await vscode.workspace.openNotebookDocument('jupyter-notebook', data);
await vscode.window.showNotebookDocument(doc);
}));
// Update new file contribution
vscode.extensions.onDidChange(() => {
vscode.commands.executeCommand('setContext', 'jupyterEnabled', vscode.extensions.getExtension('ms-toolsai.jupyter'));
});
vscode.commands.executeCommand('setContext', 'jupyterEnabled', vscode.extensions.getExtension('ms-toolsai.jupyter'));
return {
exportNotebook: (notebook: vscode.NotebookData): string => {
return exportNotebook(notebook, serializer);