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 ability to restart kernel and run to current cell #6821

Closed
wants to merge 1 commit into from
Closed
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
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