Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Draft command #519

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ export class DebuggerHandler {
*
* @param widget The widget to update.
* @param connection The session connection.
* @param manuallyRun - Flag for run button function manually
*/
async update(
widget: DebuggerHandler.SessionWidget[DebuggerHandler.SessionType],
connection: Session.ISessionConnection
connection: Session.ISessionConnection,
manuallyRun?: boolean
): Promise<void> {
if (!connection) {
delete this._kernelChangedHandlers[widget.id];
Expand Down Expand Up @@ -143,8 +145,7 @@ export class DebuggerHandler {
}
connection.statusChanged.connect(statusChanged);
this._statusChangedHandlers[widget.id] = statusChanged;

return this._update(widget, connection);
return this._update(widget, connection, manuallyRun);
}

/**
Expand All @@ -153,10 +154,12 @@ export class DebuggerHandler {
*
* @param widget The widget to update.
* @param sessionContext The session context.
* @param manuallyRun - Flag for run button function manually
*/
async updateContext(
widget: DebuggerHandler.SessionWidget[DebuggerHandler.SessionType],
sessionContext: ISessionContext
sessionContext: ISessionContext,
manuallyRun?: boolean
): Promise<void> {
const connectionChanged = (): void => {
const { session: connection } = sessionContext;
Expand All @@ -173,18 +176,20 @@ export class DebuggerHandler {
this._contextKernelChangedHandlers[widget.id] = connectionChanged;
sessionContext.kernelChanged.connect(connectionChanged);

return this.update(widget, sessionContext.session);
return this.update(widget, sessionContext.session, manuallyRun);
}

/**
* Update a debug handler for the given widget.
*
* @param widget The widget to update.
* @param connection The session connection.
* @param manuallyRun - Flag for run button function manually
*/
private async _update(
async _update(
widget: DebuggerHandler.SessionWidget[DebuggerHandler.SessionType],
connection: Session.ISessionConnection
connection: Session.ISessionConnection,
manuallyRun?: boolean
): Promise<void> {
if (!this._service.model) {
return;
Expand Down Expand Up @@ -311,6 +316,9 @@ export class DebuggerHandler {
await this._service.restoreState(false);
addToolbarButton();

if (manuallyRun) {
await toggleDebugging();
}
// check the state of the debug session
if (!this._service.isStarted) {
removeHandlers();
Expand Down
34 changes: 32 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export namespace CommandIDs {
export const stepOut = 'debugger:stepOut';

export const inspectVariable = 'debugger:inspect-variable';

export const startDebug = 'debugger:start-debug';
}

/**
Expand Down Expand Up @@ -207,6 +209,26 @@ const notebooks: JupyterFrontEndPlugin<void> = {
notebookTracker: INotebookTracker,
labShell: ILabShell
) => {
app.commands.addCommand(CommandIDs.startDebug, {
label: 'StartDebug',
caption: 'Start Debug',
icon: stepOutIcon,
isEnabled: () => {
// @todo should be something similar like threadHasStopped
return true;
},
execute: async () => {
await updateCurrentWidget();
}
});

// @todo selector probably should be different, shortcut key is draft as well
app.commands.addKeyBinding({
command: CommandIDs.startDebug,
keys: ['Alt A'],
selector: 'div'
});

const handler = new DebuggerHandler({
type: 'notebook',
shell: app.shell,
Expand All @@ -216,14 +238,22 @@ const notebooks: JupyterFrontEndPlugin<void> = {
handler.disposeAll(service);
});
const updateHandlerAndCommands = async (
widget: NotebookPanel
widget: NotebookPanel,
manuallyRun?: boolean
): Promise<void> => {
const { sessionContext } = widget;
await sessionContext.ready;
await handler.updateContext(widget, sessionContext);
await handler.updateContext(widget, sessionContext, manuallyRun);
app.commands.notifyCommandChanged();
};

const updateCurrentWidget = async (): Promise<void> => {
if (labShell) {
const widget = notebookTracker.currentWidget;
await updateHandlerAndCommands(widget, true);
}
};

if (labShell) {
labShell.currentChanged.connect(async (_, update) => {
const widget = update.newValue;
Expand Down