Explorar o código

Model now owns Breakpoints, Variables and callstack models

Johan Mabille %!s(int64=5) %!d(string=hai) anos
pai
achega
53180f7f74

+ 4 - 2
src/breakpoints/index.ts

@@ -12,7 +12,7 @@ import { ILineInfo } from '../handlers/cell';
 export class Breakpoints extends Panel {
   constructor(options: Breakpoints.IOptions) {
     super();
-    this.model = new Breakpoints.Model([]);
+    this.model = options.model;
     this.addClass('jp-DebuggerBreakpoints');
     this.title.label = 'Breakpoints';
 
@@ -169,7 +169,9 @@ export namespace Breakpoints {
   /**
    * Instantiation options for `Breakpoints`;
    */
-  export interface IOptions extends Panel.IOptions {}
+  export interface IOptions extends Panel.IOptions {
+    model: Model;
+  }
 }
 
 export type SessionTypes = 'console' | 'notebook';

+ 5 - 3
src/callstack/index.ts

@@ -9,10 +9,10 @@ import { DebugProtocol } from 'vscode-debugprotocol';
 import { Signal, ISignal } from '@phosphor/signaling';
 
 export class Callstack extends Panel {
-  constructor(options: Callstack.IOptions = {}) {
+  constructor(options: Callstack.IOptions) {
     super();
 
-    this.model = new Callstack.IModel([]);
+    this.model = options.model;
     this.addClass('jp-DebuggerCallstack');
     this.title.label = 'Callstack';
 
@@ -135,5 +135,7 @@ export namespace Callstack {
     private _currentFrameChanged = new Signal<this, IFrame>(this);
   }
 
-  export interface IOptions extends Panel.IOptions {}
+  export interface IOptions extends Panel.IOptions {
+    model: IModel;
+  }
 }

+ 41 - 22
src/debugger.ts

@@ -1,18 +1,16 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import { CodeEditor } from '@jupyterlab/codeeditor';
+import { IClientSession } from '@jupyterlab/apputils';
 
-import { DebugService } from './service';
+import { CodeEditor } from '@jupyterlab/codeeditor';
 
-import { DebuggerEditors } from './editors';
+import { IDataConnector } from '@jupyterlab/coreutils';
 
-import { DebuggerSidebar } from './sidebar';
+import { IObservableString } from '@jupyterlab/observables';
 
 import { ReadonlyJSONValue } from '@phosphor/coreutils';
 
-import { IClientSession } from '@jupyterlab/apputils';
-
 import { IDisposable } from '@phosphor/disposable';
 
 import { Message } from '@phosphor/messaging';
@@ -21,11 +19,17 @@ import { ISignal, Signal } from '@phosphor/signaling';
 
 import { SplitPanel } from '@phosphor/widgets';
 
-import { IObservableString } from '@jupyterlab/observables';
+import { Breakpoints } from './breakpoints';
+
+import { Callstack } from './callstack';
+
+import { DebuggerEditors } from './editors';
+
+import { DebugService } from './service';
 
 import { IDebugger } from './tokens';
 
-import { IDataConnector } from '@jupyterlab/coreutils';
+import { Variables } from './variables';
 
 export class Debugger extends SplitPanel {
   constructor(options: Debugger.IOptions) {
@@ -35,10 +39,7 @@ export class Debugger extends SplitPanel {
 
     this.model = new Debugger.Model(options);
 
-    this.sidebar = new DebuggerSidebar();
-
-    this.model.sidebar = this.sidebar;
-
+    this.sidebar = new Debugger.Sidebar(this.model);
     this.service = new DebugService(this.model);
 
     const { editorFactory } = options;
@@ -50,7 +51,7 @@ export class Debugger extends SplitPanel {
 
   readonly editors: DebuggerEditors;
   readonly model: Debugger.Model;
-  readonly sidebar: DebuggerSidebar;
+  readonly sidebar: Debugger.Sidebar;
   readonly service: DebugService;
 
   dispose(): void {
@@ -79,13 +80,40 @@ export namespace Debugger {
     session?: IClientSession;
   }
 
+  export class Sidebar extends SplitPanel {
+    constructor(model: Model) {
+      super();
+      this.orientation = 'vertical';
+      this.addClass('jp-DebuggerSidebar');
+
+      this.variables = new Variables({ model: model.variablesModel });
+      this.callstack = new Callstack({ model: model.callstackModel });
+      this.breakpoints = new Breakpoints({ model: model.breakpointsModel });
+
+      this.addWidget(this.variables);
+      this.addWidget(this.callstack);
+      this.addWidget(this.breakpoints);
+    }
+
+    readonly variables: Variables;
+    readonly callstack: Callstack;
+    readonly breakpoints: Breakpoints;
+  }
+
   export class Model implements IDisposable {
     constructor(options: Debugger.Model.IOptions) {
+      this.breakpointsModel = new Breakpoints.Model([]);
+      this.callstackModel = new Callstack.IModel([]);
+      this.variablesModel = new Variables.IModel([]);
       this.connector = options.connector || null;
       this.id = options.id;
       void this._populate();
     }
 
+    readonly breakpointsModel: Breakpoints.Model;
+    readonly callstackModel: Callstack.IModel;
+    readonly variablesModel: Variables.IModel;
+
     readonly connector: IDataConnector<ReadonlyJSONValue> | null;
     readonly id: string;
 
@@ -101,14 +129,6 @@ export namespace Debugger {
       this._modeChanged.emit(mode);
     }
 
-    get sidebar() {
-      return this._sidebar;
-    }
-
-    set sidebar(sidebar: DebuggerSidebar) {
-      this._sidebar = sidebar;
-    }
-
     get modeChanged(): ISignal<this, IDebugger.Mode> {
       return this._modeChanged;
     }
@@ -146,7 +166,6 @@ export namespace Debugger {
     }
 
     private _codeValue: IObservableString;
-    private _sidebar: DebuggerSidebar;
     private _isDisposed = false;
     private _mode: IDebugger.Mode;
     private _modeChanged = new Signal<this, IDebugger.Mode>(this);

+ 1 - 1
src/handlers/console.ts

@@ -19,7 +19,7 @@ export class DebuggerConsoleHandler implements IDisposable {
   constructor(options: DebuggerConsoleHandler.IOptions) {
     this.debuggerModel = options.debuggerModel;
     this.consoleTracker = options.tracker;
-    this.breakpoints = this.debuggerModel.sidebar.breakpoints.model;
+    this.breakpoints = this.debuggerModel.breakpointsModel;
     this.cellManager = new CellManager({
       activeCell: this.consoleTracker.currentWidget.console.promptCell,
       breakpointsModel: this.breakpoints,

+ 1 - 1
src/handlers/notebook.ts

@@ -22,7 +22,7 @@ export class DebuggerNotebookHandler implements IDisposable {
     this.debuggerModel = options.debuggerModel;
     this.debuggerService = options.debuggerService;
     this.notebookTracker = options.tracker;
-    this.breakpoints = this.debuggerModel.sidebar.breakpoints.model;
+    this.breakpoints = this.debuggerModel.breakpointsModel;
     this.notebookTracker.activeCellChanged.connect(this.onNewCell, this);
     this.cellManager = new CellManager({
       breakpointsModel: this.breakpoints,

+ 13 - 7
src/service.ts

@@ -112,7 +112,15 @@ export class DebugService implements IDebugger.IService {
 
   // this will change for after execute cell
   async launch(code: string): Promise<void> {
+    let threadId: number = 1;
     this.frames = [];
+    this.session.eventMessage.connect((_, event: IDebugger.ISession.Event) => {
+      const eventName = event.event;
+      if (eventName === 'thread') {
+        const msg = event as DebugProtocol.ThreadEvent;
+        threadId = msg.body.threadId;
+      }
+    });
 
     const breakpoints: DebugProtocol.SourceBreakpoint[] = this.getBreakpoints();
     const dumpedCell = await this.session.sendRequest('dumpCell', {
@@ -139,24 +147,22 @@ export class DebugService implements IDebugger.IService {
         scopes: values
       });
       if (index === 0) {
-        this._model.sidebar.variables.model.scopes = values;
+        this._model.variablesModel.scopes = values;
         this._model.currentLineChanged.emit(frame.line);
       }
     });
 
     if (stackFrames) {
-      this._model.sidebar.callstack.model.frames = stackFrames;
+      this._model.callstackModel.frames = stackFrames;
     }
 
-    this._model.sidebar.callstack.model.currentFrameChanged.connect(
-      this.onChangeFrame
-    );
+    this._model.callstackModel.currentFrameChanged.connect(this.onChangeFrame);
   };
 
   onChangeFrame = (_: Callstack.IModel, update: Callstack.IFrame) => {
     const frame = this.frames.find(ele => ele.id === update.id);
     if (frame && frame.scopes) {
-      this._model.sidebar.variables.model.scopes = frame.scopes;
+      this._model.variablesModel.scopes = frame.scopes;
     }
   };
 
@@ -194,7 +200,7 @@ export class DebugService implements IDebugger.IService {
   };
 
   getBreakpoints = (): DebugProtocol.SourceBreakpoint[] => {
-    return this._model.sidebar.breakpoints.model.breakpoints.map(breakpoint => {
+    return this._model.breakpointsModel.breakpoints.map(breakpoint => {
       return {
         line: breakpoint.line
       };

+ 0 - 30
src/sidebar.ts

@@ -1,30 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-import { SplitPanel } from '@phosphor/widgets';
-
-import { Breakpoints } from './breakpoints';
-
-import { Callstack } from './callstack';
-
-import { Variables } from './variables';
-
-export class DebuggerSidebar extends SplitPanel {
-  constructor() {
-    super();
-    this.orientation = 'vertical';
-    this.addClass('jp-DebuggerSidebar');
-
-    this.variables = new Variables();
-    this.callstack = new Callstack();
-    this.breakpoints = new Breakpoints({});
-
-    this.addWidget(this.variables);
-    this.addWidget(this.callstack);
-    this.addWidget(this.breakpoints);
-  }
-
-  readonly variables: Variables;
-  readonly callstack: Callstack;
-  readonly breakpoints: Breakpoints;
-}

+ 5 - 3
src/variables/index.ts

@@ -10,10 +10,10 @@ import { Signal, ISignal } from '@phosphor/signaling';
 import { DebugProtocol } from 'vscode-debugprotocol';
 
 export class Variables extends Panel {
-  constructor(options: Variables.IOptions = {}) {
+  constructor(options: Variables.IOptions) {
     super();
 
-    this.model = new Variables.IModel([]);
+    this.model = options.model;
     this.addClass('jp-DebuggerVariables');
     this.title.label = 'Variables';
 
@@ -117,5 +117,7 @@ export namespace Variables {
     private _scopesChanged = new Signal<this, IScope[]>(this);
   }
 
-  export interface IOptions extends Panel.IOptions {}
+  export interface IOptions extends Panel.IOptions {
+    model: IModel;
+  }
 }