NotebookExecutionService should create execution objects
Towards #125668
This commit is contained in:
parent
99104943f5
commit
cb52f1a50e
3 changed files with 45 additions and 51 deletions
|
@ -14,9 +14,9 @@ import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
|
|||
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
|
||||
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { ICellExecuteUpdate, INotebookCellExecution, INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
|
||||
import { INotebookCellExecution, INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
|
||||
import { INotebookKernel, INotebookKernelChangeEvent, INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
|
||||
import { ICellExecuteUpdateDto, ExtHostContext, ExtHostNotebookKernelsShape, IExtHostContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape } from '../common/extHost.protocol';
|
||||
import { ExtHostContext, ExtHostNotebookKernelsShape, ICellExecuteUpdateDto, IExtHostContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape } from '../common/extHost.protocol';
|
||||
|
||||
abstract class MainThreadKernel implements INotebookKernel {
|
||||
|
||||
|
@ -99,7 +99,7 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
|
|||
private readonly _kernels = new Map<number, [kernel: MainThreadKernel, registraion: IDisposable]>();
|
||||
private readonly _proxy: ExtHostNotebookKernelsShape;
|
||||
|
||||
private readonly _executions = new Map<number, MainThreadExecution>();
|
||||
private readonly _executions = new Map<number, INotebookCellExecution>();
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
|
@ -229,9 +229,8 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
|
|||
// --- execution
|
||||
|
||||
$addExecution(handle: number, uri: UriComponents, cellHandle: number): void {
|
||||
const execution = new MainThreadExecution(handle, URI.revive(uri), cellHandle);
|
||||
const execution = this._notebookExecutionService.createNotebookCellExecution(URI.revive(uri), cellHandle);
|
||||
this._executions.set(handle, execution);
|
||||
this._notebookExecutionService.registerNotebookCellExecution(execution);
|
||||
}
|
||||
|
||||
$updateExecutions(updates: ICellExecuteUpdateDto[]): void {
|
||||
|
@ -251,18 +250,3 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
class MainThreadExecution implements INotebookCellExecution {
|
||||
private readonly _onDidChange = new Emitter<ICellExecuteUpdate[]>();
|
||||
readonly onDidChange: Event<Readonly<ICellExecuteUpdate[]>> = this._onDidChange.event;
|
||||
|
||||
constructor(
|
||||
readonly id: number,
|
||||
readonly notebook: URI,
|
||||
readonly cellHandle: number,
|
||||
) { }
|
||||
|
||||
update(updates: ICellExecuteUpdate[]): void {
|
||||
this._onDidChange.fire(updates);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
|
||||
import { CellEditType, ICellEditOperation, NotebookCellExecutionState, NotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { CellExecutionUpdateType, ICellExecuteUpdate, INotebookCellExecution, INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
|
||||
|
@ -16,33 +17,8 @@ export class NotebookExecutionService implements INotebookExecutionService {
|
|||
) {
|
||||
}
|
||||
|
||||
registerNotebookCellExecution(execution: INotebookCellExecution): void {
|
||||
const notebook = this._notebookService.getNotebookTextModel(execution.notebook);
|
||||
if (!notebook) {
|
||||
return;
|
||||
}
|
||||
|
||||
const startExecuteEdit: ICellEditOperation = {
|
||||
editType: CellEditType.PartialInternalMetadata,
|
||||
handle: execution.cellHandle,
|
||||
internalMetadata: {
|
||||
runState: NotebookCellExecutionState.Pending
|
||||
}
|
||||
};
|
||||
this._applyExecutionEdits(notebook, [startExecuteEdit]);
|
||||
|
||||
const listener = execution.onDidChange(updates => {
|
||||
const edits = updates.map(update => updateToEdit(update, execution.cellHandle));
|
||||
if (updates.some(update => update.editType === CellExecutionUpdateType.Complete)) {
|
||||
listener.dispose();
|
||||
}
|
||||
|
||||
this._applyExecutionEdits(notebook, edits);
|
||||
});
|
||||
}
|
||||
|
||||
private _applyExecutionEdits(notebook: NotebookTextModel, edits: ICellEditOperation[]): void {
|
||||
notebook.applyEdits(edits, true, undefined, () => undefined, undefined, false);
|
||||
createNotebookCellExecution(notebook: URI, cellHandle: number): INotebookCellExecution {
|
||||
return new CellExecution(notebook, cellHandle, this._notebookService);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,3 +66,38 @@ function updateToEdit(update: ICellExecuteUpdate, cellHandle: number): ICellEdit
|
|||
|
||||
throw new Error('Unknown cell update type');
|
||||
}
|
||||
|
||||
class CellExecution implements INotebookCellExecution {
|
||||
private readonly _notebookModel: NotebookTextModel;
|
||||
|
||||
constructor(
|
||||
readonly notebook: URI,
|
||||
readonly cellHandle: number,
|
||||
private readonly _notebookService: INotebookService,
|
||||
) {
|
||||
const notebookModel = this._notebookService.getNotebookTextModel(notebook);
|
||||
if (!notebookModel) {
|
||||
throw new Error('Notebook not found: ' + notebook);
|
||||
}
|
||||
|
||||
this._notebookModel = notebookModel;
|
||||
|
||||
const startExecuteEdit: ICellEditOperation = {
|
||||
editType: CellEditType.PartialInternalMetadata,
|
||||
handle: cellHandle,
|
||||
internalMetadata: {
|
||||
runState: NotebookCellExecutionState.Pending
|
||||
}
|
||||
};
|
||||
this._applyExecutionEdits([startExecuteEdit]);
|
||||
}
|
||||
|
||||
update(updates: ICellExecuteUpdate[]): void {
|
||||
const edits = updates.map(update => updateToEdit(update, this.cellHandle));
|
||||
this._applyExecutionEdits(edits);
|
||||
}
|
||||
|
||||
private _applyExecutionEdits(edits: ICellEditOperation[]): void {
|
||||
this._notebookModel.applyEdits(edits, true, undefined, () => undefined, undefined, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IOutputDto, IOutputItemDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
@ -48,10 +47,9 @@ export interface ICellExecutionComplete {
|
|||
}
|
||||
|
||||
export interface INotebookCellExecution {
|
||||
readonly id: number;
|
||||
readonly notebook: URI;
|
||||
readonly cellHandle: number;
|
||||
readonly onDidChange: Event<Readonly<ICellExecuteUpdate[]>>;
|
||||
update(updates: ICellExecuteUpdate[]): void;
|
||||
}
|
||||
|
||||
export const INotebookExecutionService = createDecorator<INotebookExecutionService>('INotebookExecutionService');
|
||||
|
@ -59,5 +57,6 @@ export const INotebookExecutionService = createDecorator<INotebookExecutionServi
|
|||
export interface INotebookExecutionService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
registerNotebookCellExecution(execution: INotebookCellExecution): void;
|
||||
// getExecutions(notebook: URI): INotebookCellExecution[];
|
||||
createNotebookCellExecution(notebook: URI, cellHandle: number): INotebookCellExecution;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue