Improve NotebookExecutionService and cancel executions when closing the notebook, deleting cells, and changing the kernel

This commit is contained in:
Rob Lourens
2021-11-29 14:00:53 -08:00
parent f0ee64fa7f
commit 33d81fdc8c
9 changed files with 365 additions and 200 deletions

View File

@@ -922,7 +922,7 @@ export interface INotebookKernelDto2 {
export interface ICellExecuteOutputEditDto {
editType: CellExecutionUpdateType.Output;
executionHandle: number;
uri: UriComponents;
cellHandle: number;
append?: boolean;
outputs: NotebookOutputDto[]
@@ -930,21 +930,24 @@ export interface ICellExecuteOutputEditDto {
export interface ICellExecuteOutputItemEditDto {
editType: CellExecutionUpdateType.OutputItems;
executionHandle: number;
uri: UriComponents;
cellHandle: number;
append?: boolean;
outputId: string;
items: NotebookOutputItemDto[]
}
export interface ICellExecutionStateUpdateDto extends ICellExecutionStateUpdate {
executionHandle: number;
uri: UriComponents;
cellHandle: number;
}
export interface ICellExecutionCompleteDto extends ICellExecutionComplete {
executionHandle: number;
uri: UriComponents;
cellHandle: number;
}
export type ICellExecuteUpdateDto = ICellExecuteOutputEditDto | ICellExecuteOutputItemEditDto | ICellExecutionStateUpdateDto | ICellExecutionCompleteDto;
export type ICellExecuteUpdateDto = ICellExecuteOutputEditDto | ICellExecuteOutputItemEditDto | ICellExecutionStateUpdateDto;
export interface MainThreadNotebookKernelsShape extends IDisposable {
$postMessage(handle: number, editorId: string | undefined, message: any): Promise<boolean>;
@@ -953,9 +956,9 @@ export interface MainThreadNotebookKernelsShape extends IDisposable {
$removeKernel(handle: number): void;
$updateNotebookPriority(handle: number, uri: UriComponents, value: number | undefined): void;
$addExecution(handle: number, uri: UriComponents, cellHandle: number): void;
$addExecution(uri: UriComponents, cellHandle: number): void;
$updateExecutions(data: SerializableObjectWithBuffers<ICellExecuteUpdateDto[]>): void;
$removeExecution(handle: number): void;
$completeExecution(uri: UriComponents, cellHandle: number, data: SerializableObjectWithBuffers<ICellExecutionCompleteDto>): void;
}
export interface MainThreadNotebookRenderersShape extends IDisposable {

View File

@@ -366,9 +366,6 @@ enum NotebookCellExecutionTaskState {
}
class NotebookCellExecutionTask extends Disposable {
private static HANDLE = 0;
private _handle = NotebookCellExecutionTask.HANDLE++;
private _onDidChangeState = new Emitter<void>();
readonly onDidChangeState = this._onDidChangeState.event;
@@ -391,7 +388,7 @@ class NotebookCellExecutionTask extends Disposable {
this._collector = new TimeoutBasedCollector(10, updates => this.update(updates));
this._executionOrder = _cell.internalMetadata.executionOrder;
this._proxy.$addExecution(this._handle, this._cell.notebook.uri, this._cell.handle);
this._proxy.$addExecution(this._cell.notebook.uri, this._cell.handle);
}
cancel(): void {
@@ -448,7 +445,7 @@ class NotebookCellExecutionTask extends Disposable {
return this.updateSoon(
{
editType: CellExecutionUpdateType.Output,
executionHandle: this._handle,
uri: this._document.uri,
cellHandle: handle,
append,
outputs: outputDtos
@@ -459,7 +456,8 @@ class NotebookCellExecutionTask extends Disposable {
items = NotebookCellOutput.ensureUniqueMimeTypes(asArray(items), true);
return this.updateSoon({
editType: CellExecutionUpdateType.OutputItems,
executionHandle: this._handle,
uri: this._document.uri,
cellHandle: this._cell.handle,
items: items.map(extHostTypeConverters.NotebookCellOutputItem.from),
outputId: output.id,
append
@@ -476,7 +474,8 @@ class NotebookCellExecutionTask extends Disposable {
that._executionOrder = v;
that.update([{
editType: CellExecutionUpdateType.ExecutionState,
executionHandle: that._handle,
uri: that._document.uri,
cellHandle: that._cell.handle,
executionOrder: that._executionOrder
}]);
},
@@ -491,7 +490,8 @@ class NotebookCellExecutionTask extends Disposable {
that.update({
editType: CellExecutionUpdateType.ExecutionState,
executionHandle: that._handle,
uri: that._document.uri,
cellHandle: that._cell.handle,
runStartTime: startTime
});
},
@@ -504,18 +504,16 @@ class NotebookCellExecutionTask extends Disposable {
that._state = NotebookCellExecutionTaskState.Resolved;
that._onDidChangeState.fire();
that.updateSoon({
editType: CellExecutionUpdateType.Complete,
executionHandle: that._handle,
runEndTime: endTime,
lastRunSuccess: success
});
// The last update needs to be ordered correctly and applied immediately,
// so we use updateSoon and immediately flush.
that._collector.flush();
that._proxy.$removeExecution(that._handle);
that._proxy.$completeExecution(that._document.uri, that._cell.handle, new SerializableObjectWithBuffers({
uri: that._document.uri,
cellHandle: that._cell.handle,
runEndTime: endTime,
lastRunSuccess: success
}));
},
clearOutput(cell?: vscode.NotebookCell): Thenable<void> {