Преглед изворни кода

Update more token definitions

Afshin T. Darian пре 4 година
родитељ
комит
32aaa668e7

+ 0 - 19
src/handler.ts

@@ -81,24 +81,6 @@ export class DebuggerHandler {
     this._service = options.service;
   }
 
-  /**
-   * Dispose all the handlers.
-   *
-   * @param debug The debug service.
-   */
-  disposeAll(debug: IDebugger): void {
-    const handlerIds = Object.keys(this._handlers);
-    if (handlerIds.length === 0) {
-      return;
-    }
-    debug.session.dispose();
-    debug.session = null;
-    handlerIds.forEach(id => {
-      this._handlers[id].dispose();
-    });
-    this._handlers = {};
-  }
-
   /**
    * Update a debug handler for the given widget, and
    * handle kernel changed events.
@@ -323,7 +305,6 @@ export class DebuggerHandler {
 
     // listen to the disposed signals
     widget.disposed.connect(removeHandlers);
-    this._service.model.disposed.connect(removeHandlers);
   }
 
   private _type: DebuggerHandler.SessionType;

+ 19 - 40
src/handlers/editor.ts

@@ -15,12 +15,8 @@ import { Signal } from '@lumino/signaling';
 
 import { Editor } from 'codemirror';
 
-import { BreakpointsModel } from '../panels/breakpoints/model';
-
 import { IDebugger } from '../tokens';
 
-import { Debugger } from '../debugger';
-
 /**
  * The class name added to the current line.
  */
@@ -46,18 +42,32 @@ export class EditorHandler implements IDisposable {
     this._debuggerService = options.debuggerService;
     this._editor = options.editor;
 
-    this._onModelChanged();
-    this._debuggerService.modelChanged.connect(this._onModelChanged, this);
-
     this._editorMonitor = new ActivityMonitor({
       signal: this._editor.model.value.changed,
       timeout: EDITOR_CHANGED_TIMEOUT
     });
-
     this._editorMonitor.activityStopped.connect(() => {
       this._sendEditorBreakpoints();
     }, this);
 
+    this._debuggerService.model.breakpoints.changed.connect(async () => {
+      if (!this._editor || this._editor.isDisposed) {
+        return;
+      }
+      this._addBreakpointsToEditor();
+    });
+
+    this._debuggerService.model.breakpoints.restored.connect(async () => {
+      if (!this._editor || this._editor.isDisposed) {
+        return;
+      }
+      this._addBreakpointsToEditor();
+    });
+
+    this._debuggerService.model.callstack.currentFrameChanged.connect(() => {
+      EditorHandler.clearHighlight(this._editor);
+    });
+
     this._setupEditor();
   }
 
@@ -79,35 +89,6 @@ export class EditorHandler implements IDisposable {
     Signal.clearData(this);
   }
 
-  /**
-   * Handle when the debug model changes.
-   */
-  private _onModelChanged(): void {
-    this._debuggerModel = this._debuggerService.model as Debugger.Model;
-    if (!this._debuggerModel) {
-      return;
-    }
-    this._breakpointsModel = this._debuggerModel.breakpoints;
-
-    this._debuggerModel.callstack.currentFrameChanged.connect(() => {
-      EditorHandler.clearHighlight(this._editor);
-    });
-
-    this._breakpointsModel.changed.connect(async () => {
-      if (!this._editor || this._editor.isDisposed) {
-        return;
-      }
-      this._addBreakpointsToEditor();
-    });
-
-    this._breakpointsModel.restored.connect(async () => {
-      if (!this._editor || this._editor.isDisposed) {
-        return;
-      }
-      this._addBreakpointsToEditor();
-    });
-  }
-
   /**
    * Setup the editor.
    */
@@ -236,7 +217,7 @@ export class EditorHandler implements IDisposable {
    */
   private _getBreakpoints(): IDebugger.IBreakpoint[] {
     const code = this._editor.model.value.text;
-    return this._debuggerModel.breakpoints.getBreakpoints(
+    return this._debuggerService.model.breakpoints.getBreakpoints(
       this._path ?? this._debuggerService.getCodeId(code)
     );
   }
@@ -244,8 +225,6 @@ export class EditorHandler implements IDisposable {
   private _id: string;
   private _path: string;
   private _editor: CodeEditor.IEditor;
-  private _debuggerModel: Debugger.Model;
-  private _breakpointsModel: BreakpointsModel;
   private _debuggerService: IDebugger;
   private _editorMonitor: ActivityMonitor<
     IObservableString,

+ 2 - 2
src/handlers/notebook.ts

@@ -11,10 +11,10 @@ import { IDisposable } from '@lumino/disposable';
 
 import { Signal } from '@lumino/signaling';
 
-import { EditorHandler } from './editor';
-
 import { IDebugger } from '../tokens';
 
+import { EditorHandler } from './editor';
+
 /**
  * A handler for notebooks.
  */

+ 16 - 29
src/handlers/tracker.ts

@@ -41,35 +41,6 @@ export class TrackerHandler implements IDisposable {
     });
 
     this._editorFinder = options.editorFinder;
-    this._onModelChanged();
-    this._debuggerService.modelChanged.connect(this._onModelChanged, this);
-  }
-
-  /**
-   * Whether the handler is disposed.
-   */
-  isDisposed: boolean;
-
-  /**
-   * Dispose the handler.
-   */
-  dispose(): void {
-    if (this.isDisposed) {
-      return;
-    }
-    this.isDisposed = true;
-    Signal.clearData(this);
-  }
-
-  /**
-   * Handle when the debug model changes.
-   */
-  private _onModelChanged(): void {
-    this._debuggerModel = this._debuggerService.model as Debugger.Model;
-    if (!this._debuggerModel) {
-      return;
-    }
-
     this._debuggerModel.callstack.currentFrameChanged.connect(
       this._onCurrentFrameChanged,
       this
@@ -90,6 +61,22 @@ export class TrackerHandler implements IDisposable {
     });
   }
 
+  /**
+   * Whether the handler is disposed.
+   */
+  isDisposed: boolean;
+
+  /**
+   * Dispose the handler.
+   */
+  dispose(): void {
+    if (this.isDisposed) {
+      return;
+    }
+    this.isDisposed = true;
+    Signal.clearData(this);
+  }
+
   /**
    * Handle a current frame changed event.
    *

+ 4 - 13
src/index.ts

@@ -85,9 +85,6 @@ const consoles: JupyterFrontEndPlugin<void> = {
       shell: app.shell,
       service: debug
     });
-    debug.model.disposed.connect(() => {
-      handler.disposeAll(debug);
-    });
 
     const updateHandlerAndCommands = async (
       widget: ConsolePanel
@@ -134,9 +131,6 @@ const files: JupyterFrontEndPlugin<void> = {
       shell: app.shell,
       service: debug
     });
-    debug.model.disposed.connect(() => {
-      handler.disposeAll(debug);
-    });
 
     const activeSessions: {
       [id: string]: Session.ISessionConnection;
@@ -206,9 +200,6 @@ const notebooks: JupyterFrontEndPlugin<void> = {
       shell: app.shell,
       service
     });
-    service.model.disposed.connect(() => {
-      handler.disposeAll(service);
-    });
     const updateHandlerAndCommands = async (
       widget: NotebookPanel
     ): Promise<void> => {
@@ -289,10 +280,10 @@ const configuration: JupyterFrontEndPlugin<IDebugger.IConfig> = {
 };
 
 /**
- * A plugin that tracks editors, console and file editors used for debugging.
+ * A plugin that provides source/editor functionality for debugging.
  */
-const finder: JupyterFrontEndPlugin<IDebugger.ISources> = {
-  id: '@jupyterlab/debugger:editor-finder',
+const sources: JupyterFrontEndPlugin<IDebugger.ISources> = {
+  id: '@jupyterlab/debugger:sources',
   autoStart: true,
   provides: IDebuggerSources,
   requires: [IDebuggerConfig, IEditorServices],
@@ -567,7 +558,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
   tracker,
   variables,
   main,
-  finder,
+  sources,
   configuration
 ];
 

+ 1 - 1
src/model.ts

@@ -16,7 +16,7 @@ import { VariablesModel } from './panels/variables/model';
 /**
  * A model for a debugger.
  */
-export class DebuggerModel implements IDebugger.IModel {
+export class DebuggerModel {
   /**
    * Instantiate a new DebuggerModel
    */

+ 4 - 0
src/panels/breakpoints/index.ts

@@ -3,6 +3,8 @@
 
 import { ToolbarButton } from '@jupyterlab/apputils';
 
+import { Signal } from '@lumino/signaling';
+
 import { Panel } from '@lumino/widgets';
 
 import { closeAllIcon } from '../../icons';
@@ -47,6 +49,8 @@ export class Breakpoints extends Panel {
 
     this.addClass('jp-DebuggerBreakpoints');
   }
+
+  readonly clicked = new Signal<this, IDebugger.IBreakpoint>(this);
 }
 
 /**

+ 1 - 1
src/panels/breakpoints/model.ts

@@ -28,7 +28,7 @@ export class BreakpointsModel implements IDisposable {
   /**
    * Signal emitted when the breakpoints are restored.
    */
-  get restored(): Signal<this, void> {
+  get restored(): ISignal<this, void> {
     return this._restored;
   }
 

+ 1 - 1
src/panels/sources/model.ts

@@ -23,7 +23,7 @@ export class SourcesModel {
   /**
    * Signal emitted when the current frame changes.
    */
-  currentFrameChanged: ISignal<CallstackModel, CallstackModel.IFrame>;
+  readonly currentFrameChanged: ISignal<CallstackModel, CallstackModel.IFrame>;
 
   /**
    * Signal emitted when a source should be open in the main area.

+ 1 - 19
src/service.ts

@@ -97,16 +97,6 @@ export class DebuggerService implements IDebugger, IDisposable {
     return this._model;
   }
 
-  /**
-   * Sets the debugger model to the given parameter.
-   *
-   * @param model - The new debugger model.
-   */
-  set model(model: IDebugger.IModel) {
-    this._model = model as Debugger.Model;
-    this._modelChanged.emit(model);
-  }
-
   /**
    * Signal emitted upon session changed.
    */
@@ -114,13 +104,6 @@ export class DebuggerService implements IDebugger, IDisposable {
     return this._sessionChanged;
   }
 
-  /**
-   * Signal emitted upon model changed.
-   */
-  get modelChanged(): ISignal<IDebugger, IDebugger.IModel> {
-    return this._modelChanged;
-  }
-
   /**
    * Signal emitted for debug event messages.
    */
@@ -659,8 +642,7 @@ export class DebuggerService implements IDebugger, IDisposable {
   private _editorFinder: IDebugger.ISources | null;
   private _eventMessage = new Signal<IDebugger, IDebugger.ISession.Event>(this);
   private _isDisposed = false;
-  private _model: Debugger.Model;
-  private _modelChanged = new Signal<IDebugger, IDebugger.IModel>(this);
+  private _model: IDebugger.IModel;
   private _session: IDebugger.ISession;
   private _sessionChanged = new Signal<IDebugger, IDebugger.ISession>(this);
   private _specsManager: KernelSpec.IManager;

+ 120 - 11
src/tokens.ts

@@ -13,6 +13,12 @@ import { ISignal } from '@lumino/signaling';
 
 import { DebugProtocol } from 'vscode-debugprotocol';
 
+import { CallstackModel } from './panels/callstack/model';
+
+import { SourcesModel } from './panels/sources/model';
+
+import { VariablesModel } from './panels/variables/model';
+
 /**
  * An interface describing an application's visual debugger.
  */
@@ -25,7 +31,7 @@ export interface IDebugger {
   /**
    * The model of the debugger.
    */
-  model: IDebugger.IModel;
+  readonly model: IDebugger.IModel;
 
   /**
    * Whether the current debugger is started.
@@ -37,11 +43,6 @@ export interface IDebugger {
    */
   readonly sessionChanged: ISignal<IDebugger, IDebugger.ISession>;
 
-  /**
-   * Signal emitted upon model changed.
-   */
-  readonly modelChanged: ISignal<IDebugger, IDebugger.IModel>;
-
   /**
    * Signal emitted for debug event messages.
    */
@@ -149,6 +150,73 @@ export interface IDebugger {
  * A namespace for visual debugger types.
  */
 export namespace IDebugger {
+  /**
+   * A namespace for UI interface definitions.
+   */
+  export namespace UI {
+    /**
+     * The breakpoints UI model.
+     */
+    export interface IBreakpoints {
+      /**
+       * Signal emitted when the model changes.
+       */
+      readonly changed: ISignal<this, IDebugger.IBreakpoint[]>;
+
+      /**
+       * Signal emitted when the breakpoints are restored.
+       */
+      readonly restored: ISignal<this, void>;
+
+      /**
+       * Signal emitted when a breakpoint is clicked.
+       */
+      readonly clicked: ISignal<this, IDebugger.IBreakpoint>;
+
+      /**
+       * Get all the breakpoints.
+       */
+      readonly breakpoints: Map<string, IDebugger.IBreakpoint[]>;
+
+      /**
+       * Set the breakpoints for a given id (path).
+       *
+       * @param id The code id (path).
+       * @param breakpoints The list of breakpoints.
+       */
+      setBreakpoints(id: string, breakpoints: IBreakpoint[]): void;
+
+      /**
+       * Get the breakpoints for a given id (path).
+       *
+       * @param id The code id (path).
+       */
+      getBreakpoints(id: string): IBreakpoint[];
+
+      /**
+       * Restore a map of breakpoints.
+       *
+       * @param breakpoints The map of breakpoints
+       */
+      restoreBreakpoints(breakpoints: Map<string, IBreakpoint[]>): void;
+    }
+
+    /**
+     * The callstack UI model.
+     */
+    export type ICallstack = CallstackModel;
+
+    /**
+     * The variables UI model.
+     */
+    export type IVariables = VariablesModel;
+
+    /**
+     * The sources UI model.
+     */
+    export type ISources = SourcesModel;
+  }
+
   /**
    * The type for a source file.
    */
@@ -169,6 +237,51 @@ export namespace IDebugger {
     mimeType?: string;
   };
 
+  /**
+   * The data model for the debugger.
+   */
+  export interface IModel {
+    /**
+     * The breakpoints UI model.
+     */
+    readonly breakpoints: UI.IBreakpoints;
+
+    /**
+     * The callstack UI model.
+     */
+    readonly callstack: UI.ICallstack;
+
+    /**
+     * The variables UI model.
+     */
+    readonly variables: UI.IVariables;
+
+    /**
+     * The sources UI model.
+     */
+    readonly sources: UI.ISources;
+
+    /**
+     * The set of threads in stopped state.
+     */
+    stoppedThreads: Set<number>;
+
+    /**
+     * The current debugger title.
+     */
+    title: string;
+
+    /**
+     * A signal emitted when the title changes.
+     */
+    titleChanged: ISignal<this, string>;
+
+    /**
+     * Clear the model.
+     */
+    clear(): void;
+  }
+
   /**
    * A visual debugger session.
    */
@@ -221,6 +334,7 @@ export namespace IDebugger {
   export interface IBreakpoint extends DebugProtocol.Breakpoint {
     active: boolean;
   }
+
   /**
    * Debugger file and hashing configuration.
    */
@@ -364,11 +478,6 @@ export namespace IDebugger {
     };
   }
 
-  /**
-   * The model of a debugger session.
-   */
-  export type IModel = IObservableDisposable;
-
   export namespace ISession {
     /**
      * Response to the 'kernel_info_request' request.

+ 4 - 16
test/service.spec.ts

@@ -98,7 +98,6 @@ describe('Debugging support', () => {
 describe('DebuggerService', () => {
   const specsManager = new KernelSpecManager();
   let connection: Session.ISessionConnection;
-  let model: Debugger.Model;
   let config: IDebugger.IConfig;
   let session: IDebugger.ISession;
   let service: IDebugger;
@@ -111,7 +110,6 @@ describe('DebuggerService', () => {
     });
     await connection.changeKernel({ name: 'xpython' });
     session = new Debugger.Session({ connection });
-    model = new Debugger.Model();
     config = new Debugger.Config();
     service = new Debugger.Service({ specsManager, config });
   });
@@ -164,18 +162,6 @@ describe('DebuggerService', () => {
     });
   });
 
-  describe('#model', () => {
-    it('should emit the modelChanged signal when setting the model', () => {
-      const modelChangedEvents: Debugger.Model[] = [];
-      service.modelChanged.connect((_, newModel) => {
-        modelChangedEvents.push(newModel as Debugger.Model);
-      });
-      service.model = model;
-      expect(modelChangedEvents.length).toEqual(1);
-      expect(modelChangedEvents[0]).toEqual(model);
-    });
-  });
-
   describe('protocol', () => {
     const code = [
       'i = 0',
@@ -191,7 +177,6 @@ describe('DebuggerService', () => {
 
     beforeEach(async () => {
       service.session = session;
-      service.model = model;
       await service.restoreState(true);
       const breakpointLines: number[] = [3, 5];
       sourceId = service.getCodeId(code);
@@ -211,6 +196,7 @@ describe('DebuggerService', () => {
 
     describe('#updateBreakpoints', () => {
       it('should update the breakpoints', () => {
+        const { model } = service;
         const bpList = model.breakpoints.getBreakpoints(sourceId);
         expect(bpList).toEqual(breakpoints);
       });
@@ -218,6 +204,7 @@ describe('DebuggerService', () => {
 
     describe('#restoreState', () => {
       it('should restore the breakpoints', async () => {
+        const { model } = service;
         model.breakpoints.restoreBreakpoints(
           new Map<string, IDebugger.IBreakpoint[]>()
         );
@@ -232,6 +219,7 @@ describe('DebuggerService', () => {
     describe('#restart', () => {
       it('should restart the debugger and send the breakpoints again', async () => {
         await service.restart();
+        const { model } = service;
         model.breakpoints.restoreBreakpoints(
           new Map<string, IDebugger.IBreakpoint[]>()
         );
@@ -245,12 +233,12 @@ describe('DebuggerService', () => {
 
     describe('#hasStoppedThreads', () => {
       it('should return false if the model is null', () => {
-        service.model = null;
         const hasStoppedThreads = service.hasStoppedThreads();
         expect(hasStoppedThreads).toBe(false);
       });
 
       it('should return true when the execution has stopped', async () => {
+        const { model } = service;
         const variablesChanged = signalToPromise(model.variables.changed);
 
         // trigger a manual execute request