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

Add command to restart kernel and run up to selected cell #7789

Merged
merged 2 commits into from Jan 16, 2020
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
3 changes: 3 additions & 0 deletions packages/mainmenu-extension/src/index.ts
Expand Up @@ -71,6 +71,8 @@ export namespace CommandIDs {

export const restartKernelAndClear = 'kernelmenu:restart-and-clear';

export const restartAndRunToSelected = 'notebook:restart-and-run-to-selected';

export const changeKernel = 'kernelmenu:change';

export const shutdownKernel = 'kernelmenu:shutdown';
Expand Down Expand Up @@ -547,6 +549,7 @@ export function createKernelMenu(app: JupyterFrontEnd, menu: KernelMenu): void {
const restartGroup = [
CommandIDs.restartKernel,
CommandIDs.restartKernelAndClear,
CommandIDs.restartAndRunToSelected,
CommandIDs.restartAndRunAll
].map(command => {
return { command };
Expand Down
30 changes: 30 additions & 0 deletions packages/notebook-extension/src/index.ts
Expand Up @@ -101,6 +101,8 @@ namespace CommandIDs {

export const restartClear = 'notebook:restart-clear-output';

export const restartAndRunToSelected = 'notebook:restart-and-run-to-selected';

export const restartRunAll = 'notebook:restart-run-all';

export const reconnectToKernel = 'notebook:reconnect-to-kernel';
Expand Down Expand Up @@ -1249,6 +1251,33 @@ function addCommands(
},
isEnabled
});
commands.addCommand(CommandIDs.restartAndRunToSelected, {
label: 'Restart Kernel and Run up to Selected Cell…',
execute: args => {
const current = getCurrent(args);
if (current) {
const { context, content } = current;
return sessionDialogs!
.restart(current.sessionContext)
.then(restarted => {
if (restarted) {
void NotebookActions.runAllAbove(
content,
context.sessionContext
).then(executed => {
if (executed || content.activeCellIndex === 0) {
void NotebookActions.run(content, context.sessionContext);
}
});
}
});
}
},
isEnabled: () => {
// Can't run if there are multiple cells selected
return isEnabledAndSingleSelected();
}
});
commands.addCommand(CommandIDs.restartRunAll, {
label: 'Restart Kernel and Run All Cells…',
execute: args => {
Expand Down Expand Up @@ -1918,6 +1947,7 @@ function populatePalette(
CommandIDs.renderAllMarkdown,
CommandIDs.runAllAbove,
CommandIDs.runAllBelow,
CommandIDs.restartAndRunToSelected,
CommandIDs.selectAll,
CommandIDs.deselectAll,
CommandIDs.clearAllOutputs,
Expand Down