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

Commit

Permalink
change currentState to StatesClient as Set
Browse files Browse the repository at this point in the history
  • Loading branch information
KsavinN committed Dec 10, 2019
1 parent b185ace commit 0ac1955
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/handlers/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/handlers/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 14 additions & 9 deletions src/handlers/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeEditorWrapper>
>({
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();
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 11 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'
})
Expand Down Expand Up @@ -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(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 11 additions & 7 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down Expand Up @@ -224,7 +228,7 @@ export class DebugSession implements IDebugger.ISession {
IDebugger.ISession.Event
>(this);
private _seq: number = 0;
private _statesClient: string;
private _statesClient: Set<string> = new Set();
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand Down

0 comments on commit 0ac1955

Please sign in to comment.