Merge branch 'roblou/executionService'

This commit is contained in:
Rob Lourens
2021-12-29 17:11:42 -08:00
41 changed files with 1004 additions and 441 deletions

View File

@@ -1124,7 +1124,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
},
onDidChangeNotebookCellExecutionState(listener, thisArgs?, disposables?) {
checkProposedApiEnabled(extension, 'notebookCellExecutionState');
return extHostNotebook.onDidChangeNotebookCellExecutionState(listener, thisArgs, disposables);
return extHostNotebookKernels.onDidChangeNotebookCellExecutionState(listener, thisArgs, disposables);
},
onDidChangeCellOutputs(listener, thisArgs?, disposables?) {
checkProposedApiEnabled(extension, 'notebookEditor');

View File

@@ -54,7 +54,8 @@ import { IRevealOptions, ITreeItem } from 'vs/workbench/common/views';
import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { IAdapterDescriptor, IConfig, IDebugSessionReplMode } from 'vs/workbench/contrib/debug/common/debug';
import * as notebookCommon from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellExecutionUpdateType, ICellExecutionComplete, ICellExecutionStateUpdate } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
import { CellExecutionUpdateType } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
import { ICellExecutionComplete, ICellExecutionStateUpdate } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { OutputChannelUpdateMode } from 'vs/workbench/contrib/output/common/output';
import { InputValidationType } from 'vs/workbench/contrib/scm/common/scm';
@@ -922,7 +923,7 @@ export interface INotebookKernelDto2 {
export interface ICellExecuteOutputEditDto {
editType: CellExecutionUpdateType.Output;
executionHandle: number;
uri: UriComponents;
cellHandle: number;
append?: boolean;
outputs: NotebookOutputDto[]
@@ -930,21 +931,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 +957,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 {
@@ -2088,6 +2092,7 @@ export interface ExtHostNotebookKernelsShape {
$executeCells(handle: number, uri: UriComponents, handles: number[]): Promise<void>;
$cancelCells(handle: number, uri: UriComponents, handles: number[]): Promise<void>;
$acceptKernelMessageFromRenderer(handle: number, editorId: string, message: any): void;
$cellExecutionChanged(uri: UriComponents, cellHandle: number, state: notebookCommon.NotebookCellExecutionState | undefined): void;
}
export interface ExtHostInteractiveShape {

View File

@@ -56,8 +56,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
readonly onDidChangeCellMetadata = this._onDidChangeCellMetadata.event;
private readonly _onDidChangeActiveNotebookEditor = new Emitter<vscode.NotebookEditor | undefined>();
readonly onDidChangeActiveNotebookEditor = this._onDidChangeActiveNotebookEditor.event;
private readonly _onDidChangeCellExecutionState = new Emitter<vscode.NotebookCellExecutionStateChangeEvent>();
readonly onDidChangeNotebookCellExecutionState = this._onDidChangeCellExecutionState.event;
private _activeNotebookEditor: ExtHostNotebookEditor | undefined;
get activeNotebookEditor(): vscode.NotebookEditor | undefined {
@@ -459,9 +457,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
},
emitCellMetadataChange(event: vscode.NotebookCellMetadataChangeEvent): void {
that._onDidChangeCellMetadata.fire(event);
},
emitCellExecutionStateChange(event: vscode.NotebookCellExecutionStateChangeEvent): void {
that._onDidChangeCellExecutionState.fire(event);
}
},
uri,

View File

@@ -10,7 +10,6 @@ import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostDocumentsAndEditors, IExtHostModelAddedData } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import * as notebookCommon from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
@@ -129,7 +128,6 @@ export interface INotebookEventEmitter {
emitModelChange(events: vscode.NotebookCellsChangeEvent): void;
emitCellOutputsChange(event: vscode.NotebookCellOutputsChangeEvent): void;
emitCellMetadataChange(event: vscode.NotebookCellMetadataChangeEvent): void;
emitCellExecutionStateChange(event: vscode.NotebookCellExecutionStateChangeEvent): void;
}
@@ -373,14 +371,7 @@ export class ExtHostNotebookDocument {
private _changeCellInternalMetadata(index: number, newInternalMetadata: notebookCommon.NotebookCellInternalMetadata): void {
const cell = this._cells[index];
const originalInternalMetadata = cell.internalMetadata;
cell.setInternalMetadata(newInternalMetadata);
if (originalInternalMetadata.runState !== newInternalMetadata.runState) {
const executionState = newInternalMetadata.runState ?? extHostTypes.NotebookCellExecutionState.Idle;
this._emitter.emitCellExecutionStateChange(deepFreeze({ document: this.apiNotebook, cell: cell.apiCell, state: executionState }));
}
}
getCellFromApiCell(apiCell: vscode.NotebookCell): ExtHostCell | undefined {

View File

@@ -18,8 +18,9 @@ import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitData
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { ExtHostCell, ExtHostNotebookDocument } from 'vs/workbench/api/common/extHostNotebookDocument';
import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import { NotebookCellOutput } from 'vs/workbench/api/common/extHostTypes';
import { NotebookCellOutput, NotebookCellExecutionState as ExtHostNotebookCellExecutionState } from 'vs/workbench/api/common/extHostTypes';
import { asWebviewUri } from 'vs/workbench/api/common/shared/webview';
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellExecutionUpdateType } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
@@ -46,6 +47,9 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape {
private readonly _kernelData = new Map<number, IKernelData>();
private _handlePool: number = 0;
private readonly _onDidChangeCellExecutionState = new Emitter<vscode.NotebookCellExecutionStateChangeEvent>();
readonly onDidChangeNotebookCellExecutionState = this._onDidChangeCellExecutionState.event;
constructor(
mainContext: IMainContext,
private readonly _initData: IExtHostInitDataService,
@@ -331,6 +335,17 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape {
obj.onDidReceiveMessage.fire(Object.freeze({ editor: editor.apiEditor, message }));
}
$cellExecutionChanged(uri: UriComponents, cellHandle: number, state: NotebookCellExecutionState | undefined): void {
const document = this._extHostNotebook.getNotebookDocument(URI.revive(uri));
const cell = document.getCell(cellHandle);
if (cell) {
this._onDidChangeCellExecutionState.fire({
cell: cell.apiCell,
state: state ?? ExtHostNotebookCellExecutionState.Idle
});
}
}
// ---
_createNotebookCellExecution(cell: vscode.NotebookCell): vscode.NotebookCellExecution {
@@ -366,9 +381,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 +403,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 +460,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 +471,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 +489,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 +505,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 +519,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> {