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

Commit

Permalink
Merge pull request #126 from JohanMabille/auto_start
Browse files Browse the repository at this point in the history
Automagically starts the debugger if the kernel supports it
  • Loading branch information
jtpio authored Oct 30, 2019
2 parents 15fc5f1 + e573acc commit d1c0d9c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/breakpoints/body.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import React, { useEffect, useState } from 'react';
import { Breakpoints } from '.';
import { ReactWidget } from '@jupyterlab/apputils';
import { ArrayExt } from '@phosphor/algorithm';
import { ISignal } from '@phosphor/signaling';
import React, { useEffect, useState } from 'react';
import { Breakpoints } from '.';

export class Body extends ReactWidget {
constructor(model: Breakpoints.Model) {
Expand Down
6 changes: 3 additions & 3 deletions src/breakpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import { Toolbar, ToolbarButton } from '@jupyterlab/apputils';

import { Widget, Panel, PanelLayout } from '@phosphor/widgets';
import { DebugProtocol } from 'vscode-debugprotocol';
import { Body } from './body';
import { Signal } from '@phosphor/signaling';
import { Panel, PanelLayout, Widget } from '@phosphor/widgets';
import { DebugProtocol } from 'vscode-debugprotocol';
import { ILineInfo } from '../handlers/cell';
import { Body } from './body';

export class Breakpoints extends Panel {
constructor(options: Breakpoints.IOptions) {
Expand Down
6 changes: 3 additions & 3 deletions src/callstack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import { Toolbar, ToolbarButton } from '@jupyterlab/apputils';

import { Widget, Panel, PanelLayout } from '@phosphor/widgets';
import { Body } from './body';
import { ISignal, Signal } from '@phosphor/signaling';
import { Panel, PanelLayout, Widget } from '@phosphor/widgets';
import { DebugProtocol } from 'vscode-debugprotocol';
import { Signal, ISignal } from '@phosphor/signaling';
import { Body } from './body';

export class Callstack extends Panel {
constructor(options: Callstack.IOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/editors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

import { CodeEditorWrapper, CodeEditor } from '@jupyterlab/codeeditor';
import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';

import { ISignal, Signal } from '@phosphor/signaling';

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/console.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { IConsoleTracker, CodeConsole } from '@jupyterlab/console';
import { CodeConsole, IConsoleTracker } from '@jupyterlab/console';

import { CellManager } from '../handlers/cell';

Expand All @@ -11,9 +11,9 @@ import { Breakpoints } from '../breakpoints';

import { IDebugger } from '../tokens';

import { Debugger } from '../debugger';
import { IDisposable } from '@phosphor/disposable';
import { Signal } from '@phosphor/signaling';
import { Debugger } from '../debugger';

export class DebuggerConsoleHandler implements IDisposable {
constructor(options: DebuggerConsoleHandler.IOptions) {
Expand Down
31 changes: 7 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ async function setDebugSession(
debug.session.client = client;
}
await debug.session.restoreState();
if (debug.canStart()) {
await debug.start();
}
app.commands.notifyCommandChanged();
}

Expand Down Expand Up @@ -243,7 +246,7 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
let widget: MainAreaWidget<Debugger>;

commands.addCommand(CommandIDs.mount, {
execute: args => {
execute: async args => {
if (!widget) {
return;
}
Expand Down Expand Up @@ -277,28 +280,10 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
sidebar.id = 'jp-debugger-sidebar';
sidebar.title.label = 'Environment';
shell.add(sidebar, 'right', { activate: false });
}
});

commands.addCommand(CommandIDs.stop, {
label: 'Stop',
isEnabled: () => {
return service.isStarted();
},
execute: async () => {
await service.session.stop();
commands.notifyCommandChanged();
}
});

commands.addCommand(CommandIDs.start, {
label: 'Start',
isEnabled: () => {
return widget && service.canStart();
},
execute: async () => {
await service.session.start();
commands.notifyCommandChanged();
if (service.canStart()) {
await service.start();
}
}
});

Expand Down Expand Up @@ -393,8 +378,6 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
const category = 'Debugger';
palette.addItem({ command: CommandIDs.changeMode, category });
palette.addItem({ command: CommandIDs.create, category });
palette.addItem({ command: CommandIDs.start, category });
palette.addItem({ command: CommandIDs.stop, category });
palette.addItem({ command: CommandIDs.debugContinue, category });
palette.addItem({ command: CommandIDs.next, category });
palette.addItem({ command: CommandIDs.stepIn, category });
Expand Down
26 changes: 22 additions & 4 deletions src/service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { IClientSession } from '@jupyterlab/apputils';

import { ISignal, Signal } from '@phosphor/signaling';

import { DebugProtocol } from 'vscode-debugprotocol';
Expand Down Expand Up @@ -77,10 +82,6 @@ export class DebugService implements IDebugger {
this._sessionChanged.emit(session);
}

canStart(): boolean {
return this._session !== null && !this._session.isStarted;
}

isStarted(): boolean {
return this._session !== null && this._session.isStarted;
}
Expand All @@ -89,6 +90,20 @@ export class DebugService implements IDebugger {
return this._threadStopped.has(this.currentThread());
}

canStart(): boolean {
return (
this._model !== null && this._session !== null && !this._session.isStarted
);
}

async start(): Promise<void> {
await this.session.start();
}

async stop(): Promise<void> {
await this.session.stop();
}

async continue(): Promise<void> {
try {
await this.session.sendRequest('continue', {
Expand Down Expand Up @@ -204,6 +219,9 @@ export class DebugService implements IDebugger {
breakpoints: DebugProtocol.SourceBreakpoint[],
path: string
) => {
// Workaround: this should not be called before the session has started
const client = this.session.client as IClientSession;
await client.ready;
await this.session.sendRequest('setBreakpoints', {
breakpoints: breakpoints,
source: { path },
Expand Down
12 changes: 12 additions & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export interface IDebugger {
*/
isThreadStopped(): boolean;

/**
* Starts a debugger.
* Precondition: canStart() && !isStarted()
*/
start(): Promise<void>;

/**
* Stops the debugger.
* Precondition: isStarted()
*/
stop(): Promise<void>;

/**
* Continues the execution of the current thread.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/variables/body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import { Variables } from '../index';

import { ObjectInspector, ObjectLabel, ITheme } from 'react-inspector';
import { ITheme, ObjectInspector, ObjectLabel } from 'react-inspector';

import { ReactWidget } from '@jupyterlab/apputils';

import React, { useState, useEffect } from 'react';
import { ArrayExt } from '@phosphor/algorithm';
import React, { useEffect, useState } from 'react';

export class Body extends ReactWidget {
constructor(model: Variables.Model) {
Expand Down
4 changes: 2 additions & 2 deletions src/variables/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Panel, Widget, PanelLayout } from '@phosphor/widgets';
import { Panel, PanelLayout, Widget } from '@phosphor/widgets';

import { Body } from './body';

import { Signal, ISignal } from '@phosphor/signaling';
import { ISignal, Signal } from '@phosphor/signaling';

import { DebugProtocol } from 'vscode-debugprotocol';

Expand Down

0 comments on commit d1c0d9c

Please sign in to comment.