Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ registerNotebookAction({
icon: ThemeIcon.fromId('notebook-execute-all'),
positronActionBarOptions: {
controlType: 'button',
displayTitle: true
displayTitle: false
}
},
keybinding: {
Expand All @@ -841,7 +841,7 @@ registerNotebookAction({
icon: ThemeIcon.fromId('positron-clean'),
positronActionBarOptions: {
controlType: 'button',
displayTitle: true
displayTitle: false
}
},
keybinding: {
Expand All @@ -854,10 +854,10 @@ registerNotebookAction({
commandId: 'positronNotebook.showConsole',
handler: (notebook) => notebook.showNotebookConsole(),
menu: {
id: MenuId.EditorActionsLeft,
group: 'navigation',
id: MenuId.EditorTitle,
group: 'kernel',
order: 30,
title: { value: localize('showConsole', 'Show Console'), original: 'Show Console' },
title: { value: localize('showConsole', 'Show Notebook Console'), original: 'Show Notebook Console' },
icon: ThemeIcon.fromId('terminal'),
positronActionBarOptions: {
controlType: 'button',
Expand All @@ -874,9 +874,9 @@ registerNotebookAction({
notebook.addCell(CellKind.Code, cellCount);
},
menu: {
id: MenuId.EditorActionsRight,
id: MenuId.EditorActionsLeft,
group: 'navigation',
order: 10,
order: 30,
title: { value: localize('addCodeCell', 'Code'), original: 'Code' },
icon: ThemeIcon.fromId('add'),
positronActionBarOptions: {
Expand All @@ -894,9 +894,9 @@ registerNotebookAction({
notebook.addCell(CellKind.Markup, cellCount);
},
menu: {
id: MenuId.EditorActionsRight,
id: MenuId.EditorActionsLeft,
group: 'navigation',
order: 20,
order: 40,
title: { value: localize('addMarkdownCell', 'Markdown'), original: 'Markdown' },
icon: ThemeIcon.fromId('add'),
positronActionBarOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { Codicon } from '../../../../base/common/codicons.js';
import { isUriComponents, URI } from '../../../../base/common/uri.js';
import { localize, localize2 } from '../../../../nls.js';
import { Action2, MenuId, registerAction2 } from '../../../../platform/actions/common/actions.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
Expand All @@ -15,6 +16,7 @@ import { IRuntimeSessionService } from '../../../services/runtimeSession/common/
import { NotebookEditorWidget } from '../../notebook/browser/notebookEditorWidget.js';
import { NOTEBOOK_KERNEL } from '../../notebook/common/notebookContextKeys.js';
import { isNotebookEditorInput } from '../../notebook/common/notebookEditorInput.js';
import { POSITRON_NOTEBOOK_EDITOR_ID } from '../../positronNotebook/common/positronNotebookCommon.js';
import { ActiveNotebookHasRunningRuntime } from '../common/activeRuntimeNotebookContextManager.js';
import { POSITRON_RUNTIME_NOTEBOOK_KERNELS_EXTENSION_ID } from '../common/runtimeNotebookKernelConfig.js';

Expand All @@ -39,29 +41,58 @@ class RuntimeNotebookKernelRestartAction extends Action2 {
super({
id: RuntimeNotebookKernelRestartAction.ID,
title: localize2('positron.command.restartNotebookInterpreter', 'Restart Kernel'),
icon: Codicon.debugRestart,
positronActionBarOptions: {
controlType: 'button',
displayTitle: false
},
icon: Codicon.positronRestartRuntimeThin,
f1: true,
category,
precondition: ActiveNotebookHasRunningRuntime,
menu: [
// VSCode notebooks
{
id: MenuId.NotebookToolbar,
group: 'navigation/execute@5',
order: 5,
when: NOTEBOOK_POSITRON_KERNEL_SELECTED,
},
// Positron notebooks
{
id: MenuId.EditorActionsRight,
group: 'navigation',
order: 0,
when: ContextKeyExpr.equals('activeEditor', POSITRON_NOTEBOOK_EDITOR_ID),
}
]
});
}

override async run(accessor: ServicesAccessor, context?: INotebookEditorToolbarContext): Promise<void> {
override async run(accessor: ServicesAccessor, context?: INotebookEditorToolbarContext | URI): Promise<void> {
const editorService = accessor.get(IEditorService);
const progressService = accessor.get(IProgressService);
const notificationService = accessor.get(INotificationService);
const runtimeSessionService = accessor.get(IRuntimeSessionService);

// Try to use the notebook URI from the context - set if run via the notebook editor toolbar.
let notebookUri = context?.notebookEditor.textModel?.uri;
let notebookUri: URI | undefined;
let source: string;
if (context) {
if (isUriComponents(context)) {
source = 'User clicked restart button in Positron notebook editor toolbar';
notebookUri = context;
} else {
source = 'User clicked restart button in VSCode notebook editor toolbar';
notebookUri = context.notebookEditor.textModel?.uri;
}
} else {
source = `Restart notebook kernel command ${RuntimeNotebookKernelRestartAction.ID} executed`;
const activeEditor = editorService.activeEditor;
if (!isNotebookEditorInput(activeEditor)) {
throw new Error('No active notebook. This command should only be available when a notebook is active.');
}
notebookUri = activeEditor.resource;
}

// If no context was provided, try to get the active notebook URI.
if (!notebookUri) {
Expand All @@ -84,10 +115,7 @@ class RuntimeNotebookKernelRestartAction extends Action2 {
location: ProgressLocation.Notification,
title: localize("positron.notebook.restart.restarting", "Restarting {0} interpreter for '{1}'",
session.runtimeMetadata.runtimeName, notebookUri.fsPath),
}, () => runtimeSessionService.restartSession(session.metadata.sessionId,
context ?
'User clicked restart button in the notebook editor toolbar' :
`Restart notebook kernel command ${RuntimeNotebookKernelRestartAction.ID} executed`));
}, () => runtimeSessionService.restartSession(session.metadata.sessionId, source));
} catch (error) {
notificationService.error(
localize("positron.notebook.restart.failed", "Restarting {0} interpreter for '{1}' failed. Reason: {2}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { isEqual } from '../../../../base/common/resources.js';
import { URI } from '../../../../base/common/uri.js';
import { localize } from '../../../../nls.js';
import { IContextKey, IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
import { EditorInput } from '../../../common/editor/editorInput.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { ILanguageRuntimeInfo, LanguageRuntimeSessionMode, RuntimeState } from '../../../services/languageRuntime/common/languageRuntimeService.js';
import { ILanguageRuntimeSession, IRuntimeSessionService } from '../../../services/runtimeSession/common/runtimeSessionService.js';
import { isNotebookEditorInput } from '../../notebook/common/notebookEditorInput.js';
import { isNotebookEditorInput as isVSCodeNotebookEditorInput } from '../../notebook/common/notebookEditorInput.js';
import { POSITRON_NOTEBOOK_EDITOR_INPUT_ID } from '../../positronNotebook/common/positronNotebookCommon.js';

/** Whether the active notebook has a running runtime. */
export const ActiveNotebookHasRunningRuntime = new RawContextKey<boolean>(
Expand Down Expand Up @@ -163,3 +165,10 @@ export class ActiveRuntimeNotebookContextManager extends Disposable {
);
}
}

function isNotebookEditorInput(editor: EditorInput | undefined): editor is EditorInput & { resource: URI } {
return editor !== undefined && (
isVSCodeNotebookEditorInput(editor) ||
(editor.typeId === POSITRON_NOTEBOOK_EDITOR_INPUT_ID && editor.resource !== undefined)
);
}