mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
re #142872. Contribute ipynb notebook to File -> New when no Jupyter extension enabled.
This commit is contained in:
parent
8e3c41760e
commit
4b17d05668
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue