浏览代码

Merge pull request #509 from jtpio/interfaces

Move CallstackModel.IFrame to IDebugger.IStackFrame
Afshin Taylor Darian 4 年之前
父节点
当前提交
66e082ab16

+ 1 - 0
.eslintrc.js

@@ -30,6 +30,7 @@ module.exports = {
     '@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
     '@typescript-eslint/no-var-requires': 'off',
     '@typescript-eslint/no-explicit-any': 'off',
+    '@typescript-eslint/no-empty-interface': 'off',
     '@typescript-eslint/no-namespace': 'off',
     '@typescript-eslint/no-use-before-define': 'off',
     '@typescript-eslint/quotes': [

+ 1 - 3
src/index.ts

@@ -48,8 +48,6 @@ import { EditorHandler } from './handlers/editor';
 
 import { IDebugger, IDebuggerConfig, IDebuggerSources } from './tokens';
 
-import { CallstackModel } from './panels/callstack/model';
-
 import { ReadOnlyEditorFactory } from './panels/sources/factory';
 
 import { VariablesBodyGrid } from './panels/variables/grid';
@@ -551,7 +549,7 @@ const main: JupyterFrontEndPlugin<void> = {
 
       const onCurrentFrameChanged = (
         _: IDebugger.Model.ICallstack,
-        frame: CallstackModel.IFrame
+        frame: IDebugger.IStackFrame
       ): void => {
         debuggerSources
           .find({

+ 11 - 23
src/panels/callstack/model.ts

@@ -3,8 +3,6 @@
 
 import { ISignal, Signal } from '@lumino/signaling';
 
-import { DebugProtocol } from 'vscode-debugprotocol';
-
 import { IDebugger } from '../../tokens';
 
 /**
@@ -14,14 +12,14 @@ export class CallstackModel implements IDebugger.Model.ICallstack {
   /**
    * Get all the frames.
    */
-  get frames(): CallstackModel.IFrame[] {
+  get frames(): IDebugger.IStackFrame[] {
     return this._state;
   }
 
   /**
    * Set the frames.
    */
-  set frames(newFrames: CallstackModel.IFrame[]) {
+  set frames(newFrames: IDebugger.IStackFrame[]) {
     this._state = newFrames;
     const frame = newFrames.find(
       frame => Private.getFrameId(frame) === Private.getFrameId(this.frame)
@@ -37,14 +35,14 @@ export class CallstackModel implements IDebugger.Model.ICallstack {
   /**
    * Get the current frame.
    */
-  get frame(): CallstackModel.IFrame {
+  get frame(): IDebugger.IStackFrame {
     return this._currentFrame;
   }
 
   /**
    * Set the current frame.
    */
-  set frame(frame: CallstackModel.IFrame) {
+  set frame(frame: IDebugger.IStackFrame) {
     this._currentFrame = frame;
     this._currentFrameChanged.emit(frame);
   }
@@ -52,31 +50,21 @@ export class CallstackModel implements IDebugger.Model.ICallstack {
   /**
    * Signal emitted when the frames have changed.
    */
-  get framesChanged(): ISignal<this, CallstackModel.IFrame[]> {
+  get framesChanged(): ISignal<this, IDebugger.IStackFrame[]> {
     return this._framesChanged;
   }
 
   /**
    * Signal emitted when the current frame has changed.
    */
-  get currentFrameChanged(): ISignal<this, CallstackModel.IFrame> {
+  get currentFrameChanged(): ISignal<this, IDebugger.IStackFrame> {
     return this._currentFrameChanged;
   }
 
-  private _state: CallstackModel.IFrame[] = [];
-  private _currentFrame: CallstackModel.IFrame;
-  private _framesChanged = new Signal<this, CallstackModel.IFrame[]>(this);
-  private _currentFrameChanged = new Signal<this, CallstackModel.IFrame>(this);
-}
-
-/**
- * A namespace for CallstackModel `statics`.
- */
-export namespace CallstackModel {
-  /**
-   * An interface for a frame.
-   */
-  export type IFrame = DebugProtocol.StackFrame;
+  private _state: IDebugger.IStackFrame[] = [];
+  private _currentFrame: IDebugger.IStackFrame;
+  private _framesChanged = new Signal<this, IDebugger.IStackFrame[]>(this);
+  private _currentFrameChanged = new Signal<this, IDebugger.IStackFrame>(this);
 }
 
 /**
@@ -88,7 +76,7 @@ namespace Private {
    *
    * @param frame The frame.
    */
-  export function getFrameId(frame: CallstackModel.IFrame): string {
+  export function getFrameId(frame: IDebugger.IStackFrame): string {
     return `${frame?.source?.path}-${frame?.id}`;
   }
 }

+ 1 - 3
src/panels/sources/body.ts

@@ -13,8 +13,6 @@ import { PanelLayout, Widget } from '@lumino/widgets';
 
 import { EditorHandler } from '../../handlers/editor';
 
-import { CallstackModel } from '../../panels/callstack/model';
-
 import { IDebugger } from '../../tokens';
 
 import { ReadOnlyEditorFactory } from './factory';
@@ -86,7 +84,7 @@ export class SourcesBody extends Widget {
    *
    * @param frame The current frame.
    */
-  private async _showSource(frame: CallstackModel.IFrame): Promise<void> {
+  private async _showSource(frame: IDebugger.IStackFrame): Promise<void> {
     const path = frame.source.path;
     const source = await this._debuggerService.getSource({
       sourceReference: 0,

+ 8 - 4
src/panels/sources/model.ts

@@ -5,8 +5,6 @@ import { ISignal, Signal } from '@lumino/signaling';
 
 import { IDebugger } from '../../tokens';
 
-import { CallstackModel } from '../callstack/model';
-
 /**
  * The model to keep track of the current source being displayed.
  */
@@ -23,7 +21,10 @@ export class SourcesModel implements IDebugger.Model.ISources {
   /**
    * Signal emitted when the current frame changes.
    */
-  readonly currentFrameChanged: ISignal<CallstackModel, CallstackModel.IFrame>;
+  readonly currentFrameChanged: ISignal<
+    IDebugger.Model.ICallstack,
+    IDebugger.IStackFrame
+  >;
 
   /**
    * Signal emitted when a source should be open in the main area.
@@ -83,6 +84,9 @@ export namespace SourcesModel {
     /**
      * Signal emitted when the current frame changes.
      */
-    currentFrameChanged: ISignal<CallstackModel, CallstackModel.IFrame>;
+    currentFrameChanged: ISignal<
+      IDebugger.Model.ICallstack,
+      IDebugger.IStackFrame
+    >;
   }
 }

+ 2 - 2
src/panels/variables/grid.ts

@@ -208,7 +208,7 @@ export class VariableDataGridModel extends DataModel {
    *
    * @param scopes The scopes.
    */
-  setData(scopes: VariablesModel.IScope[]): void {
+  setData(scopes: IDebugger.IScope[]): void {
     this._clearData();
     this.emitChanged({
       type: 'model-reset',
@@ -278,7 +278,7 @@ export namespace VariablesBodyGrid {
     /**
      * The optional initial scopes data.
      */
-    scopes?: VariablesModel.IScope[];
+    scopes?: IDebugger.IScope[];
   }
 }
 

+ 1 - 5
src/panels/variables/index.ts

@@ -13,8 +13,6 @@ import { VariablesBodyGrid, VariablesGrid } from './grid';
 
 import { VariablesHeader } from './header';
 
-import { VariablesModel } from './model';
-
 import { VariablesBodyTree } from './tree';
 
 /**
@@ -109,9 +107,7 @@ export class Variables extends Panel {
  *
  * @param variable The variable.
  */
-export const convertType = (
-  variable: VariablesModel.IVariable
-): string | number => {
+export const convertType = (variable: IDebugger.IVariable): string | number => {
   const { type, value } = variable;
   switch (type) {
     case 'int':

+ 6 - 38
src/panels/variables/model.ts

@@ -3,8 +3,6 @@
 
 import { ISignal, Signal } from '@lumino/signaling';
 
-import { DebugProtocol } from 'vscode-debugprotocol';
-
 import { IDebugger } from '../../tokens';
 
 /**
@@ -14,14 +12,14 @@ export class VariablesModel implements IDebugger.Model.IVariables {
   /**
    * Get all the scopes.
    */
-  get scopes(): VariablesModel.IScope[] {
+  get scopes(): IDebugger.IScope[] {
     return this._state;
   }
 
   /**
    * Set the scopes.
    */
-  set scopes(scopes: VariablesModel.IScope[]) {
+  set scopes(scopes: IDebugger.IScope[]) {
     this._state = scopes;
     this._changed.emit();
   }
@@ -36,7 +34,7 @@ export class VariablesModel implements IDebugger.Model.IVariables {
   /**
    * Signal emitted when the current variable has been expanded.
    */
-  get variableExpanded(): ISignal<this, VariablesModel.IVariable> {
+  get variableExpanded(): ISignal<this, IDebugger.IVariable> {
     return this._variableExpanded;
   }
 
@@ -45,41 +43,11 @@ export class VariablesModel implements IDebugger.Model.IVariables {
    *
    * @param variable The variable to expand.
    */
-  expandVariable(variable: VariablesModel.IVariable): void {
+  expandVariable(variable: IDebugger.IVariable): void {
     this._variableExpanded.emit(variable);
   }
 
-  private _state: VariablesModel.IScope[] = [];
-  private _variableExpanded = new Signal<this, VariablesModel.IVariable>(this);
+  private _state: IDebugger.IScope[] = [];
+  private _variableExpanded = new Signal<this, IDebugger.IVariable>(this);
   private _changed = new Signal<this, void>(this);
 }
-
-/**
- * A namespace for VariablesModel `statics`.
- */
-export namespace VariablesModel {
-  /**
-   * An interface for a variable.
-   */
-  export interface IVariable extends DebugProtocol.Variable {
-    /**
-     * Whether the variable is expanded.
-     */
-    expanded?: boolean;
-  }
-
-  /**
-   * An interface for a scope.
-   */
-  export interface IScope {
-    /**
-     * The name of the scope.
-     */
-    name: string;
-
-    /**
-     * The list of variables.
-     */
-    variables: IVariable[];
-  }
-}

+ 3 - 3
src/panels/variables/tree.tsx

@@ -73,7 +73,7 @@ export class VariablesBodyTree extends ReactWidget {
     this.update();
   }
 
-  private _scopes: VariablesModel.IScope[] = [];
+  private _scopes: IDebugger.IScope[] = [];
   private _filter = new Set<string>();
   private _service: IDebugger;
 }
@@ -91,7 +91,7 @@ const VariablesComponent = ({
   service,
   filter
 }: {
-  data: VariablesModel.IVariable[];
+  data: IDebugger.IVariable[];
   service: IDebugger;
   filter?: Set<string>;
 }): JSX.Element => {
@@ -133,7 +133,7 @@ const VariableComponent = ({
   service,
   filter
 }: {
-  data: VariablesModel.IVariable;
+  data: IDebugger.IVariable;
   service: IDebugger;
   filter?: Set<string>;
 }): JSX.Element => {

+ 3 - 5
src/service.ts

@@ -11,8 +11,6 @@ import { DebugProtocol } from 'vscode-debugprotocol';
 
 import { Debugger } from './debugger';
 
-import { CallstackModel } from './panels/callstack/model';
-
 import { VariablesModel } from './panels/variables/model';
 
 import { IDebugger } from './tokens';
@@ -413,7 +411,7 @@ export class DebuggerService implements IDebugger, IDisposable {
   private _convertScopes(
     scopes: DebugProtocol.Scope[],
     variables: DebugProtocol.Variable[]
-  ): VariablesModel.IScope[] {
+  ): IDebugger.IScope[] {
     if (!variables || !scopes) {
       return;
     }
@@ -577,8 +575,8 @@ export class DebuggerService implements IDebugger, IDisposable {
    * @param frame The frame.
    */
   private async _onCurrentFrameChanged(
-    _: CallstackModel,
-    frame: CallstackModel.IFrame
+    _: IDebugger.Model.ICallstack,
+    frame: IDebugger.IStackFrame
   ): Promise<void> {
     if (!frame) {
       return;

+ 116 - 86
src/tokens.ts

@@ -13,12 +13,6 @@ import { ISignal, Signal } 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.
  */
@@ -204,6 +198,21 @@ export namespace IDebugger {
     setTmpFileParams(params: IConfig.FileParams): void;
   }
 
+  /**
+   * An interface for a scope.
+   */
+  export interface IScope {
+    /**
+     * The name of the scope.
+     */
+    name: string;
+
+    /**
+     * The list of variables.
+     */
+    variables: IVariable[];
+  }
+
   /**
    * A visual debugger session.
    */
@@ -226,16 +235,6 @@ export namespace IDebugger {
       IDebugger.ISession.Event
     >;
 
-    /**
-     * Start a new debug session.
-     */
-    start(): Promise<void>;
-
-    /**
-     * Stop a running debug session.
-     */
-    stop(): Promise<void>;
-
     /**
      * Restore the state of a debug session.
      */
@@ -248,6 +247,16 @@ export namespace IDebugger {
       command: K,
       args: IDebugger.ISession.Request[K]
     ): Promise<IDebugger.ISession.Response[K]>;
+
+    /**
+     * Start a new debug session.
+     */
+    start(): Promise<void>;
+
+    /**
+     * Stop a running debug session.
+     */
+    stop(): Promise<void>;
   }
 
   /**
@@ -271,6 +280,21 @@ export namespace IDebugger {
     open(params: ISources.OpenParams): void;
   }
 
+  /**
+   * The type for a stack frame
+   */
+  export interface IStackFrame extends DebugProtocol.StackFrame {}
+
+  /**
+   * An interface for a variable.
+   */
+  export interface IVariable extends DebugProtocol.Variable {
+    /**
+     * Whether the variable is expanded.
+     */
+    expanded?: boolean;
+  }
+
   /**
    * Debugger file and hashing configuration.
    */
@@ -318,59 +342,9 @@ export namespace IDebugger {
 
   export namespace ISession {
     /**
-     * Response to the 'kernel_info_request' request.
-     * This interface extends the IInfoReply by adding the `debugger` key
-     * that isn't part of the protocol yet.
-     * See this pull request for more info: https://github.com/jupyter/jupyter_client/pull/486
-     */
-    export interface IInfoReply extends KernelMessage.IInfoReply {
-      debugger: boolean;
-    }
-
-    /**
-     * Arguments for 'dumpCell' request.
-     * This is an addition to the Debug Adapter Protocol to support
-     * setting breakpoints for cells.
-     */
-    export interface IDumpCellArguments {
-      code: string;
-    }
-
-    /**
-     * Response to 'dumpCell' request.
-     * This is an addition to the Debug Adapter Protocol to support
-     * setting breakpoints for cells.
-     */
-    export interface IDumpCellResponse extends DebugProtocol.Response {
-      body: {
-        sourcePath: string;
-      };
-    }
-
-    /**
-     * List of breakpoints in a source file.
-     */
-    export interface IDebugInfoBreakpoints {
-      source: string;
-      breakpoints: DebugProtocol.Breakpoint[];
-    }
-
-    /**
-     * Response to 'debugInfo' request.
-     * This is an addition to the Debug Adapter Protocol to be able
-     * to retrieve the debugger state when restoring a session.
+     * A generic debug event.
      */
-    export interface IDebugInfoResponse extends DebugProtocol.Response {
-      body: {
-        isStarted: boolean;
-        hashMethod: string;
-        hashSeed: number;
-        breakpoints: IDebugInfoBreakpoints[];
-        tmpFilePrefix: string;
-        tmpFileSuffix: string;
-        stoppedThreads: number[];
-      };
-    }
+    export type Event = DebugProtocol.Event;
 
     /**
      * Expose all the debug requests types.
@@ -457,9 +431,59 @@ export namespace IDebugger {
     };
 
     /**
-     * A generic debug event.
+     * List of breakpoints in a source file.
      */
-    export type Event = DebugProtocol.Event;
+    export interface IDebugInfoBreakpoints {
+      source: string;
+      breakpoints: DebugProtocol.Breakpoint[];
+    }
+
+    /**
+     * Response to 'debugInfo' request.
+     * This is an addition to the Debug Adapter Protocol to be able
+     * to retrieve the debugger state when restoring a session.
+     */
+    export interface IDebugInfoResponse extends DebugProtocol.Response {
+      body: {
+        isStarted: boolean;
+        hashMethod: string;
+        hashSeed: number;
+        breakpoints: IDebugInfoBreakpoints[];
+        tmpFilePrefix: string;
+        tmpFileSuffix: string;
+        stoppedThreads: number[];
+      };
+    }
+
+    /**
+     * Arguments for 'dumpCell' request.
+     * This is an addition to the Debug Adapter Protocol to support
+     * setting breakpoints for cells.
+     */
+    export interface IDumpCellArguments {
+      code: string;
+    }
+
+    /**
+     * Response to 'dumpCell' request.
+     * This is an addition to the Debug Adapter Protocol to support
+     * setting breakpoints for cells.
+     */
+    export interface IDumpCellResponse extends DebugProtocol.Response {
+      body: {
+        sourcePath: string;
+      };
+    }
+
+    /**
+     * Response to the 'kernel_info_request' request.
+     * This interface extends the IInfoReply by adding the `debugger` key
+     * that isn't part of the protocol yet.
+     * See this pull request for more info: https://github.com/jupyter/jupyter_client/pull/486
+     */
+    export interface IInfoReply extends KernelMessage.IInfoReply {
+      debugger: boolean;
+    }
   }
 
   /**
@@ -495,11 +519,6 @@ export namespace IDebugger {
      * Unified parameters for the open method
      */
     export type OpenParams = {
-      /**
-       * The label for the read-only editor.
-       */
-      label: string;
-
       /**
        * The caption for the read-only editor.
        */
@@ -509,6 +528,11 @@ export namespace IDebugger {
        * The code editor wrapper to add to the main area.
        */
       editorWrapper: CodeEditorWrapper;
+
+      /**
+       * The label for the read-only editor.
+       */
+      label: string;
     };
   }
 
@@ -570,22 +594,22 @@ export namespace IDebugger {
       /**
        * Signal emitted when the current frame has changed.
        */
-      readonly currentFrameChanged: ISignal<this, CallstackModel.IFrame>;
+      readonly currentFrameChanged: ISignal<this, IDebugger.IStackFrame>;
 
       /**
        * The current frame.
        */
-      frame: CallstackModel.IFrame;
+      frame: IDebugger.IStackFrame;
 
       /**
        * The frames for the callstack.
        */
-      frames: CallstackModel.IFrame[];
+      frames: IDebugger.IStackFrame[];
 
       /**
        * Signal emitted when the frames have changed.
        */
-      readonly framesChanged: ISignal<this, CallstackModel.IFrame[]>;
+      readonly framesChanged: ISignal<this, IDebugger.IStackFrame[]>;
     }
 
     /**
@@ -641,8 +665,8 @@ export namespace IDebugger {
        * Signal emitted when the current frame changes.
        */
       readonly currentFrameChanged: ISignal<
-        CallstackModel,
-        CallstackModel.IFrame
+        IDebugger.Model.ICallstack,
+        IDebugger.IStackFrame
       >;
 
       /**
@@ -653,12 +677,18 @@ export namespace IDebugger {
       /**
        * Signal emitted when the current source changes.
        */
-      readonly currentSourceChanged: ISignal<SourcesModel, IDebugger.Source>;
+      readonly currentSourceChanged: ISignal<
+        IDebugger.Model.ISources,
+        IDebugger.Source
+      >;
 
       /**
        * Signal emitted when a source should be open in the main area.
        */
-      readonly currentSourceOpened: ISignal<SourcesModel, IDebugger.Source>;
+      readonly currentSourceOpened: ISignal<
+        IDebugger.Model.ISources,
+        IDebugger.Source
+      >;
 
       /**
        * Open a source in the main area.
@@ -678,19 +708,19 @@ export namespace IDebugger {
       /**
        * The variable scopes.
        */
-      scopes: VariablesModel.IScope[];
+      scopes: IDebugger.IScope[];
 
       /**
        * Signal emitted when the current variable has been expanded.
        */
-      readonly variableExpanded: ISignal<this, VariablesModel.IVariable>;
+      readonly variableExpanded: ISignal<this, IDebugger.IVariable>;
 
       /**
        * Expand a variable.
        *
        * @param variable The variable to expand.
        */
-      expandVariable(variable: VariablesModel.IVariable): void;
+      expandVariable(variable: IDebugger.IVariable): void;
     }
   }
 }