allow notebook cancel execution with proxy kernel.

This commit is contained in:
rebornix 2022-04-14 12:05:38 -07:00
parent 9fe5271dac
commit 7195f05a16
No known key found for this signature in database
GPG key ID: 0299D52A1BBA52AB
2 changed files with 20 additions and 8 deletions

View file

@ -4,6 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ILogService } from 'vs/platform/log/common/log';
import { IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust';
@ -14,8 +16,9 @@ import { INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
import { INotebookKernelService, NotebookKernelType } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
export class NotebookExecutionService implements INotebookExecutionService {
export class NotebookExecutionService implements INotebookExecutionService, IDisposable {
declare _serviceBrand: undefined;
private _activeProxyKernelExecutionToken: CancellationTokenSource | undefined;
constructor(
@ICommandService private readonly _commandService: ICommandService,
@ -46,9 +49,10 @@ export class NotebookExecutionService implements INotebookExecutionService {
}
if (kernel.type === NotebookKernelType.Proxy) {
// we should actually resolve the kernel
this._activeProxyKernelExecutionToken?.dispose(true);
const tokenSource = this._activeProxyKernelExecutionToken = new CancellationTokenSource();
const resolved = await kernel.resolveKernel(notebook.uri);
let kernels = this._notebookKernelService.getMatchingKernel(notebook);
const kernels = this._notebookKernelService.getMatchingKernel(notebook);
const newlyMatchedKernel = kernels.all.find(k => k.id === resolved);
if (!newlyMatchedKernel) {
@ -56,6 +60,11 @@ export class NotebookExecutionService implements INotebookExecutionService {
}
kernel = newlyMatchedKernel;
if (tokenSource.token.isCancellationRequested) {
// execution was cancelled but we still need to update the active kernel
this._notebookKernelService.selectKernelForNotebook(kernel, notebook);
return;
}
}
if (kernel.type === NotebookKernelType.Proxy) {
@ -93,15 +102,19 @@ export class NotebookExecutionService implements INotebookExecutionService {
const kernel = this._notebookKernelService.getSelectedOrSuggestedKernel(notebook);
if (kernel) {
if (kernel.type === NotebookKernelType.Proxy) {
// we should handle cancelling proxy kernel too
return;
this._activeProxyKernelExecutionToken?.dispose(true);
} else {
await kernel.cancelNotebookCellExecution(notebook.uri, cellsArr);
}
await kernel.cancelNotebookCellExecution(notebook.uri, cellsArr);
}
}
async cancelNotebookCells(notebook: INotebookTextModel, cells: Iterable<NotebookCellTextModel>): Promise<void> {
this.cancelNotebookCellHandles(notebook, Array.from(cells, cell => cell.handle));
}
dispose() {
this._activeProxyKernelExecutionToken?.dispose(true);
}
}

View file

@ -68,7 +68,7 @@ export class NotebooKernelActionViewItem extends ActionViewItem {
private _updateActionFromKernelInfo(info: INotebookKernelMatchResult): void {
this._kernelDisposable.clear();
this._action.enabled = true;
const selectedOrSuggested = info.selected ?? ((info.all.length === 1 && info.suggestions.length === 1 && !('resolveKernel' in info.suggestions[0])) ? info.suggestions[0] : undefined);
const selectedOrSuggested = info.selected ?? ((info.all.length === 1 && info.suggestions.length === 1 && info.suggestions[0].type === NotebookKernelType.Resolved) ? info.suggestions[0] : undefined);
if (selectedOrSuggested) {
// selected or suggested kernel
this._action.label = selectedOrSuggested.label;
@ -94,7 +94,6 @@ export class NotebooKernelActionViewItem extends ActionViewItem {
}
}));
}
} else {
// many kernels or no kernels
this._action.label = localize('select', "Select Kernel");