6
6
import { nbformat } from '@jupyterlab/coreutils' ;
7
7
import type { KernelMessage } from '@jupyterlab/services/lib/kernel/messages' ;
8
8
import { CancellationToken , CellOutputKind , CellStreamOutput , NotebookCell , NotebookCellRunState } from 'vscode' ;
9
+ import type { NotebookEditor as VSCNotebookEditor } from '../../../../../types/vscode-proposed' ;
9
10
import { concatMultilineString , formatStreamText } from '../../../../datascience-ui/common' ;
10
- import { IApplicationShell } from '../../../common/application/types' ;
11
+ import { IApplicationShell , IVSCodeNotebook } from '../../../common/application/types' ;
11
12
import { traceInfo , traceWarning } from '../../../common/logger' ;
12
13
import { RefBool } from '../../../common/refBool' ;
13
14
import { createDeferred } from '../../../common/utils/async' ;
@@ -43,12 +44,14 @@ export class CellExecutionFactory {
43
44
private readonly contentProvider : INotebookContentProvider ,
44
45
private readonly errorHandler : IDataScienceErrorHandler ,
45
46
private readonly editorProvider : INotebookEditorProvider ,
46
- private readonly appShell : IApplicationShell
47
+ private readonly appShell : IApplicationShell ,
48
+ private readonly vscNotebook : IVSCodeNotebook
47
49
) { }
48
50
49
51
public create ( cell : NotebookCell ) {
50
52
// tslint:disable-next-line: no-use-before-declare
51
53
return CellExecution . fromCell (
54
+ this . vscNotebook . notebookEditors . find ( ( e ) => e . document === cell . notebook ) ! ,
52
55
cell ,
53
56
this . contentProvider ,
54
57
this . errorHandler ,
@@ -89,6 +92,7 @@ export class CellExecution {
89
92
private _completed ?: boolean ;
90
93
91
94
private constructor (
95
+ public readonly editor : VSCNotebookEditor ,
92
96
public readonly cell : NotebookCell ,
93
97
private readonly contentProvider : INotebookContentProvider ,
94
98
private readonly errorHandler : IDataScienceErrorHandler ,
@@ -100,19 +104,20 @@ export class CellExecution {
100
104
}
101
105
102
106
public static fromCell (
107
+ editor : VSCNotebookEditor ,
103
108
cell : NotebookCell ,
104
109
contentProvider : INotebookContentProvider ,
105
110
errorHandler : IDataScienceErrorHandler ,
106
111
editorProvider : INotebookEditorProvider ,
107
112
appService : IApplicationShell
108
113
) {
109
- return new CellExecution ( cell , contentProvider , errorHandler , editorProvider , appService ) ;
114
+ return new CellExecution ( editor , cell , contentProvider , errorHandler , editorProvider , appService ) ;
110
115
}
111
116
112
117
public start ( kernelPromise : Promise < IKernel > , notebook : INotebook ) {
113
118
this . started = true ;
114
119
// Ensure we clear the cell state and trigger a change.
115
- clearCellForExecution ( this . cell ) ;
120
+ clearCellForExecution ( this . editor , this . cell ) ;
116
121
this . cell . metadata . runStartTime = new Date ( ) . getTime ( ) ;
117
122
this . stopWatch . reset ( ) ;
118
123
// Changes to metadata must be saved in ipynb, hence mark doc has dirty.
@@ -149,7 +154,7 @@ export class CellExecution {
149
154
private completedWithErrors ( error : Partial < Error > ) {
150
155
this . sendPerceivedCellExecute ( ) ;
151
156
this . cell . metadata . lastRunDuration = this . stopWatch . elapsedTime ;
152
- updateCellWithErrorStatus ( this . cell , error ) ;
157
+ updateCellWithErrorStatus ( this . editor , this . cell , error ) ;
153
158
this . contentProvider . notifyChangesToDocument ( this . cell . notebook ) ;
154
159
this . errorHandler . handleError ( ( error as unknown ) as Error ) . ignoreErrors ( ) ;
155
160
@@ -169,7 +174,7 @@ export class CellExecution {
169
174
170
175
this . cell . metadata . statusMessage = '' ;
171
176
this . cell . metadata . lastRunDuration = this . stopWatch . elapsedTime ;
172
- updateCellExecutionTimes ( this . cell , {
177
+ updateCellExecutionTimes ( this . editor , this . cell , {
173
178
startTime : this . cell . metadata . runStartTime ,
174
179
duration : this . cell . metadata . lastRunDuration
175
180
} ) ;
@@ -353,7 +358,7 @@ export class CellExecution {
353
358
354
359
// Set execution count, all messages should have it
355
360
if ( 'execution_count' in msg . content && typeof msg . content . execution_count === 'number' ) {
356
- if ( updateCellExecutionCount ( this . cell , msg . content . execution_count ) ) {
361
+ if ( updateCellExecutionCount ( this . editor , this . cell , msg . content . execution_count ) ) {
357
362
shouldUpdate = true ;
358
363
}
359
364
}
@@ -449,7 +454,7 @@ export class CellExecution {
449
454
450
455
private handleExecuteInput ( msg : KernelMessage . IExecuteInputMsg , _clearState : RefBool ) {
451
456
if ( msg . content . execution_count ) {
452
- updateCellExecutionCount ( this . cell , msg . content . execution_count ) ;
457
+ updateCellExecutionCount ( this . editor , this . cell , msg . content . execution_count ) ;
453
458
}
454
459
}
455
460
@@ -530,7 +535,7 @@ export class CellExecution {
530
535
531
536
// Set execution count, all messages should have it
532
537
if ( 'execution_count' in msg . content && typeof msg . content . execution_count === 'number' ) {
533
- updateCellExecutionCount ( this . cell , msg . content . execution_count ) ;
538
+ updateCellExecutionCount ( this . editor , this . cell , msg . content . execution_count ) ;
534
539
}
535
540
536
541
// Send this event.
0 commit comments