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', []), ]); });