From 2905395d662bb3e2fed80e9555e71a984cce33cb Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 3 Jun 2021 12:46:43 -0700 Subject: [PATCH 1/4] Fix go to definition in Python notebooks (#16385) * notebook renamed to notebooks, notebooks symbols moved to workspace namespace * Drop usage of NotebookCellMetadata ctor --- src/client/common/application/notebook.ts | 19 +++++++++--------- .../insiders/languageServer.insiders.test.ts | 20 ++----------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/client/common/application/notebook.ts b/src/client/common/application/notebook.ts index b84544a31642..ccc20659c7fb 100644 --- a/src/client/common/application/notebook.ts +++ b/src/client/common/application/notebook.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import { DocumentSelector, Event, EventEmitter } from 'vscode'; +import { DocumentSelector, Event, EventEmitter, workspace } from 'vscode'; import type { notebook, NotebookConcatTextDocument, NotebookDocument } from 'vscode-proposed'; import { UseProposedApi } from '../constants'; import { IApplicationEnvironment, IVSCodeNotebook } from './types'; @@ -10,21 +10,22 @@ import { IApplicationEnvironment, IVSCodeNotebook } from './types'; @injectable() export class VSCodeNotebook implements IVSCodeNotebook { public get onDidOpenNotebookDocument(): Event { - return this.canUseNotebookApi - ? this.notebook.onDidOpenNotebookDocument - : new EventEmitter().event; + const onDidOpenNotebookDocument = + this.notebook.onDidOpenNotebookDocument ?? (workspace as any).onDidOpenNotebookDocument; + return this.canUseNotebookApi ? onDidOpenNotebookDocument : new EventEmitter().event; } public get onDidCloseNotebookDocument(): Event { - return this.canUseNotebookApi - ? this.notebook.onDidCloseNotebookDocument - : new EventEmitter().event; + const onDidCloseNotebookDocument = + this.notebook.onDidCloseNotebookDocument ?? (workspace as any).onDidCloseNotebookDocument; + return this.canUseNotebookApi ? onDidCloseNotebookDocument : new EventEmitter().event; } public get notebookDocuments(): ReadonlyArray { - return this.canUseNotebookApi ? this.notebook.notebookDocuments : []; + const notebookDocuments = this.notebook.notebookDocuments ?? (workspace as any).notebookDocuments; + return this.canUseNotebookApi ? notebookDocuments : []; } private get notebook() { if (!this._notebook) { - this._notebook = require('vscode').notebook; + this._notebook = require('vscode').notebook ?? require('vscode').notebooks; } return this._notebook!; } diff --git a/src/test/insiders/languageServer.insiders.test.ts b/src/test/insiders/languageServer.insiders.test.ts index 54a095adbe24..be504fe82f1f 100644 --- a/src/test/insiders/languageServer.insiders.test.ts +++ b/src/test/insiders/languageServer.insiders.test.ts @@ -101,15 +101,7 @@ suite('Insiders Test: Language Server', () => { expect(activeEditor).not.to.be.equal(undefined, 'Active editor not found in notebook'); await activeEditor!.edit((edit) => { edit.replaceCells(0, 0, [ - new vscode.NotebookCellData( - vscode.NotebookCellKind.Code, - PYTHON_LANGUAGE, - 'x = 4', - [], - new vscode.NotebookCellMetadata().with({ - hasExecutionOrder: false, - }), - ), + new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4', []), ]); }); @@ -124,15 +116,7 @@ suite('Insiders Test: Language Server', () => { await activeEditor!.edit((edit) => { edit.replaceCells(0, 1, []); edit.replaceCells(1, 0, [ - new vscode.NotebookCellData( - vscode.NotebookCellKind.Code, - PYTHON_LANGUAGE, - 'x = 4', - [], - new vscode.NotebookCellMetadata().with({ - hasExecutionOrder: false, - }), - ), + new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4', []), ]); }); From 5b841e703ff41c40dc1f5a4e1a170cf5fb5719ea Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 3 Jun 2021 10:33:49 -0700 Subject: [PATCH 2/4] Update tests: `vscode.notebook.activeNotebookEditor` --> `vscode.window.activeNotebookEditor` (#16381) * vscode.window.activeNotebookEditor * window.visibleNotebookEditors --- src/test/initialize.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/initialize.ts b/src/test/initialize.ts index cba7529693f8..559a033e1a3b 100644 --- a/src/test/initialize.ts +++ b/src/test/initialize.ts @@ -69,7 +69,7 @@ export async function closeActiveNotebooks(): Promise { } // We could have untitled notebooks, close them by reverting changes. - while ((vscode as any).notebook.activeNotebookEditor || vscode.window.activeTextEditor) { + while ((vscode as any).window.activeNotebookEditor || vscode.window.activeTextEditor) { await vscode.commands.executeCommand('workbench.action.revertAndCloseActiveEditor'); } // Work around VS Code issues (sometimes notebooks do not get closed). @@ -102,10 +102,10 @@ async function closeWindowsInteral() { function isANotebookOpen() { if ( - Array.isArray((vscode as any).notebook.visibleNotebookEditors) && - (vscode as any).notebook.visibleNotebookEditors.length + Array.isArray((vscode as any).window.visibleNotebookEditors) && + (vscode as any).window.visibleNotebookEditors.length ) { return true; } - return !!(vscode as any).notebook.activeNotebookEditor; + return !!(vscode as any).window.activeNotebookEditor; } From 3b175c570f3cd6a58ca6300c44551d53e4750817 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 3 Jun 2021 18:43:31 -0700 Subject: [PATCH 3/4] Remove deprecated `NotebookCellData` constructor parameter (#16390) --- src/test/insiders/languageServer.insiders.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/insiders/languageServer.insiders.test.ts b/src/test/insiders/languageServer.insiders.test.ts index be504fe82f1f..10b87ae7cfd2 100644 --- a/src/test/insiders/languageServer.insiders.test.ts +++ b/src/test/insiders/languageServer.insiders.test.ts @@ -101,7 +101,7 @@ suite('Insiders Test: Language Server', () => { expect(activeEditor).not.to.be.equal(undefined, 'Active editor not found in notebook'); await activeEditor!.edit((edit) => { edit.replaceCells(0, 0, [ - new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4', []), + new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4'), ]); }); @@ -116,7 +116,7 @@ suite('Insiders Test: Language Server', () => { await activeEditor!.edit((edit) => { edit.replaceCells(0, 1, []); edit.replaceCells(1, 0, [ - new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4', []), + new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4'), ]); }); From da5a2394da5dd87558ce1d1da37fb60c7dfa4adb Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 10 Jun 2021 12:52:44 -0700 Subject: [PATCH 4/4] Update smoke tests and add CHANGELOG item --- CHANGELOG.md | 7 +++++++ src/test/smoke/datascience.smoke.test.ts | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2be3d4bc127..b65e6a646308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2021.5.3 (10 June 2021) + +### Fixes + +1. Fix go to definition in Python notebooks. + ([#16385](https://github.com/microsoft/vscode-python/issues/16385)) + ## 2021.5.2 (14 May 2021) ### Fixes diff --git a/src/test/smoke/datascience.smoke.test.ts b/src/test/smoke/datascience.smoke.test.ts index e2a034694a5b..70106fa254d1 100644 --- a/src/test/smoke/datascience.smoke.test.ts +++ b/src/test/smoke/datascience.smoke.test.ts @@ -24,9 +24,6 @@ suite('Smoke Test: Datascience', () => { await verifyExtensionIsAvailable(JUPYTER_EXTENSION_ID); await initialize(); await setAutoSaveDelayInWorkspaceRoot(1); - const jupyterConfig = vscode.workspace.getConfiguration('jupyter', null); - await jupyterConfig.update('alwaysTrustNotebooks', true, true); - return undefined; }); setup(initializeTest);