diff --git a/extensions/ipynb/package.json b/extensions/ipynb/package.json index 1fea9ef0e0e..1efd245ea17 100644 --- a/extensions/ipynb/package.json +++ b/extensions/ipynb/package.json @@ -32,6 +32,10 @@ { "command": "ipynb.newUntitledIpynb", "title": "Jupyter Notebook" + }, + { + "command": "ipynb.openIpynbInNotebookEditor", + "title": "Open ipynb file in notebook editor" } ], "notebooks": [ @@ -52,6 +56,16 @@ "command": "ipynb.newUntitledIpynb", "when": "!jupyterEnabled" } + ], + "commandPalette": [ + { + "command": "ipynb.newUntitledIpynb", + "when": "false" + }, + { + "command": "ipynb.openIpynbInNotebookEditor", + "when": "false" + } ] } }, diff --git a/extensions/ipynb/src/ipynbMain.ts b/extensions/ipynb/src/ipynbMain.ts index fad8331f960..5596117faab 100644 --- a/extensions/ipynb/src/ipynbMain.ts +++ b/extensions/ipynb/src/ipynbMain.ts @@ -37,6 +37,16 @@ export function activate(context: vscode.ExtensionContext) { } })); + vscode.languages.registerCodeLensProvider({ pattern: '**/*.ipynb' }, { + provideCodeLenses: (document) => { + if (document.uri.scheme === 'vscode-notebook-cell') { + return []; + } + const codelens = new vscode.CodeLens(new vscode.Range(0, 0, 0, 0), { title: 'Open in Notebook Editor', command: 'ipynb.openIpynbInNotebookEditor', arguments: [document.uri] }); + return [codelens]; + } + }); + context.subscriptions.push(vscode.commands.registerCommand('ipynb.newUntitledIpynb', async () => { const language = 'python'; const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, '', language); @@ -55,6 +65,14 @@ export function activate(context: vscode.ExtensionContext) { await vscode.window.showNotebookDocument(doc); })); + context.subscriptions.push(vscode.commands.registerCommand('ipynb.openIpynbInNotebookEditor', async (uri: vscode.Uri) => { + if (vscode.window.activeTextEditor?.document.uri.toString() === uri.toString()) { + await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); + } + const document = await vscode.workspace.openNotebookDocument(uri); + await vscode.window.showNotebookDocument(document); + })); + // Update new file contribution vscode.extensions.onDidChange(() => { vscode.commands.executeCommand('setContext', 'jupyterEnabled', vscode.extensions.getExtension('ms-toolsai.jupyter'));