Skip to content

Commit

Permalink
Fix go to definition in Python notebooks (#16385) (#16448)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
joyceerhl authored Jun 10, 2021
1 parent 43e14ea commit c0a8d13
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 10 additions & 9 deletions src/client/common/application/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
// 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';

@injectable()
export class VSCodeNotebook implements IVSCodeNotebook {
public get onDidOpenNotebookDocument(): Event<NotebookDocument> {
return this.canUseNotebookApi
? this.notebook.onDidOpenNotebookDocument
: new EventEmitter<NotebookDocument>().event;
const onDidOpenNotebookDocument =
this.notebook.onDidOpenNotebookDocument ?? (workspace as any).onDidOpenNotebookDocument;
return this.canUseNotebookApi ? onDidOpenNotebookDocument : new EventEmitter<NotebookDocument>().event;
}
public get onDidCloseNotebookDocument(): Event<NotebookDocument> {
return this.canUseNotebookApi
? this.notebook.onDidCloseNotebookDocument
: new EventEmitter<NotebookDocument>().event;
const onDidCloseNotebookDocument =
this.notebook.onDidCloseNotebookDocument ?? (workspace as any).onDidCloseNotebookDocument;
return this.canUseNotebookApi ? onDidCloseNotebookDocument : new EventEmitter<NotebookDocument>().event;
}
public get notebookDocuments(): ReadonlyArray<NotebookDocument> {
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!;
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function closeActiveNotebooks(): Promise<void> {
}
// 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).
Expand Down Expand Up @@ -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;
}
20 changes: 2 additions & 18 deletions src/test/insiders/languageServer.insiders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]);
});

Expand All @@ -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'),
]);
});

Expand Down
3 changes: 0 additions & 3 deletions src/test/smoke/datascience.smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c0a8d13

Please sign in to comment.