diff --git a/src/handlers/console.ts b/src/handlers/console.ts index bb613d65..af05dd72 100644 --- a/src/handlers/console.ts +++ b/src/handlers/console.ts @@ -39,6 +39,7 @@ export class ConsoleHandler implements IDisposable { this.isDisposed = true; this.editorHandler.dispose(); Signal.clearData(this); + this.consolePanel.node.setAttribute('data-jp-debugger', 'false'); } protected promptCellCreated(sender: CodeConsole, update: CodeCell) { diff --git a/src/handlers/notebook.ts b/src/handlers/notebook.ts index e896d852..de0453d4 100644 --- a/src/handlers/notebook.ts +++ b/src/handlers/notebook.ts @@ -36,6 +36,7 @@ export class NotebookHandler implements IDisposable { this.cleanAllCells(); this._cellMap.values().forEach(handler => handler.dispose()); Signal.clearData(this); + this.notebookPanel.node.setAttribute('data-jp-debugger', 'false'); } protected addEditorHandler(cell: Cell) { diff --git a/src/handlers/tracker.ts b/src/handlers/tracker.ts index 27e9a61e..01e449ba 100644 --- a/src/handlers/tracker.ts +++ b/src/handlers/tracker.ts @@ -58,14 +58,19 @@ export class TrackerHandler implements IDisposable { this.consoleTracker = options.consoleTracker; this.editorTracker = options.editorTracker; - this.readOnlyEditorFactory = new ReadOnlyEditorFactory({ - editorServices: options.editorServices - }); - - this.readOnlyEditorTracker = new WidgetTracker< - MainAreaWidget - >({ - namespace: '@jupyterlab/debugger' + this.debuggerService.modelChanged.connect(() => { + const debuggerModel = this.debuggerService.model as Debugger.Model; + if (debuggerModel) { + debuggerModel.callstackModel.currentFrameChanged.connect( + this.onCurrentFrameChanged, + this + ); + + debuggerModel.breakpointsModel.clicked.connect((_, breakpoint) => { + const debugSessionPath = this.debuggerService.session.client.path; + this.find(debugSessionPath, breakpoint.source.path); + }); + } }); this.onModelChanged(); @@ -257,7 +262,7 @@ export class TrackerHandler implements IDisposable { protected findInReadOnlyEditors(_: string, source: string) { let editors: CodeEditor.IEditor[] = []; - this.readOnlyEditorTracker.forEach(widget => { + this.readOnlyEditorTracker?.forEach(widget => { const editor = widget.content?.editor; if (!editor) { return; diff --git a/src/index.ts b/src/index.ts index 29712846..6170043f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -93,10 +93,11 @@ function updateToolbar( handler: any ): void { const isConsolePanel = widget instanceof ConsolePanel; - const checkState = () => - debug.session.client.name === debug.session.currentStateClient; - widget.node.setAttribute('data-debugger-on', checkState().toString()); + widget.node.setAttribute( + 'data-debugger-on', + debug.session.statesClient(debug.session.client.name, true).toString() + ); const getToolbar = (): Toolbar => { if (isConsolePanel) { @@ -117,16 +118,10 @@ function updateToolbar( className: 'jp-debugger-switch-button', iconClassName: 'jp-toggle-switch', onClick: async () => { - if (debug.model == null && !checkState()) { - await commands.execute(CommandIDs.create); - handler.update(debug, widget); - } - if (!checkState()) { - debug.session.currentStateClient = debug.session.client.name; - } else { - debug.session.currentStateClient = null; - } - widget.node.setAttribute('data-debugger-on', checkState().toString()); + widget.node.setAttribute( + 'data-debugger-on', + debug.session.statesClient(debug.session.client.name).toString() + ); }, tooltip: 'Enable / Disable Debugger' }) @@ -155,11 +150,13 @@ class DebuggerHandler< return; } + widget.node.setAttribute('data-jp-debugger', 'true'); + const handler = new this.builder({ debuggerService: debug, widget }); - widget.node.setAttribute('data-jp-debugger', 'true'); + this.handlers[widget.id] = handler; widget.disposed.connect(() => { diff --git a/src/service.ts b/src/service.ts index 2f951283..e2c88962 100644 --- a/src/service.ts +++ b/src/service.ts @@ -134,8 +134,8 @@ export class DebugService implements IDebugger, IDisposable { /** * Checking lifecycle state of debugger in current widget */ - isActualKernelState(): boolean { - return this.session.client.name === this.session.currentStateClient; + isLifeCycleOnKernelState(): boolean { + return this.session.statesClient(this.session.client.name, true); } /** @@ -239,7 +239,7 @@ export class DebugService implements IDebugger, IDisposable { await this.start(); } - if (this.isActualKernelState()) { + if (this.isLifeCycleOnKernelState()) { if (stoppedThreads.size !== 0) { await this.getAllFrames(); } else { diff --git a/src/session.ts b/src/session.ts index b564f948..c6b43a55 100644 --- a/src/session.ts +++ b/src/session.ts @@ -66,12 +66,16 @@ export class DebugSession implements IDebugger.ISession { } } - get currentStateClient() { - return this._statesClient; - } - - set currentStateClient(state: string) { - this._statesClient = state; + statesClient(clientName: string, onlyCheck?: boolean) { + if (onlyCheck) { + return this._statesClient.has(clientName); + } + if (this._statesClient.delete(clientName)) { + return false; + } else { + this._statesClient.add(clientName); + return true; + } } /** @@ -224,7 +228,7 @@ export class DebugSession implements IDebugger.ISession { IDebugger.ISession.Event >(this); private _seq: number = 0; - private _statesClient: string; + private _statesClient: Set = new Set(); } /** diff --git a/src/tokens.ts b/src/tokens.ts index a52b0cbe..cea3f419 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -144,11 +144,6 @@ export namespace IDebugger { */ client: IClientSession | Session.ISession; - /** - * The current enabled debugger of client. - */ - currentStateClient: string; - /** * The kernel info for the debug session. */ @@ -167,6 +162,13 @@ export namespace IDebugger { IDebugger.ISession.Event >; + /** + * Add/Delete client to Set of lifecycle debugger. + * @param clientName name of client. + * @param onlyCheck set true if only want to check if client exist in Set. + */ + statesClient(clientName: string, onlyCheck?: boolean): boolean; + /** * Start a new debug session. */