|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | import { inject, injectable } from 'inversify'; |
5 | | -import { DocumentSelector, Event, EventEmitter } from 'vscode'; |
| 5 | +import { DocumentSelector, Event, EventEmitter, workspace } from 'vscode'; |
6 | 6 | import type { notebook, NotebookConcatTextDocument, NotebookDocument } from 'vscode-proposed'; |
7 | 7 | import { UseProposedApi } from '../constants'; |
8 | 8 | import { IApplicationEnvironment, IVSCodeNotebook } from './types'; |
9 | 9 |
|
10 | 10 | @injectable() |
11 | 11 | export class VSCodeNotebook implements IVSCodeNotebook { |
12 | 12 | 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; |
16 | 16 | } |
17 | 17 | 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; |
21 | 21 | } |
22 | 22 | 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 : []; |
24 | 25 | } |
25 | 26 | private get notebook() { |
26 | 27 | if (!this._notebook) { |
27 | | - this._notebook = require('vscode').notebook; |
| 28 | + this._notebook = require('vscode').notebook ?? require('vscode').notebooks; |
28 | 29 | } |
29 | 30 | return this._notebook!; |
30 | 31 | } |
|
0 commit comments