Skip to content

Commit cd8f4d3

Browse files
authored
Fix go to definition in Python notebooks (microsoft#16385)
* notebook renamed to notebooks, notebooks symbols moved to workspace namespace * Drop usage of NotebookCellMetadata ctor
1 parent 4936a76 commit cd8f4d3

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

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

0 commit comments

Comments
 (0)