mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-13 01:04:23 +01:00
Merge branch 'roblou/executionService'
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import { flatten, groupBy, isNonEmptyArray } from 'vs/base/common/arrays';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { combinedDisposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { combinedDisposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { ILanguageService } from 'vs/editor/common/services/language';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
@@ -14,10 +14,11 @@ 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 { INotebookCellExecution, INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
|
||||
import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
|
||||
import { INotebookKernel, INotebookKernelChangeEvent, INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
|
||||
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
|
||||
import { ExtHostContext, ExtHostNotebookKernelsShape, ICellExecuteUpdateDto, IExtHostContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape } from '../common/extHost.protocol';
|
||||
import { ExtHostContext, ExtHostNotebookKernelsShape, ICellExecuteUpdateDto, ICellExecutionCompleteDto, IExtHostContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape } from '../common/extHost.protocol';
|
||||
|
||||
abstract class MainThreadKernel implements INotebookKernel {
|
||||
|
||||
@@ -106,14 +107,13 @@ 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, INotebookCellExecution>();
|
||||
private readonly _executions = new Set<string>();
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@ILanguageService private readonly _languageService: ILanguageService,
|
||||
@INotebookKernelService private readonly _notebookKernelService: INotebookKernelService,
|
||||
@INotebookExecutionService private readonly _notebookExecutionService: INotebookExecutionService,
|
||||
// @INotebookService private readonly _notebookService: INotebookService,
|
||||
@INotebookExecutionStateService private readonly _notebookExecutionStateService: INotebookExecutionStateService,
|
||||
@INotebookEditorService notebookEditorService: INotebookEditorService
|
||||
) {
|
||||
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostNotebookKernels);
|
||||
@@ -121,6 +121,20 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
|
||||
notebookEditorService.listNotebookEditors().forEach(this._onEditorAdd, this);
|
||||
notebookEditorService.onDidAddNotebookEditor(this._onEditorAdd, this, this._disposables);
|
||||
notebookEditorService.onDidRemoveNotebookEditor(this._onEditorRemove, this, this._disposables);
|
||||
|
||||
this._disposables.add(toDisposable(() => {
|
||||
// EH shut down, complete all executions started by this EH
|
||||
this._executions.forEach(e => {
|
||||
const uri = CellUri.parse(URI.parse(e));
|
||||
if (uri) {
|
||||
this._notebookExecutionStateService.completeNotebookCellExecution(uri.notebook, uri.handle, { });
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
this._disposables.add(this._notebookExecutionStateService.onDidChangeCellExecution(e => {
|
||||
this._proxy.$cellExecutionChanged(e.notebook, e.cellHandle, e.changed?.state);
|
||||
}));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
@@ -235,30 +249,34 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
|
||||
|
||||
// --- execution
|
||||
|
||||
$addExecution(handle: number, uri: UriComponents, cellHandle: number): void {
|
||||
const execution = this._notebookExecutionService.createNotebookCellExecution(URI.revive(uri), cellHandle);
|
||||
this._executions.set(handle, execution);
|
||||
$addExecution(rawUri: UriComponents, cellHandle: number): void {
|
||||
const uri = URI.revive(rawUri);
|
||||
this._notebookExecutionStateService.createNotebookCellExecution(uri, cellHandle);
|
||||
|
||||
const cellUri = CellUri.generateCellUri(uri, cellHandle, uri.scheme);
|
||||
this._executions.add(cellUri.toString());
|
||||
}
|
||||
|
||||
$updateExecutions(data: SerializableObjectWithBuffers<ICellExecuteUpdateDto[]>): void {
|
||||
const updates = data.value;
|
||||
const groupedUpdates = groupBy(updates, (a, b) => a.executionHandle - b.executionHandle);
|
||||
const groupedUpdates = groupBy(updates, (a, b) => a.cellHandle - b.cellHandle);
|
||||
groupedUpdates.forEach(datas => {
|
||||
const first = datas[0];
|
||||
const execution = this._executions.get(first.executionHandle);
|
||||
if (!execution) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
execution.update(datas.map(NotebookDto.fromCellExecuteUpdateDto));
|
||||
const uri = URI.revive(first.uri);
|
||||
this._notebookExecutionStateService.updateNotebookCellExecution(uri, first.cellHandle, datas.map(NotebookDto.fromCellExecuteUpdateDto));
|
||||
} catch (e) {
|
||||
onUnexpectedError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$removeExecution(handle: number): void {
|
||||
this._executions.delete(handle);
|
||||
$completeExecution(rawUri: UriComponents, cellHandle: number, data: SerializableObjectWithBuffers<ICellExecutionCompleteDto>): void {
|
||||
const uri = URI.revive(rawUri);
|
||||
this._notebookExecutionStateService.completeNotebookCellExecution(uri, cellHandle, NotebookDto.fromCellExecuteCompleteDto(data.value));
|
||||
|
||||
const cellUri = CellUri.generateCellUri(uri, cellHandle, uri.scheme);
|
||||
this._executions.delete(cellUri.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user