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",
"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",

View File

@@ -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<boolean>('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) => {

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'/>