Redirect vscode New Jupyter Notebook command (#24520)

This commit is contained in:
Cory Rivera
2023-09-27 13:25:49 -07:00
committed by GitHub
parent 131c288ab4
commit 12da714803
3 changed files with 35 additions and 17 deletions

View File

@@ -6,7 +6,8 @@
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"vscode": "^1.57.0" "vscode": "^1.57.0",
"azdata": "*"
}, },
"enabledApiProposals": [ "enabledApiProposals": [
"documentPaste", "documentPaste",
@@ -14,7 +15,7 @@
"dropMetadata" "dropMetadata"
], ],
"activationEvents": [ "activationEvents": [
"*" "onNotebook:jupyter-notebook"
], ],
"extensionKind": [ "extensionKind": [
"workspace", "workspace",

View File

@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as azdata from 'azdata'; // {{SQL CARBON EDIT}}
import { NotebookSerializer } from './notebookSerializer'; import { NotebookSerializer } from './notebookSerializer';
import { ensureAllNewCellsHaveCellIds } from './cellIdService'; import { ensureAllNewCellsHaveCellIds } from './cellIdService';
import { notebookImagePasteSetup } from './notebookImagePaste'; import { notebookImagePasteSetup } from './notebookImagePaste';
@@ -58,21 +59,27 @@ export function activate(context: vscode.ExtensionContext) {
}); });
context.subscriptions.push(vscode.commands.registerCommand('ipynb.newUntitledIpynb', async () => { context.subscriptions.push(vscode.commands.registerCommand('ipynb.newUntitledIpynb', async () => {
const language = 'python'; // {{SQL CARBON EDIT}} Open new notebooks using the default ADS notebook viewer if VSCode notebooks aren't enabled.
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, '', language); let useVSCodeNotebooks = vscode.workspace.getConfiguration('workbench')?.get<boolean>('useVSCodeNotebooks');
const data = new vscode.NotebookData([cell]); if (useVSCodeNotebooks) {
data.metadata = { const language = 'python';
custom: { const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, '', language);
cells: [], const data = new vscode.NotebookData([cell]);
metadata: { data.metadata = {
orig_nbformat: 4 custom: {
}, cells: [],
nbformat: 4, metadata: {
nbformat_minor: 2 orig_nbformat: 4
} },
}; nbformat: 4,
const doc = await vscode.workspace.openNotebookDocument('jupyter-notebook', data); nbformat_minor: 2
await vscode.window.showNotebookDocument(doc); }
};
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) => { context.subscriptions.push(vscode.commands.registerCommand('ipynb.openIpynbInNotebookEditor', async (uri: vscode.Uri) => {

10
extensions/ipynb/src/typings/refs.d.ts vendored Normal file
View File

@@ -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
/// <reference path='../../../../src/sql/azdata.d.ts'/>
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
/// <reference path='../../../../src/vscode-dts/vscode.d.ts'/>
/// <reference path='../../../resource-deployment/src/typings/resource-deployment.d.ts'/>