Skip to content

Commit

Permalink
Add ability to restart kernel and run to current cell
Browse files Browse the repository at this point in the history
  • Loading branch information
alesgenova committed Jul 13, 2019
1 parent 621ae2a commit bf9bfa8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/mainmenu-extension/src/index.ts
Expand Up @@ -91,6 +91,8 @@ export namespace CommandIDs {

export const restartAndRunAll = 'runmenu:restart-and-run-all';

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

export const runAbove = 'runmenu:run-above';

export const runBelow = 'runmenu:run-below';
Expand Down Expand Up @@ -538,7 +540,8 @@ export function createKernelMenu(app: JupyterFrontEnd, menu: KernelMenu): void {
const restartGroup = [
CommandIDs.restartKernel,
CommandIDs.restartKernelAndClear,
CommandIDs.restartAndRunAll
CommandIDs.restartAndRunAll,
CommandIDs.restartAndRunToSelected
].map(command => {
return { command };
});
Expand Down Expand Up @@ -687,6 +690,21 @@ export function createRunMenu(app: JupyterFrontEnd, menu: RunMenu): void {
),
execute: Private.delegateExecute(app, menu.codeRunners, 'restartAndRunAll')
});
commands.addCommand(CommandIDs.restartAndRunToSelected, {
label: () => {
return `Restart Kernel and Run up to Selected Cell …`;
},
isEnabled: Private.delegateEnabled(
app,
menu.codeRunners,
'restartAndRunToSelected'
),
execute: Private.delegateExecute(
app,
menu.codeRunners,
'restartAndRunToSelected'
)
});

const runAllGroup = [CommandIDs.runAll, CommandIDs.restartAndRunAll].map(
command => {
Expand Down
6 changes: 6 additions & 0 deletions packages/mainmenu/src/run.ts
Expand Up @@ -79,5 +79,11 @@ export namespace IRunMenu {
* returns a promise of whether the action was performed.
*/
restartAndRunAll?: (widget: T) => Promise<boolean>;
/**
* A function to restart and run all the code hosted by the widget
* up to the currently selected cell, which returns a promise of whether
* the action was performed.
*/
restartAndRunToSelected?: (widget: T) => Promise<boolean>;
}
}
15 changes: 15 additions & 0 deletions packages/notebook-extension/src/index.ts
Expand Up @@ -2113,6 +2113,21 @@ function populateMenus(
}
return restarted;
});
},
restartAndRunToSelected: current => {
const { context, content } = current;
return context.session.restart().then(restarted => {
if (restarted) {
void NotebookActions.runAllAbove(content, context.session).then(
executed => {
if (executed) {
void NotebookActions.run(content, context.session);
}
}
);
}
return restarted;
});
}
} as IRunMenu.ICodeRunner<NotebookPanel>);

Expand Down

0 comments on commit bf9bfa8

Please sign in to comment.