Move New Notebook command to core (#21247)

This commit is contained in:
Cory Rivera
2022-11-18 14:54:58 -08:00
committed by GitHub
parent 78b17bba82
commit 728a90cd53
11 changed files with 68 additions and 99 deletions

View File

@@ -98,14 +98,6 @@
"command": "notebook.command.analyzeNotebook",
"title": "%notebook.analyzeJupyterNotebook%"
},
{
"command": "_notebook.command.new",
"title": "%notebook.command.new%",
"icon": {
"dark": "resources/dark/new_notebook_inverse.svg",
"light": "resources/light/new_notebook.svg"
}
},
{
"command": "notebook.command.open",
"title": "%notebook.command.open%"
@@ -346,10 +338,6 @@
"command": "notebook.command.analyzeNotebook",
"when": "false"
},
{
"command": "_notebook.command.new",
"when": "false"
},
{
"command": "notebook.command.open"
},

View File

@@ -19,10 +19,6 @@ export class NotebookUtils {
constructor() { }
public async newNotebook(options?: azdata.nb.NotebookShowOptions): Promise<azdata.nb.NotebookEditor> {
return azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }), options);
}
public async openNotebook(): Promise<void> {
try {
let filter: { [key: string]: Array<string> } = {};

View File

@@ -85,9 +85,6 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
return dialog.createDialog();
}));
extensionContext.subscriptions.push(vscode.commands.registerCommand('_notebook.command.new', async (options?: azdata.nb.NotebookShowOptions) => {
return appContext.notebookUtils.newNotebook(options);
}));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.open', async () => {
await appContext.notebookUtils.openNotebook();
}));

View File

@@ -906,7 +906,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
nbformat_minor: constants.NBFORMAT_MINOR
};
await vscode.commands.executeCommand('_notebook.command.new', {
await vscode.commands.executeCommand('notebook.command.new', {
initialContent: JSON.stringify(initialContent),
defaultKernel: 'Python 3'
});

View File

@@ -40,7 +40,7 @@ describe('notebookUtils Tests', function (): void {
describe('newNotebook', function (): void {
it('Should open a new notebook successfully', async function (): Promise<void> {
should(azdata.nb.notebookDocuments.length).equal(0, 'There should be not any open Notebook documents');
await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
should(azdata.nb.notebookDocuments.length).equal(1, 'There should be exactly 1 open Notebook document');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
should(azdata.nb.notebookDocuments.length).equal(0, 'There should be not any open Notebook documents');
@@ -48,12 +48,12 @@ describe('notebookUtils Tests', function (): void {
it('Opening an untitled editor after closing should re-use previous untitled name', async function (): Promise<void> {
should(azdata.nb.notebookDocuments.length).equal(0, 'There should be not any open Notebook documents');
await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
should(azdata.nb.notebookDocuments.length).equal(1, 'There should be exactly 1 open Notebook document');
should(azdata.nb.notebookDocuments[0].fileName).equal('Notebook-1', 'The first Untitled Notebook should have an index of 1');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
should(azdata.nb.notebookDocuments.length).equal(0, 'There should be not any open Notebook documents');
await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
should(azdata.nb.notebookDocuments.length).equal(1, 'There should be exactly 1 open Notebook document after second opening');
should(azdata.nb.notebookDocuments[0].fileName).equal('Notebook-1', 'The first Untitled Notebook should have an index of 1 after closing first Untitled Notebook');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
@@ -61,10 +61,11 @@ describe('notebookUtils Tests', function (): void {
it('Untitled Name index should increase', async function (): Promise<void> {
should(azdata.nb.notebookDocuments.length).equal(0, 'There should be not any open Notebook documents');
await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
should(azdata.nb.notebookDocuments.length).equal(1, 'There should be exactly 1 open Notebook document');
const secondNotebook = await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
should(azdata.nb.notebookDocuments.length).equal(2, 'There should be exactly 2 open Notebook documents');
let secondNotebook = azdata.nb.activeNotebookEditor;
should(secondNotebook.document.fileName).equal('Notebook-2', 'The second Untitled Notebook should have an index of 2');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
@@ -94,9 +95,9 @@ describe('notebookUtils Tests', function (): void {
});
it('closing and opening an untitled notebook shows correct contents', async function (): Promise<void> {
await notebookUtils.newNotebook();
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await notebookUtils.newNotebook({
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }), {
initialContent: {
cells: [{
source: 'test content',
@@ -183,7 +184,8 @@ describe('notebookUtils Tests', function (): void {
});
it('does not show error when notebook visible for code cell', async function (): Promise<void> {
const notebookEditor = await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebookEditor = azdata.nb.activeNotebookEditor;
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
await notebookUtils.addCell('code');
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
@@ -192,7 +194,8 @@ describe('notebookUtils Tests', function (): void {
});
it('does not show error when notebook visible for markdown cell', async function (): Promise<void> {
const notebookEditor = await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebookEditor = azdata.nb.activeNotebookEditor;
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
await notebookUtils.addCell('markdown');
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
@@ -203,7 +206,8 @@ describe('notebookUtils Tests', function (): void {
describe('analyzeNotebook', function () {
it('creates cell when oeContext exists', async function (): Promise<void> {
const notebookEditor = await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebookEditor = azdata.nb.activeNotebookEditor;
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
sinon.stub(azdata.nb, 'showNotebookDocument').returns(Promise.resolve(notebookEditor));
const oeContext: azdata.ObjectExplorerContext = {
@@ -226,7 +230,8 @@ describe('notebookUtils Tests', function (): void {
});
it('does not create new cell when oeContext does not exist', async function (): Promise<void> {
const notebookEditor = await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebookEditor = azdata.nb.activeNotebookEditor;
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
sinon.stub(azdata.nb, 'showNotebookDocument').returns(Promise.resolve(notebookEditor));
await notebookUtils.analyzeNotebook();

View File

@@ -63,7 +63,8 @@ describe('Completion Item Provider', function () {
});
it('should not provide items when session does not exist in notebook provider', async () => {
let notebook = await notebookUtils.newNotebook();
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebook = azdata.nb.activeNotebookEditor;
await notebookUtils.addCell('code');
let document = await tryFindTextDocument(notebook);
should(document).not.equal(undefined, 'Could not find text document that matched cell uri path');
@@ -75,7 +76,8 @@ describe('Completion Item Provider', function () {
it('should not provide items when session list throws exception', async () => {
mockSessionManager.setup(m => m.listRunning()).throws(new Error('Test Error'));
let notebook = await notebookUtils.newNotebook();
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebook = azdata.nb.activeNotebookEditor;
await notebookUtils.addCell('code');
let document = await tryFindTextDocument(notebook);
@@ -86,7 +88,8 @@ describe('Completion Item Provider', function () {
it('should not provide items when kernel does not exist in notebook provider', async () => {
mockSessionManager.setup(m => m.listRunning()).returns(() => [mockJupyterSession.object]);
let notebook = await notebookUtils.newNotebook();
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebook = azdata.nb.activeNotebookEditor;
await notebookUtils.addCell('code');
let document = await tryFindTextDocument(notebook);
@@ -102,7 +105,8 @@ describe('Completion Item Provider', function () {
mockSessionManager.setup(m => m.listRunning()).returns(() => [mockJupyterSession.object]);
mockJupyterSession.setup(s => s.path).returns(() => notebook.document.uri.path);
let notebook = await notebookUtils.newNotebook();
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebook = azdata.nb.activeNotebookEditor;
await notebookUtils.addCell('code');
let document = await tryFindTextDocument(notebook);
@@ -145,7 +149,8 @@ describe('Completion Item Provider', function () {
mockJupyterSession.setup(s => s.kernel).returns(() => kernel);
mockSessionManager.setup(m => m.listRunning()).returns(() => [mockJupyterSession.object]);
let notebook = await notebookUtils.newNotebook();
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebook = azdata.nb.activeNotebookEditor;
await notebook.edit((editBuilder: azdata.nb.NotebookEditorEdit) => {
editBuilder.insertCell({
cell_type: 'code',
@@ -182,7 +187,8 @@ describe('Completion Item Provider', function () {
mockJupyterSession.setup(s => s.kernel).returns(() => kernel);
mockSessionManager.setup(m => m.listRunning()).returns(() => [mockJupyterSession.object]);
let notebook = await notebookUtils.newNotebook();
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebook = azdata.nb.activeNotebookEditor;
if (source) {
await notebook.edit((editBuilder: azdata.nb.NotebookEditorEdit) => {
editBuilder.insertCell({

View File

@@ -13,7 +13,6 @@ import { AppContext } from '../../common/appContext';
import { JupyterController } from '../../jupyter/jupyterController';
import { LocalPipPackageManageProvider } from '../../jupyter/localPipPackageManageProvider';
import { MockExtensionContext } from '../common/stubs';
import { NotebookUtils } from '../../common/notebookUtils';
describe('Jupyter Controller', function () {
let mockExtensionContext: vscode.ExtensionContext = new MockExtensionContext();
@@ -74,7 +73,7 @@ describe('Jupyter Controller', function () {
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not be called');
});
it('Returns expected values from notebook provider', async () => {
it('Returns expected values from notebook provider', async () => {
await controller.activate();
should(controller.executeProvider.providerId).equal('jupyter', 'Notebook provider should be jupyter');
await should(controller.executeProvider.getExecuteManager(undefined)).be.rejected();
@@ -82,10 +81,10 @@ describe('Jupyter Controller', function () {
controller.executeProvider.handleNotebookClosed(undefined);
});
it('Returns execute manager for real notebook editor', async () => {
it('Returns execute manager for real notebook editor', async () => {
await controller.activate();
let notebookUtils = new NotebookUtils();
const notebookEditor = await notebookUtils.newNotebook(undefined);
await azdata.nb.showNotebookDocument(vscode.Uri.from({ scheme: 'untitled' }));
const notebookEditor = azdata.nb.activeNotebookEditor;
let notebookManager = await controller.executeProvider.getExecuteManager(notebookEditor.document.uri);
should(controller.executeProvider.executeManagerCount).equal(1);