diff options
author | Peng Lyu <penn.lv@gmail.com> | 2022-09-13 20:53:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-13 20:53:04 +0300 |
commit | 28e52a46fe8df0c924c881e438e124c05f171b9c (patch) | |
tree | 851f3560ed1b66107a6a0ea46e6abc8427ddab90 /src | |
parent | b2672beffbf1b0dbfe0802880efe2019d26ac4c5 (diff) |
Unify Stop/Interrupt in core and jupyter (#160738)
* Unify Stop/Interrupt in core and jupyter
* ILocalizedString
Diffstat (limited to 'src')
4 files changed, 65 insertions, 20 deletions
diff --git a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts index 136d77a68c0..30702b46cd8 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts @@ -90,6 +90,10 @@ abstract class MainThreadKernel implements INotebookKernel { this.implementsExecutionOrder = data.supportsExecutionOrder; event.hasExecutionOrder = true; } + if (data.supportsInterrupt !== undefined) { + this.implementsInterrupt = data.supportsInterrupt; + event.hasInterruptHandler = true; + } this._onDidChange.fire(event); } diff --git a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts index 70d6930241c..eefafb7edab 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts @@ -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'; @@ -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'; @@ -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, @@ -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(); - } }); diff --git a/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts b/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts index 294f43e558b..35506ece47f 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts @@ -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, @@ -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 { diff --git a/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts b/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts index 756377bdd86..a32d1ba2815 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts @@ -30,6 +30,7 @@ export interface INotebookKernelChangeEvent { kind?: true; supportedLanguages?: true; hasExecutionOrder?: true; + hasInterruptHandler?: true; } export interface INotebookKernel { |