Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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