Skip to content

Commit 202ebc4

Browse files
committed
fix actions from kernel menu
1 parent 5cc56fc commit 202ebc4

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/vs/workbench/contrib/positronNotebook/browser/KernelStatusBadge.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { localize } from '../../../../nls.js';
1818
import { MenuId, MenuItemAction, SubmenuItemAction } from '../../../../platform/actions/common/actions.js';
1919
import { ActionBarMenuButton } from '../../../../platform/positronActionBar/browser/components/actionBarMenuButton.js';
2020
import { useMenu } from './useMenu.js';
21+
import { IPositronNotebookActionBarContext } from '../../runtimeNotebookKernel/browser/runtimeNotebookKernelActions.js';
2122

2223
const kernelStatusToRuntimeStatus = {
2324
[KernelStatus.Uninitialized]: RuntimeStatus.Disconnected,
@@ -51,7 +52,10 @@ export function KernelStatusBadge() {
5152
}
5253
const actions: (MenuItemAction | SubmenuItemAction)[] = [];
5354
for (const [_group, groupActions] of menu.current.getActions({
54-
arg: notebookInstance.uri,
55+
arg: {
56+
uri: notebookInstance.uri,
57+
ui: true,
58+
} satisfies IPositronNotebookActionBarContext,
5559
shouldForwardArgs: true,
5660
})) {
5761
actions.push(...groupActions);

src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookInstance.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { IPositronNotebookService } from './positronNotebookService.js';
2828
import { IPositronNotebookInstance, KernelStatus } from './IPositronNotebookInstance.js';
2929
import { NotebookCellTextModel } from '../../notebook/common/model/notebookCellTextModel.js';
3030
import { ICommandService } from '../../../../platform/commands/common/commands.js';
31-
import { SELECT_KERNEL_ID_POSITRON, SelectPositronNotebookKernelContext } from './SelectPositronNotebookKernelAction.js';
31+
import { SELECT_KERNEL_ID_POSITRON } from './SelectPositronNotebookKernelAction.js';
3232
import { INotebookKernel, INotebookKernelService } from '../../notebook/common/notebookKernelService.js';
3333
import { IRuntimeSessionService } from '../../../services/runtimeSession/common/runtimeSessionService.js';
3434
import { isEqual } from '../../../../base/common/resources.js';
@@ -932,10 +932,7 @@ export class PositronNotebookInstance extends Disposable implements IPositronNot
932932
if (this.kernelStatus.get() !== KernelStatus.Connected) {
933933
this._logService.info(this.id, 'No kernel connected, attempting to connect');
934934
// Attempt to connect to the kernel
935-
await this._commandService.executeCommand(
936-
SELECT_KERNEL_ID_POSITRON,
937-
{ forceDropdown: false } satisfies SelectPositronNotebookKernelContext
938-
);
935+
await this._commandService.executeCommand(SELECT_KERNEL_ID_POSITRON);
939936
}
940937

941938
const hasExecutions = [...cells].some(cell => Boolean(this.notebookExecutionStateService.getCellExecution(cell.uri)));

src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ import { PositronNotebookInstance } from './PositronNotebookInstance.js';
1313
import { IPositronNotebookService } from './positronNotebookService.js';
1414
import { POSITRON_RUNTIME_NOTEBOOK_KERNELS_EXTENSION_ID } from '../../runtimeNotebookKernel/common/runtimeNotebookKernelConfig.js';
1515
import { Codicon } from '../../../../base/common/codicons.js';
16+
import { IPositronNotebookActionBarContext } from '../../runtimeNotebookKernel/browser/runtimeNotebookKernelActions.js';
1617

1718
export const SELECT_KERNEL_ID_POSITRON = 'positronNotebook.selectKernel';
1819
const NOTEBOOK_ACTIONS_CATEGORY_POSITRON = localize2('positronNotebookActions.category', 'Positron Notebook');
1920
const NOTEBOOK_IS_ACTIVE_EDITOR = ContextKeyExpr.equals('activeEditor', 'workbench.editor.positronNotebook');
2021

21-
export interface SelectPositronNotebookKernelContext {
22-
forceDropdown: boolean;
23-
}
24-
2522
class SelectPositronNotebookKernelAction extends Action2 {
2623

2724
constructor() {
@@ -39,8 +36,9 @@ class SelectPositronNotebookKernelAction extends Action2 {
3936
});
4037
}
4138

42-
async run(accessor: ServicesAccessor, context?: SelectPositronNotebookKernelContext): Promise<boolean> {
43-
const { forceDropdown } = context || { forceDropdown: false };
39+
async run(accessor: ServicesAccessor, context?: IPositronNotebookActionBarContext): Promise<boolean> {
40+
// Force the dropdown if the action was invoked by the user in the UI
41+
const forceDropdown = context?.ui ?? false;
4442
const notebookKernelService = accessor.get(INotebookKernelService);
4543
const notebookService = accessor.get(IPositronNotebookService);
4644
const activeNotebook = notebookService.getActiveInstance();

src/vs/workbench/contrib/runtimeNotebookKernel/browser/runtimeNotebookKernelActions.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ interface INotebookEditorToolbarContext {
3636
source: 'notebookToolbar';
3737
}
3838

39+
export interface IPositronNotebookActionBarContext {
40+
ui: boolean;
41+
uri: URI;
42+
}
43+
44+
function isPositronNotebookActionBarContext(obj: unknown): obj is IPositronNotebookActionBarContext {
45+
const context = obj as IPositronNotebookActionBarContext;
46+
return !!context && typeof context.ui === 'boolean' && isUriComponents(context.uri);
47+
}
48+
3949
/** The context for actions in a notebook using a language runtime kernel. */
4050
interface IRuntimeNotebookKernelActionContext {
4151
/** The notebook's language runtime session, if any */
@@ -51,20 +61,20 @@ interface IRuntimeNotebookKernelActionContext {
5161
abstract class BaseRuntimeNotebookKernelAction extends Action2 {
5262
abstract runWithContext(accessor: ServicesAccessor, context?: IRuntimeNotebookKernelActionContext): Promise<void>;
5363

54-
override async run(accessor: ServicesAccessor, context?: INotebookEditorToolbarContext | URI): Promise<void> {
64+
override async run(accessor: ServicesAccessor, context?: INotebookEditorToolbarContext | IPositronNotebookActionBarContext): Promise<void> {
5565
const editorService = accessor.get(IEditorService);
5666
const runtimeSessionService = accessor.get(IRuntimeSessionService);
5767

5868
// Try to use the notebook URI from the context - set if run via the notebook editor toolbar.
5969
let notebookUri: URI | undefined;
6070
let source: IRuntimeNotebookKernelActionContext['source'];
6171
if (context) {
62-
if (isUriComponents(context)) {
72+
if (isPositronNotebookActionBarContext(context)) {
6373
source = {
6474
id: 'positronNotebookActionBar',
6575
debugMessage: 'User clicked restart button in Positron notebook editor toolbar',
6676
};
67-
notebookUri = context;
77+
notebookUri = context.uri;
6878
} else {
6979
source = {
7080
id: 'vscodeNotebookToolbar',

0 commit comments

Comments
 (0)