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

Commit

Permalink
implementing functionalyt of lifecycle debugger[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
KsavinN committed Dec 5, 2019
1 parent 1788de6 commit 290e200
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
31 changes: 23 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { Debugger } from './debugger';

import { ConsoleHandler } from './handlers/console';

import { CommandRegistry } from '@phosphor/commands';

import { FileHandler } from './handlers/file';

import { NotebookHandler } from './handlers/notebook';
Expand Down Expand Up @@ -93,12 +95,16 @@ async function setDebugSession(
}

function updateToolbar(
widget: NotebookPanel | ConsolePanel | FileEditor
widget: NotebookPanel | ConsolePanel | FileEditor,
debug: IDebugger,
commands: CommandRegistry
): void {
console.log({ widget });

const isConsolePanel = widget instanceof ConsolePanel;
let toogleState = false;
const checkState = () =>
debug.session.client.name === debug.session.currentStateClient;

widget.node.setAttribute('data-debugger-on', checkState().toString());

const getToolbar = (): Toolbar => {
if (isConsolePanel) {
return (
Expand All @@ -118,8 +124,15 @@ function updateToolbar(
className: 'jp-debugger-switch-button',
iconClassName: 'jp-toggle-switch',
onClick: () => {
toogleState = !toogleState;
widget.node.setAttribute('data-debugger-on', toogleState.toString());
if (debug.model == null && !checkState()) {
void commands.execute(CommandIDs.create);
}
if (!checkState()) {
debug.session.currentStateClient = debug.session.client.name;
} else {
debug.session.currentStateClient = null;
}
widget.node.setAttribute('data-debugger-on', checkState().toString());
},
tooltip: 'Enable / Disable Debugger'
})
Expand Down Expand Up @@ -147,13 +160,14 @@ class DebuggerHandler<
if (!debug.model || this.handlers[widget.id] || !debug.isDebuggingEnabled) {
return;
}
updateToolbar(widget);

const handler = new this.builder({
debuggerService: debug,
widget
});
widget.node.setAttribute('data-jp-debugger', 'true');
this.handlers[widget.id] = handler;

widget.disposed.connect(() => {
handler.dispose();
delete this.handlers[widget.id];
Expand Down Expand Up @@ -255,13 +269,13 @@ const notebooks: JupyterFrontEndPlugin<void> = {
requires: [IDebugger, ILabShell],
activate: (app: JupyterFrontEnd, debug: IDebugger, labShell: ILabShell) => {
const handler = new DebuggerHandler<NotebookHandler>(NotebookHandler);

labShell.activeChanged.connect(async (_, update) => {
const widget = update.newValue;
if (!(widget instanceof NotebookPanel)) {
return;
}
await setDebugSession(app, debug, widget.session);
updateToolbar(widget, debug, app.commands);
handler.update(debug, widget);
});
}
Expand Down Expand Up @@ -482,6 +496,7 @@ const main: JupyterFrontEndPlugin<IDebugger> = {

if (tracker.currentWidget) {
widget = tracker.currentWidget;
return;
} else {
widget = new MainAreaWidget({
content: new Debugger({
Expand Down
19 changes: 14 additions & 5 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ export class DebugService implements IDebugger, IDisposable {
Signal.clearData(this);
}

/**
* Checking lifecycle state of debugger in current widget
*/
isActualKernelState(): boolean {
return this.session.client.name === this.session.currentStateClient;
}

/**
* Computes an id based on the given code.
*/
Expand Down Expand Up @@ -251,11 +258,13 @@ export class DebugService implements IDebugger, IDisposable {
await this.start();
}

if (stoppedThreads.size !== 0) {
await this.getAllFrames();
} else {
this.clearModel();
this.clearSignals();
if (this.isActualKernelState()) {
if (stoppedThreads.size !== 0) {
await this.getAllFrames();
} else {
this.clearModel();
this.clearSignals();
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ export class DebugSession implements IDebugger.ISession {
this._client.iopubMessage.disconnect(this._handleEvent, this);
}

this._client = client;

if (client) {
this._client = client;
this._client.iopubMessage.connect(this._handleEvent, this);
}
}

get currentStateClient() {
return this._statesClient;
}

set currentStateClient(state: string) {
this._statesClient = state;
}

/**
* Return the kernel info for the debug session.
*/
Expand Down Expand Up @@ -217,6 +224,7 @@ export class DebugSession implements IDebugger.ISession {
IDebugger.ISession.Event
>(this);
private _seq: number = 0;
private _statesClient: string;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export namespace IDebugger {
*/
client: IClientSession | Session.ISession;

currentStateClient: string;

/**
* The kernel info for the debug session.
*/
Expand Down

0 comments on commit 290e200

Please sign in to comment.