@@ -5,23 +5,39 @@ import { inject, injectable } from 'inversify';
55import { DocumentSelector , Event , EventEmitter , workspace } from 'vscode' ;
66import type { notebook , NotebookConcatTextDocument , NotebookDocument } from 'vscode-proposed' ;
77import { UseProposedApi } from '../constants' ;
8+ import { traceError } from '../logger' ;
89import { IApplicationEnvironment , IVSCodeNotebook } from './types' ;
910
1011@injectable ( )
1112export class VSCodeNotebook implements IVSCodeNotebook {
1213 public get onDidOpenNotebookDocument ( ) : Event < NotebookDocument > {
13- const onDidOpenNotebookDocument =
14- this . notebook . onDidOpenNotebookDocument ?? ( workspace as any ) . onDidOpenNotebookDocument ;
15- return this . canUseNotebookApi ? onDidOpenNotebookDocument : new EventEmitter < NotebookDocument > ( ) . event ;
14+ try {
15+ const onDidOpenNotebookDocument =
16+ this . notebook . onDidOpenNotebookDocument ?? ( workspace as any ) . onDidOpenNotebookDocument ;
17+ return this . canUseNotebookApi ? onDidOpenNotebookDocument : new EventEmitter < NotebookDocument > ( ) . event ;
18+ } catch ( ex ) {
19+ traceError ( `Failed to get event handler onDidOpenNotebookDocument` , ex ) ;
20+ return new EventEmitter < NotebookDocument > ( ) . event ;
21+ }
1622 }
1723 public get onDidCloseNotebookDocument ( ) : Event < NotebookDocument > {
18- const onDidCloseNotebookDocument =
19- this . notebook . onDidCloseNotebookDocument ?? ( workspace as any ) . onDidCloseNotebookDocument ;
20- return this . canUseNotebookApi ? onDidCloseNotebookDocument : new EventEmitter < NotebookDocument > ( ) . event ;
24+ try {
25+ const onDidCloseNotebookDocument =
26+ this . notebook . onDidCloseNotebookDocument ?? ( workspace as any ) . onDidCloseNotebookDocument ;
27+ return this . canUseNotebookApi ? onDidCloseNotebookDocument : new EventEmitter < NotebookDocument > ( ) . event ;
28+ } catch ( ex ) {
29+ traceError ( `Failed to get event handler onDidOpenNotebookDocument` , ex ) ;
30+ return new EventEmitter < NotebookDocument > ( ) . event ;
31+ }
2132 }
2233 public get notebookDocuments ( ) : ReadonlyArray < NotebookDocument > {
23- const notebookDocuments = this . notebook . notebookDocuments ?? ( workspace as any ) . notebookDocuments ;
24- return this . canUseNotebookApi ? notebookDocuments : [ ] ;
34+ try {
35+ const notebookDocuments = this . notebook . notebookDocuments ?? ( workspace as any ) . notebookDocuments ;
36+ return this . canUseNotebookApi ? notebookDocuments : [ ] ;
37+ } catch ( ex ) {
38+ traceError ( `Failed to get event handler onDidOpenNotebookDocument` , ex ) ;
39+ return [ ] ;
40+ }
2541 }
2642 private get notebook ( ) {
2743 if ( ! this . _notebook ) {
0 commit comments