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' ;
@@ -41,12 +42,14 @@ export class CellExecutionFactory {
41
42
private readonly contentProvider : INotebookContentProvider ,
42
43
private readonly errorHandler : IDataScienceErrorHandler ,
43
44
private readonly editorProvider : INotebookEditorProvider ,
44
- private readonly appShell : IApplicationShell
45
+ private readonly appShell : IApplicationShell ,
46
+ private readonly vscNotebook : IVSCodeNotebook
45
47
) { }
46
48
47
49
public create ( cell : NotebookCell ) {
48
50
// tslint:disable-next-line: no-use-before-declare
49
51
return CellExecution . fromCell (
52
+ this . vscNotebook . notebookEditors . find ( ( e ) => e . document === cell . notebook ) ! ,
50
53
cell ,
51
54
this . contentProvider ,
52
55
this . errorHandler ,
@@ -87,6 +90,7 @@ export class CellExecution {
87
90
private _completed ?: boolean ;
88
91
89
92
private constructor (
93
+ public readonly editor : VSCNotebookEditor ,
90
94
public readonly cell : NotebookCell ,
91
95
private readonly contentProvider : INotebookContentProvider ,
92
96
private readonly errorHandler : IDataScienceErrorHandler ,
@@ -98,19 +102,20 @@ export class CellExecution {
98
102
}
99
103
100
104
public static fromCell (
105
+ editor : VSCNotebookEditor ,
101
106
cell : NotebookCell ,
102
107
contentProvider : INotebookContentProvider ,
103
108
errorHandler : IDataScienceErrorHandler ,
104
109
editorProvider : INotebookEditorProvider ,
105
110
appService : IApplicationShell
106
111
) {
107
- return new CellExecution ( cell , contentProvider , errorHandler , editorProvider , appService ) ;
112
+ return new CellExecution ( editor , cell , contentProvider , errorHandler , editorProvider , appService ) ;
108
113
}
109
114
110
115
public start ( kernelPromise : Promise < IKernel > , notebook : INotebook ) {
111
116
this . started = true ;
112
117
// Ensure we clear the cell state and trigger a change.
113
- clearCellForExecution ( this . cell ) ;
118
+ clearCellForExecution ( this . editor , this . cell ) ;
114
119
this . cell . metadata . runStartTime = new Date ( ) . getTime ( ) ;
115
120
this . stopWatch . reset ( ) ;
116
121
// Changes to metadata must be saved in ipynb, hence mark doc has dirty.
@@ -147,7 +152,7 @@ export class CellExecution {
147
152
private completedWithErrors ( error : Partial < Error > ) {
148
153
this . sendPerceivedCellExecute ( ) ;
149
154
this . cell . metadata . lastRunDuration = this . stopWatch . elapsedTime ;
150
- updateCellWithErrorStatus ( this . cell , error ) ;
155
+ updateCellWithErrorStatus ( this . editor , this . cell , error ) ;
151
156
this . contentProvider . notifyChangesToDocument ( this . cell . notebook ) ;
152
157
this . errorHandler . handleError ( ( error as unknown ) as Error ) . ignoreErrors ( ) ;
153
158
@@ -167,7 +172,7 @@ export class CellExecution {
167
172
168
173
this . cell . metadata . statusMessage = '' ;
169
174
this . cell . metadata . lastRunDuration = this . stopWatch . elapsedTime ;
170
- updateCellExecutionTimes ( this . cell , {
175
+ updateCellExecutionTimes ( this . editor , this . cell , {
171
176
startTime : this . cell . metadata . runStartTime ,
172
177
duration : this . cell . metadata . lastRunDuration
173
178
} ) ;
@@ -351,7 +356,7 @@ export class CellExecution {
351
356
352
357
// Set execution count, all messages should have it
353
358
if ( 'execution_count' in msg . content && typeof msg . content . execution_count === 'number' ) {
354
- if ( updateCellExecutionCount ( this . cell , msg . content . execution_count ) ) {
359
+ if ( updateCellExecutionCount ( this . editor , this . cell , msg . content . execution_count ) ) {
355
360
shouldUpdate = true ;
356
361
}
357
362
}
@@ -442,7 +447,7 @@ export class CellExecution {
442
447
443
448
private handleExecuteInput ( msg : KernelMessage . IExecuteInputMsg , _clearState : RefBool ) {
444
449
if ( msg . content . execution_count ) {
445
- updateCellExecutionCount ( this . cell , msg . content . execution_count ) ;
450
+ updateCellExecutionCount ( this . editor , this . cell , msg . content . execution_count ) ;
446
451
}
447
452
}
448
453
@@ -518,7 +523,7 @@ export class CellExecution {
518
523
519
524
// Set execution count, all messages should have it
520
525
if ( 'execution_count' in msg . content && typeof msg . content . execution_count === 'number' ) {
521
- updateCellExecutionCount ( this . cell , msg . content . execution_count ) ;
526
+ updateCellExecutionCount ( this . editor , this . cell , msg . content . execution_count ) ;
522
527
}
523
528
524
529
// Send this event.
0 commit comments