@@ -13,7 +13,7 @@ import { ILogService } from 'vs/platform/log/common/log';
13
13
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel' ;
14
14
import { CellEditType , CellUri , ICellEditOperation , NotebookCellExecutionState , NotebookCellInternalMetadata , NotebookTextModelWillAddRemoveEvent } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
15
15
import { CellExecutionUpdateType , INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService' ;
16
- import { ICellExecuteUpdate , ICellExecutionComplete , ICellExecutionStateChangedEvent , ICellExecutionStateUpdate , INotebookCellExecution , INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService' ;
16
+ import { ICellExecuteUpdate , ICellExecutionComplete , ICellExecutionStateChangedEvent , ICellExecutionStateUpdate , INotebookCellExecution , INotebookExecutionStateService , INotebookFailStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService' ;
17
17
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService' ;
18
18
19
19
export class NotebookExecutionStateService extends Disposable implements INotebookExecutionStateService {
@@ -22,10 +22,14 @@ export class NotebookExecutionStateService extends Disposable implements INotebo
22
22
private readonly _executions = new ResourceMap < Map < number , CellExecution > > ( ) ;
23
23
private readonly _notebookListeners = new ResourceMap < NotebookExecutionListeners > ( ) ;
24
24
private readonly _cellListeners = new ResourceMap < IDisposable > ( ) ;
25
+ private readonly _lastFailedCells = new ResourceMap < number > ( ) ;
25
26
26
27
private readonly _onDidChangeCellExecution = this . _register ( new Emitter < ICellExecutionStateChangedEvent > ( ) ) ;
27
28
onDidChangeCellExecution = this . _onDidChangeCellExecution . event ;
28
29
30
+ private readonly _onDidChangeLastRunFailState = this . _register ( new Emitter < INotebookFailStateChangedEvent > ( ) ) ;
31
+ onDidChangeLastRunFailState = this . _onDidChangeLastRunFailState . event ;
32
+
29
33
constructor (
30
34
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
31
35
@ILogService private readonly _logService : ILogService ,
@@ -34,6 +38,10 @@ export class NotebookExecutionStateService extends Disposable implements INotebo
34
38
super ( ) ;
35
39
}
36
40
41
+ getLastFailedCellForNotebook ( notebook : URI ) : number | undefined {
42
+ return this . _lastFailedCells . get ( notebook ) ;
43
+ }
44
+
37
45
forceCancelNotebookExecutions ( notebookUri : URI ) : void {
38
46
const notebookExecutions = this . _executions . get ( notebookUri ) ;
39
47
if ( ! notebookExecutions ) {
@@ -68,7 +76,7 @@ export class NotebookExecutionStateService extends Disposable implements INotebo
68
76
this . _onDidChangeCellExecution . fire ( new NotebookExecutionEvent ( notebookUri , cellHandle , exe ) ) ;
69
77
}
70
78
71
- private _onCellExecutionDidComplete ( notebookUri : URI , cellHandle : number , exe : CellExecution ) : void {
79
+ private _onCellExecutionDidComplete ( notebookUri : URI , cellHandle : number , exe : CellExecution , lastRunSuccess ?: boolean ) : void {
72
80
const notebookExecutions = this . _executions . get ( notebookUri ) ;
73
81
if ( ! notebookExecutions ) {
74
82
this . _logService . debug ( `NotebookExecutionStateService#_onCellExecutionDidComplete - unknown notebook ${ notebookUri . toString ( ) } ` ) ;
@@ -86,6 +94,14 @@ export class NotebookExecutionStateService extends Disposable implements INotebo
86
94
this . _notebookListeners . delete ( notebookUri ) ;
87
95
}
88
96
97
+ if ( lastRunSuccess !== undefined ) {
98
+ if ( lastRunSuccess ) {
99
+ this . _clearLastFailedCell ( notebookUri ) ;
100
+ } else {
101
+ this . _setLastFailedCell ( notebookUri , cellHandle ) ;
102
+ }
103
+ }
104
+
89
105
this . _onDidChangeCellExecution . fire ( new NotebookExecutionEvent ( notebookUri , cellHandle ) ) ;
90
106
}
91
107
@@ -119,12 +135,22 @@ export class NotebookExecutionStateService extends Disposable implements INotebo
119
135
const exe : CellExecution = this . _instantiationService . createInstance ( CellExecution , cellHandle , notebook ) ;
120
136
const disposable = combinedDisposable (
121
137
exe . onDidUpdate ( ( ) => this . _onCellExecutionDidChange ( notebookUri , cellHandle , exe ) ) ,
122
- exe . onDidComplete ( ( ) => this . _onCellExecutionDidComplete ( notebookUri , cellHandle , exe ) ) ) ;
138
+ exe . onDidComplete ( lastRunSuccess => this . _onCellExecutionDidComplete ( notebookUri , cellHandle , exe , lastRunSuccess ) ) ) ;
123
139
this . _cellListeners . set ( CellUri . generate ( notebookUri , cellHandle ) , disposable ) ;
124
140
125
141
return exe ;
126
142
}
127
143
144
+ private _setLastFailedCell ( notebook : URI , cellHandle : number ) {
145
+ this . _lastFailedCells . set ( notebook , cellHandle ) ;
146
+ this . _onDidChangeLastRunFailState . fire ( { failed : true , notebook } ) ;
147
+ }
148
+
149
+ private _clearLastFailedCell ( notebook : URI ) {
150
+ this . _lastFailedCells . delete ( notebook ) ;
151
+ this . _onDidChangeLastRunFailState . fire ( { failed : false , notebook : notebook } ) ;
152
+ }
153
+
128
154
override dispose ( ) : void {
129
155
super . dispose ( ) ;
130
156
this . _executions . forEach ( executionMap => {
@@ -250,7 +276,7 @@ class CellExecution extends Disposable implements INotebookCellExecution {
250
276
private readonly _onDidUpdate = this . _register ( new Emitter < void > ( ) ) ;
251
277
readonly onDidUpdate = this . _onDidUpdate . event ;
252
278
253
- private readonly _onDidComplete = this . _register ( new Emitter < void > ( ) ) ;
279
+ private readonly _onDidComplete = this . _register ( new Emitter < boolean | undefined > ( ) ) ;
254
280
readonly onDidComplete = this . _onDidComplete . event ;
255
281
256
282
private _state : NotebookCellExecutionState = NotebookCellExecutionState . Unconfirmed ;
@@ -350,7 +376,7 @@ class CellExecution extends Disposable implements INotebookCellExecution {
350
376
this . _applyExecutionEdits ( [ edit ] ) ;
351
377
}
352
378
353
- this . _onDidComplete . fire ( ) ;
379
+ this . _onDidComplete . fire ( completionData . lastRunSuccess ) ;
354
380
}
355
381
356
382
private _applyExecutionEdits ( edits : ICellEditOperation [ ] ) : void {
0 commit comments