From 12da7148033b9be222aa7636391de002e5c5ba79 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Wed, 27 Sep 2023 13:25:49 -0700 Subject: [PATCH] Redirect vscode New Jupyter Notebook command (#24520) --- extensions/ipynb/package.json | 5 ++-- extensions/ipynb/src/ipynbMain.ts | 37 +++++++++++++++----------- extensions/ipynb/src/typings/refs.d.ts | 10 +++++++ 3 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 extensions/ipynb/src/typings/refs.d.ts diff --git a/extensions/ipynb/package.json b/extensions/ipynb/package.json index 73896ed47b..67548cd8b8 100644 --- a/extensions/ipynb/package.json +++ b/extensions/ipynb/package.json @@ -6,7 +6,8 @@ "version": "1.0.0", "license": "MIT", "engines": { - "vscode": "^1.57.0" + "vscode": "^1.57.0", + "azdata": "*" }, "enabledApiProposals": [ "documentPaste", @@ -14,7 +15,7 @@ "dropMetadata" ], "activationEvents": [ - "*" + "onNotebook:jupyter-notebook" ], "extensionKind": [ "workspace", diff --git a/extensions/ipynb/src/ipynbMain.ts b/extensions/ipynb/src/ipynbMain.ts index e90376f9e0..cfec9013ca 100644 --- a/extensions/ipynb/src/ipynbMain.ts +++ b/extensions/ipynb/src/ipynbMain.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import * as azdata from 'azdata'; // {{SQL CARBON EDIT}} import { NotebookSerializer } from './notebookSerializer'; import { ensureAllNewCellsHaveCellIds } from './cellIdService'; import { notebookImagePasteSetup } from './notebookImagePaste'; @@ -58,21 +59,27 @@ 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); + // {{SQL CARBON EDIT}} Open new notebooks using the default ADS notebook viewer if VSCode notebooks aren't enabled. + let useVSCodeNotebooks = vscode.workspace.getConfiguration('workbench')?.get('useVSCodeNotebooks'); + if (useVSCodeNotebooks) { + 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); + } else { + await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' })); + } })); context.subscriptions.push(vscode.commands.registerCommand('ipynb.openIpynbInNotebookEditor', async (uri: vscode.Uri) => { diff --git a/extensions/ipynb/src/typings/refs.d.ts b/extensions/ipynb/src/typings/refs.d.ts new file mode 100644 index 0000000000..c0b50aa7f0 --- /dev/null +++ b/extensions/ipynb/src/typings/refs.d.ts @@ -0,0 +1,10 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// {{SQL CARBON EDIT}} Import ADS extension APIs +/// +/// +/// +///