Skip to content

Commit

Permalink
Merge pull request #7789 from markellekelly/restart-run-to
Browse files Browse the repository at this point in the history
Add command to restart kernel and run up to selected cell
  • Loading branch information
Steven Silvester committed Jan 16, 2020
2 parents ac3ab8c + 804d0f4 commit 2ae17ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 2ae17ef

Please sign in to comment.