Skip to content

Commit c0a8d13

Browse files
authored
Fix go to definition in Python notebooks (#16385) (#16448)
* Fix go to definition in Python notebooks (#16385) * notebook renamed to notebooks, notebooks symbols moved to workspace namespace * Drop usage of NotebookCellMetadata ctor * Update tests: `vscode.notebook.activeNotebookEditor` --> `vscode.window.activeNotebookEditor` (#16381) * vscode.window.activeNotebookEditor * window.visibleNotebookEditors * Remove deprecated `NotebookCellData` constructor parameter (#16390) * Update smoke tests and add CHANGELOG item
1 parent 43e14ea commit c0a8d13

File tree

5 files changed

+23
-34
lines changed

5 files changed

+23
-34
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 2021.5.3 (10 June 2021)
4+
5+
### Fixes
6+
7+
1. Fix go to definition in Python notebooks.
8+
([#16385](https://github.com/microsoft/vscode-python/issues/16385))
9+
310
## 2021.5.2 (14 May 2021)
411

512
### Fixes

src/client/common/application/notebook.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
// Licensed under the MIT License.
33

44
import { inject, injectable } from 'inversify';
5-
import { DocumentSelector, Event, EventEmitter } from 'vscode';
5+
import { DocumentSelector, Event, EventEmitter, workspace } from 'vscode';
66
import type { notebook, NotebookConcatTextDocument, NotebookDocument } from 'vscode-proposed';
77
import { UseProposedApi } from '../constants';
88
import { IApplicationEnvironment, IVSCodeNotebook } from './types';
99

1010
@injectable()
1111
export class VSCodeNotebook implements IVSCodeNotebook {
1212
public get onDidOpenNotebookDocument(): Event<NotebookDocument> {
13-
return this.canUseNotebookApi
14-
? this.notebook.onDidOpenNotebookDocument
15-
: new EventEmitter<NotebookDocument>().event;
13+
const onDidOpenNotebookDocument =
14+
this.notebook.onDidOpenNotebookDocument ?? (workspace as any).onDidOpenNotebookDocument;
15+
return this.canUseNotebookApi ? onDidOpenNotebookDocument : new EventEmitter<NotebookDocument>().event;
1616
}
1717
public get onDidCloseNotebookDocument(): Event<NotebookDocument> {
18-
return this.canUseNotebookApi
19-
? this.notebook.onDidCloseNotebookDocument
20-
: new EventEmitter<NotebookDocument>().event;
18+
const onDidCloseNotebookDocument =
19+
this.notebook.onDidCloseNotebookDocument ?? (workspace as any).onDidCloseNotebookDocument;
20+
return this.canUseNotebookApi ? onDidCloseNotebookDocument : new EventEmitter<NotebookDocument>().event;
2121
}
2222
public get notebookDocuments(): ReadonlyArray<NotebookDocument> {
23-
return this.canUseNotebookApi ? this.notebook.notebookDocuments : [];
23+
const notebookDocuments = this.notebook.notebookDocuments ?? (workspace as any).notebookDocuments;
24+
return this.canUseNotebookApi ? notebookDocuments : [];
2425
}
2526
private get notebook() {
2627
if (!this._notebook) {
27-
this._notebook = require('vscode').notebook;
28+
this._notebook = require('vscode').notebook ?? require('vscode').notebooks;
2829
}
2930
return this._notebook!;
3031
}

src/test/initialize.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function closeActiveNotebooks(): Promise<void> {
6969
}
7070
// We could have untitled notebooks, close them by reverting changes.
7171

72-
while ((vscode as any).notebook.activeNotebookEditor || vscode.window.activeTextEditor) {
72+
while ((vscode as any).window.activeNotebookEditor || vscode.window.activeTextEditor) {
7373
await vscode.commands.executeCommand('workbench.action.revertAndCloseActiveEditor');
7474
}
7575
// Work around VS Code issues (sometimes notebooks do not get closed).
@@ -102,10 +102,10 @@ async function closeWindowsInteral() {
102102

103103
function isANotebookOpen() {
104104
if (
105-
Array.isArray((vscode as any).notebook.visibleNotebookEditors) &&
106-
(vscode as any).notebook.visibleNotebookEditors.length
105+
Array.isArray((vscode as any).window.visibleNotebookEditors) &&
106+
(vscode as any).window.visibleNotebookEditors.length
107107
) {
108108
return true;
109109
}
110-
return !!(vscode as any).notebook.activeNotebookEditor;
110+
return !!(vscode as any).window.activeNotebookEditor;
111111
}

src/test/insiders/languageServer.insiders.test.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,7 @@ suite('Insiders Test: Language Server', () => {
101101
expect(activeEditor).not.to.be.equal(undefined, 'Active editor not found in notebook');
102102
await activeEditor!.edit((edit) => {
103103
edit.replaceCells(0, 0, [
104-
new vscode.NotebookCellData(
105-
vscode.NotebookCellKind.Code,
106-
PYTHON_LANGUAGE,
107-
'x = 4',
108-
[],
109-
new vscode.NotebookCellMetadata().with({
110-
hasExecutionOrder: false,
111-
}),
112-
),
104+
new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4'),
113105
]);
114106
});
115107

@@ -124,15 +116,7 @@ suite('Insiders Test: Language Server', () => {
124116
await activeEditor!.edit((edit) => {
125117
edit.replaceCells(0, 1, []);
126118
edit.replaceCells(1, 0, [
127-
new vscode.NotebookCellData(
128-
vscode.NotebookCellKind.Code,
129-
PYTHON_LANGUAGE,
130-
'x = 4',
131-
[],
132-
new vscode.NotebookCellMetadata().with({
133-
hasExecutionOrder: false,
134-
}),
135-
),
119+
new vscode.NotebookCellData(vscode.NotebookCellKind.Code, PYTHON_LANGUAGE, 'x = 4'),
136120
]);
137121
});
138122

src/test/smoke/datascience.smoke.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ suite('Smoke Test: Datascience', () => {
2424
await verifyExtensionIsAvailable(JUPYTER_EXTENSION_ID);
2525
await initialize();
2626
await setAutoSaveDelayInWorkspaceRoot(1);
27-
const jupyterConfig = vscode.workspace.getConfiguration('jupyter', null);
28-
await jupyterConfig.update('alwaysTrustNotebooks', true, true);
29-
3027
return undefined;
3128
});
3229
setup(initializeTest);

0 commit comments

Comments
 (0)