Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify Stop/Interrupt in core and jupyter #160738

Merged
merged 2 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/vs/workbench/api/browser/mainThreadNotebookKernels.ts
Expand Up @@ -90,6 +90,10 @@ abstract class MainThreadKernel implements INotebookKernel {
this.implementsExecutionOrder = data.supportsExecutionOrder;
event.hasExecutionOrder = true;
}
if (data.supportsInterrupt !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a scenario for when a kernel goes from supporting Interrupt to not supporting Interrupt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 we should handle this, and also for other properties too supportsExecutionOrder. Will have follow up PRs for this.

this.implementsInterrupt = data.supportsInterrupt;
event.hasInterruptHandler = true;
}
this._onDidChange.fire(event);
}

Expand Down
Expand Up @@ -5,7 +5,7 @@

import { Iterable } from 'vs/base/common/iterator';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { URI, UriComponents } from 'vs/base/common/uri';
import { UriComponents } from 'vs/base/common/uri';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { localize } from 'vs/nls';
import { MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
Expand All @@ -27,6 +27,7 @@ import { Schemas } from 'vs/base/common/network';

const EXECUTE_NOTEBOOK_COMMAND_ID = 'notebook.execute';
const CANCEL_NOTEBOOK_COMMAND_ID = 'notebook.cancelExecution';
const INTERRUPT_NOTEBOOK_COMMAND_ID = 'notebook.interruptExecution';
const CANCEL_CELL_COMMAND_ID = 'notebook.cell.cancelExecution';
const EXECUTE_CELL_FOCUS_CONTAINER_COMMAND_ID = 'notebook.cell.executeAndFocusContainer';
const EXECUTE_CELL_SELECT_BELOW = 'notebook.cell.executeAndSelectBelow';
Expand Down Expand Up @@ -488,22 +489,61 @@ registerAction2(class ExecuteCellInsertBelow extends NotebookCellAction {
}
});

registerAction2(class CancelNotebook extends NotebookAction {
class CancelNotebook extends NotebookAction {
override getEditorContextFromArgsOrActive(accessor: ServicesAccessor, context?: UriComponents): INotebookActionContext | undefined {
return getContextFromUri(accessor, context) ?? getContextFromActiveEditor(accessor.get(IEditorService));
}

async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
return context.notebookEditor.cancelNotebookCells();
}
}

registerAction2(class CancelAllNotebook extends CancelNotebook {
constructor() {
super({
id: CANCEL_NOTEBOOK_COMMAND_ID,
title: localize('notebookActions.cancelNotebook', "Stop Execution"),
title: {
value: localize('notebookActions.cancelNotebook', "Stop Execution"),
original: 'Stop Execution'
},
icon: icons.stopIcon,
description: {
description: localize('notebookActions.cancelNotebook', "Stop Execution"),
args: [
{
name: 'uri',
description: 'The document uri',
constraint: URI
}
]
menu: [
{
id: MenuId.EditorTitle,
order: -1,
group: 'navigation',
when: ContextKeyExpr.and(
NOTEBOOK_IS_ACTIVE_EDITOR,
NOTEBOOK_HAS_RUNNING_CELL,
NOTEBOOK_INTERRUPTIBLE_KERNEL.toNegated(),
ContextKeyExpr.notEquals('config.notebook.globalToolbar', true)
)
},
{
id: MenuId.NotebookToolbar,
order: -1,
group: 'navigation/execute',
when: ContextKeyExpr.and(
NOTEBOOK_HAS_RUNNING_CELL,
NOTEBOOK_INTERRUPTIBLE_KERNEL.toNegated(),
ContextKeyExpr.equals('config.notebook.globalToolbar', true)
)
}
]
});
}
});

registerAction2(class InterruptNotebook extends CancelNotebook {
constructor() {
super({
id: INTERRUPT_NOTEBOOK_COMMAND_ID,
title: {
value: localize('notebookActions.interruptNotebook', "Interrupt"),
original: 'Interrupt'
},
icon: icons.stopIcon,
menu: [
{
id: MenuId.EditorTitle,
Expand All @@ -529,14 +569,6 @@ registerAction2(class CancelNotebook extends NotebookAction {
]
});
}

override getEditorContextFromArgsOrActive(accessor: ServicesAccessor, context?: UriComponents): INotebookActionContext | undefined {
return getContextFromUri(accessor, context) ?? getContextFromActiveEditor(accessor.get(IEditorService));
}

async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
return context.notebookEditor.cancelNotebookCells();
}
});


Expand Down
Expand Up @@ -30,6 +30,7 @@ export class NotebookEditorContextKeys {
private readonly _disposables = new DisposableStore();
private readonly _viewModelDisposables = new DisposableStore();
private readonly _cellOutputsListeners: IDisposable[] = [];
private readonly _selectedKernelDisposables = new DisposableStore();

constructor(
private readonly _editor: INotebookEditorDelegate,
Expand Down Expand Up @@ -174,6 +175,13 @@ export class NotebookEditorContextKeys {
this._interruptibleKernel.set(selected?.implementsInterrupt ?? false);
this._notebookKernelSelected.set(Boolean(selected));
this._notebookKernel.set(selected?.id ?? '');

this._selectedKernelDisposables.clear();
if (selected) {
this._selectedKernelDisposables.add(selected.onDidChange(() => {
this._interruptibleKernel.set(selected?.implementsInterrupt ?? false);
}));
}
}

private _updateForNotebookOptions(): void {
Expand Down
Expand Up @@ -30,6 +30,7 @@ export interface INotebookKernelChangeEvent {
kind?: true;
supportedLanguages?: true;
hasExecutionOrder?: true;
hasInterruptHandler?: true;
}

export interface INotebookKernel {
Expand Down