Skip to content

Commit 5854a03

Browse files
Hide notebook console actions behind existing setting (#11072)
Addresses #9948 ### Prior Behavior When the `console.showNotebookConsoles` setting (Console -> Show Notebook Consoles) is enabled, a console instance gets automatically created for a notebook session (for built-in notebooks and Positron Notebooks). We also have two commands that allow a user to create/focus a console instance for a notebook session that we always showed. These actions did not depend on the `console.showNotebookConsoles` setting to be enabled to show up or work: - `workbench.action.positronConsole.showNotebookConsole`: The "Show Notebook Console" command in the editor toolbar for built-in notebooks that users could select to show/focus a console for the current notebook session. - `positronNotebook.showConsole`: The "Open Notebook Console" command in the kernel menu dropdown for Positron Notebooks that users could select to show/focus a console for the current notebook session. There is also `positronNotebook.executeSelectionInConsole`: The "Notebook: Execute Selection In Console" menu item that lets you execute a highlighted portion from a notebook cell in the console for the current notebook. NOTE: The `Execute Selection in Console` doesn't ever show up in the Positron Notebook right-click menu. This is a known bug and unrelated to this change! ### New Behavior This PR introduces a new setting called `console.showNotebookConsoleActions` that controls whether a user sees the commands described above. The new behavior is as follows: - Both OFF (default): - Console instances will NOT be automatically created for open notebooks. The "Show/Open Notebook Console" and "Notebook: Execute Selection In Console" menu items will NOT show up for notebooks. - `console.showNotebookConsoleActions` ON only: - Console instances will NOT be automatically created for open notebooks. The "Show/Open Notebook Console" and "Notebook: Execute Selection In Console" menu items WILL show up for notebooks. - For users who want control over when a notebook console appear. They can manually trigger console creation when needed. - `console.showNotebookConsoles` ON only: - Console instances WILL BE automatically created for open notebooks. The "Show/Open Notebook Console" and "Notebook: Execute Selection In Console" menu items will NOT show up for notebooks. - For users who want consoles for all notebooks and don't need the toolbar buttons cluttering their UI. - Both ON: - Console instances WILL BE automatically created for open notebooks. The "Show/Open Notebook Console" and "Notebook: Execute Selection In Console" menu items WILL show up for notebooks. Once this PR is merged, I'll leave a comment in #3801 that introduced this change to let users know they will need to opt into the new setting to see the new commands: ``` ### Notebook Console Actions Now Opt-In Hey folks! We've made this notebook console work an opt-in feature for now based o feedback in [#9948](#9948). **What's new:** - Added a new setting **Console: Show Notebook Console Actions** (`console.showNotebookConsoleActions`) that controls whether the "Show Notebook Console" and "Execute Selection in Console " commands appear in your notebook toolbar/menu/command palette. It's off by default to keep the UI clean while we refine the experience. The existing **Console: Show Notebook Consoles** (`console.showNotebookConsoles`) setting hasn't changed and still controls whether consoles are automatically created when you open a notebook. These two settings are independent, so you can mix and match based on your workflow: - Turn on **Console: Show Notebook Console Actions** to manually show consoles when you need them - Turn on **Console: Show Notebook Consoles** if you want consoles for all notebooks without the extra toolbar buttons - Turn on both if you want all the options! Both settings are experimental for now as we gather feedback and refine the experience. ``` ### Screenshots **BEFORE - setting OFF** https://github.com/user-attachments/assets/b048c49c-281c-4312-8a14-8550b971b96f **BEFORE - setting ON** https://github.com/user-attachments/assets/9211a94b-c246-416d-a53c-332807a124a7 **AFTER - Both OFF** https://github.com/user-attachments/assets/bb19b331-a65b-45d7-b64b-33d2f05f65ac **AFTER - BOTH ON** https://github.com/user-attachments/assets/1214c36d-0d6e-487e-b74a-87321ae23829 **AFTER - `console.showNotebookConsoles` ON** https://github.com/user-attachments/assets/ae5d7219-9f99-4855-804a-ec7e42081acb **AFTER - `console.showNotebookConsoleActions` ON** https://github.com/user-attachments/assets/ec34edfc-9be2-4808-81fc-a1ead5c1d19d https://github.com/user-attachments/assets/0cca0ca5-12dc-44ad-ac0d-c0e3cffd5148 ### Release Notes <!-- Optionally, replace `N/A` with text to be included in the next release notes. The `N/A` bullets are ignored. If you refer to one or more Positron issues, these issues are used to collect information about the feature or bugfix, such as the relevant language pack as determined by Github labels of type `lang: `. The note will automatically be tagged with the language. These notes are typically filled by the Positron team. If you are an external contributor, you may ignore this section. --> #### New Features - Following up on the shared notebook/console kernel feature ([#3801](#3801)), notebook console action buttons are now hidden by default ([#9948](#9948)). Enable **Console: Show Notebook Console Actions** to display "Show Notebook Console" option in notebook toolbars. #### Bug Fixes - N/A ### QA Notes @:positron-notebooks <!-- Positron team members: please add relevant e2e test tags, so the tests can be run when you open this pull request. - Instructions: https://github.com/posit-dev/positron/blob/main/test/e2e/README.md#pull-requests-and-test-tags - Available tags: https://github.com/posit-dev/positron/blob/main/test/e2e/infra/test-runner/test-tags.ts --> <!-- Add additional information for QA on how to validate the change, paying special attention to the level of risk, adjacent areas that could be affected by the change, and any important contextual information not present in the linked issues. -->
1 parent 440aa61 commit 5854a03

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,13 +1064,17 @@ export function registerPositronConsoleActions() {
10641064
},
10651065
f1: true,
10661066
category,
1067+
precondition: ContextKeyExpr.equals('config.console.showNotebookConsoleActions', true),
10671068
menu: [
10681069
{
10691070
// Add an entry to the notebook toolbar to show the
10701071
// notebook console
10711072
id: MenuId.NotebookToolbar,
10721073
group: 'notebookConsole',
1073-
when: ContextKeyExpr.equals('config.notebook.globalToolbar', true),
1074+
when: ContextKeyExpr.and(
1075+
ContextKeyExpr.equals('config.notebook.globalToolbar', true),
1076+
ContextKeyExpr.equals('config.console.showNotebookConsoleActions', true)
1077+
),
10741078
order: 1
10751079
}
10761080
]

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ export class ExecuteSelectionInConsoleAction extends Action2 {
3737
title: localize2('positronNotebookActions.executeSelectionInConsole', 'Execute Selection in Console'),
3838
icon: executeIcon,
3939
f1: true,
40-
// Only enable if the active editor is a notebook (Positron or built-in)
41-
precondition: ContextKeyExpr.or(
42-
ContextKeyExpr.equals('activeEditor', POSITRON_NOTEBOOK_EDITOR_ID),
43-
ContextKeyExpr.equals('activeEditor', NOTEBOOK_EDITOR_ID),
40+
// Only enable if the active editor is a notebook (Positron or built-in) and the notebook console actions setting is enabled
41+
precondition: ContextKeyExpr.and(
42+
ContextKeyExpr.or(
43+
ContextKeyExpr.equals('activeEditor', POSITRON_NOTEBOOK_EDITOR_ID),
44+
ContextKeyExpr.equals('activeEditor', NOTEBOOK_EDITOR_ID),
45+
),
46+
ContextKeyExpr.equals('config.console.showNotebookConsoleActions', true)
4447
),
4548
// Show in the cell context menu, but only for code cells and when there's a selection
4649
menu: [
@@ -53,7 +56,8 @@ export class ExecuteSelectionInConsoleAction extends Action2 {
5356
group: CELL_TITLE_CELL_GROUP_ID,
5457
when: ContextKeyExpr.and(
5558
NOTEBOOK_CELL_TYPE.isEqualTo('code'),
56-
EditorContextKeys.hasNonEmptySelection
59+
EditorContextKeys.hasNonEmptySelection,
60+
ContextKeyExpr.equals('config.console.showNotebookConsoleActions', true)
5761
),
5862
}
5963
]

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,14 +1270,21 @@ registerAction2(class extends NotebookAction2 {
12701270
icon: ThemeIcon.fromId('terminal'),
12711271
f1: true,
12721272
category: POSITRON_NOTEBOOK_CATEGORY,
1273-
precondition: ActiveNotebookHasRunningRuntime,
1273+
precondition: ContextKeyExpr.and(
1274+
ActiveNotebookHasRunningRuntime,
1275+
ContextKeyExpr.equals('config.console.showNotebookConsoleActions', true)
1276+
),
12741277
positronActionBarOptions: {
12751278
controlType: 'button',
12761279
displayTitle: true
12771280
},
12781281
menu: {
12791282
id: MenuId.PositronNotebookKernelSubmenu,
12801283
order: 100,
1284+
when: ContextKeyExpr.and(
1285+
ActiveNotebookHasRunningRuntime,
1286+
ContextKeyExpr.equals('config.console.showNotebookConsoleActions', true)
1287+
)
12811288
}
12821289
});
12831290
}

src/vs/workbench/services/positronConsole/browser/positronConsoleService.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,19 @@ configurationRegistry.registerConfiguration({
269269
'default': 1000,
270270
markdownDescription: localize('console.scrollbackSize', "The number of console output items to display."),
271271
},
272-
// Whether to show notebook consoles
272+
// Whether to automatically create consoles for notebook sessions
273273
'console.showNotebookConsoles': {
274274
type: 'boolean',
275275
default: false,
276-
markdownDescription: localize('console.showNotebookConsoles', "Whether to show consoles for open notebooks."),
276+
markdownDescription: localize('console.showNotebookConsoles', "Controls whether consoles are automatically shown for open notebooks."),
277+
tags: ['experimental'],
278+
},
279+
// Whether to show the notebook console actions in menus
280+
'console.showNotebookConsoleActions': {
281+
type: 'boolean',
282+
default: false,
283+
markdownDescription: localize('console.showNotebookConsoleActions', "Controls whether notebook console actions are visible in notebook toolbars. When enabled, you can manually show or focus a notebook console using the 'Show Notebook Console' menu item."),
284+
tags: ['experimental'],
277285
}
278286
}
279287
});

test/e2e/tests/notebooks-positron/notebook-kernel-behavior.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ test.describe('Positron Notebooks: Kernel Behavior', {
3131
// ensure when no kernel is selected, restart/shutdown are disabled
3232
await notebooksPositron.kernel.expectMenuToContain([
3333
{ label: 'Change Kernel', enabled: true },
34-
{ label: 'Open Notebook Console', enabled: false },
3534
{ label: 'Restart Kernel', enabled: false },
3635
{ label: 'Shutdown Kernel', enabled: false },
3736
]);
@@ -73,7 +72,6 @@ test.describe('Positron Notebooks: Kernel Behavior', {
7372
{ label: 'Restart Kernel', enabled: true },
7473
{ label: 'Shutdown Kernel', enabled: false },
7574
{ label: 'Change Kernel', enabled: true },
76-
{ label: 'Open Notebook Console', enabled: false },
7775
]);
7876

7977
// re-start kernel from shutdown state and ensure state changes
@@ -175,9 +173,12 @@ test.describe('Positron Notebooks: Kernel Behavior', {
175173
});
176174
});
177175

178-
test('ensure notebook console attaches and terminates with active kernel', async function ({ app, sessions }) {
176+
test('ensure notebook console attaches and terminates with active kernel', async function ({ app, sessions, settings }) {
179177
const { notebooksPositron, console } = app.workbench;
180178

179+
// Enable the notebook console actions setting for this test
180+
await settings.set({ 'console.showNotebookConsoleActions': true }, { reload: true, waitMs: 1000 });
181+
181182
const [, rSession] = await sessions.start(['python', 'r']);
182183
await sessions.select(rSession.id);
183184

@@ -203,6 +204,9 @@ test.describe('Positron Notebooks: Kernel Behavior', {
203204
kernelGroup: 'R',
204205
status: 'disconnected'
205206
});
207+
208+
// Disable the notebook console actions setting after this test
209+
await settings.remove(['console.showNotebookConsoleActions']);
206210
});
207211
});
208212

0 commit comments

Comments
 (0)