瀏覽代碼

Implemented variable inspection when the debugger has started

Johan Mabille 4 年之前
父節點
當前提交
8e1687c2b5
共有 4 個文件被更改,包括 71 次插入2 次删除
  1. 36 1
      packages/debugger/src/handler.ts
  2. 20 0
      packages/debugger/src/service.ts
  3. 14 0
      packages/debugger/src/tokens.ts
  4. 1 1
      scripts/ci_install.sh

+ 36 - 1
packages/debugger/src/handler.ts

@@ -19,7 +19,7 @@ import { FileEditor } from '@jupyterlab/fileeditor';
 
 import { NotebookPanel } from '@jupyterlab/notebook';
 
-import { Kernel, Session } from '@jupyterlab/services';
+import { Kernel, Session, KernelMessage } from '@jupyterlab/services';
 
 import { nullTranslator, ITranslator } from '@jupyterlab/translation';
 
@@ -122,6 +122,7 @@ export class DebuggerHandler {
     if (!connection) {
       delete this._kernelChangedHandlers[widget.id];
       delete this._statusChangedHandlers[widget.id];
+      delete this._iopubMessageHandlers[widget.id];
       return this._update(widget, connection);
     }
 
@@ -152,6 +153,26 @@ export class DebuggerHandler {
     connection.statusChanged.connect(statusChanged);
     this._statusChangedHandlers[widget.id] = statusChanged;
 
+    const iopubMessage = (
+      _: Session.ISessionConnection,
+      msg: KernelMessage.IIOPubMessage
+    ): void => {
+      if (
+        msg.parent_header != {} &&
+        (msg.parent_header as KernelMessage.IHeader).msg_type == 'execute_request' &&
+        this._service.isStarted &&
+        !this._service.hasStoppedThreads()
+      ) {
+        void this._service.displayDefinedVariables();
+      }
+    };
+    const iopubMessageHandler = this._iopubMessageHandlers[widget.id];
+    if (iopubMessageHandler) {
+      connection.iopubMessage.disconnect(iopubMessageHandler);
+    }
+    connection.iopubMessage.connect(iopubMessage);
+    this._iopubMessageHandlers[widget.id] = iopubMessage;
+
     return this._update(widget, connection);
   }
 
@@ -249,6 +270,7 @@ export class DebuggerHandler {
       delete this._handlers[widget.id];
       delete this._kernelChangedHandlers[widget.id];
       delete this._statusChangedHandlers[widget.id];
+      delete this._iopubMessageHandlers[widget.id];
       delete this._contextKernelChangedHandlers[widget.id];
 
       // Clear the model if the handler being removed corresponds
@@ -321,6 +343,7 @@ export class DebuggerHandler {
         this._service.session!.connection = connection;
         this._previousConnection = connection;
         await this._service.restoreState(true);
+        await this._service.displayDefinedVariables();
         createHandler();
       }
     };
@@ -342,6 +365,12 @@ export class DebuggerHandler {
       this._service.session.connection = connection;
     }
     await this._service.restoreState(false);
+    if (
+      this._service.isStarted &&
+      !this._service.hasStoppedThreads()
+    ) {
+      await this._service.displayDefinedVariables();
+    }
     addToolbarButton();
 
     // check the state of the debug session
@@ -394,6 +423,12 @@ export class DebuggerHandler {
       status: Kernel.Status
     ) => void;
   } = {};
+  private _iopubMessageHandlers: {
+    [id: string]: (
+      sender: Session.ISessionConnection,
+      msg: KernelMessage.IIOPubMessage
+    ) => void;
+  } = {};
   private _iconButtons: {
     [id: string]: ToolbarButton | undefined;
   } = {};

+ 20 - 0
packages/debugger/src/service.ts

@@ -249,6 +249,26 @@ export class DebuggerService implements IDebugger, IDisposable {
     return reply.body.variables;
   }
 
+  /**
+   * Requests all the defined variables and display them in the
+   * table view.
+   */
+  async displayDefinedVariables(): Promise<void> {
+    if (!this.session) {
+      throw new Error('No active debugger session');
+    }
+    const inspectReply = await this.session.sendRequest('inspectVariables', {});
+    const variables = inspectReply.body.variables;
+
+    const variableScopes = [
+      {
+        name: 'Globals',
+        variables: variables
+      }
+    ];
+    this._model.variables.scopes = variableScopes;
+  }
+
   /**
    * Restart the debugger.
    */

+ 14 - 0
packages/debugger/src/tokens.ts

@@ -80,6 +80,12 @@ export interface IDebugger {
     variablesReference: number
   ): Promise<DebugProtocol.Variable[]>;
 
+  /**
+   * Requests all the defined variables and display them in the
+   * table view.
+   */
+  displayDefinedVariables(): Promise<void>;
+
   /**
    * Request whether debugging is available for the given session connection.
    *
@@ -362,6 +368,7 @@ export namespace IDebugger {
       goto: DebugProtocol.GotoArguments;
       gotoTargets: DebugProtocol.GotoTargetsArguments;
       initialize: DebugProtocol.InitializeRequestArguments;
+      inspectVariables: {};
       launch: DebugProtocol.LaunchRequestArguments;
       loadedSources: DebugProtocol.LoadedSourcesArguments;
       modules: DebugProtocol.ModulesArguments;
@@ -404,6 +411,7 @@ export namespace IDebugger {
       goto: DebugProtocol.GotoResponse;
       gotoTargets: DebugProtocol.GotoTargetsResponse;
       initialize: DebugProtocol.InitializeResponse;
+      inspectVariables: IInspectVariablesResponse;
       launch: DebugProtocol.LaunchResponse;
       loadedSources: DebugProtocol.LoadedSourcesResponse;
       modules: DebugProtocol.ModulesResponse;
@@ -475,6 +483,12 @@ export namespace IDebugger {
       };
     }
 
+    export interface IInspectVariablesResponse extends DebugProtocol.Response {
+      body: {
+        variables: DebugProtocol.Variable[];
+      };
+    }
+
     /**
      * Response to the 'kernel_info_request' request.
      * This interface extends the IInfoReply by adding the `debugger` key

+ 1 - 1
scripts/ci_install.sh

@@ -51,7 +51,7 @@ fi
 
 # The debugger tests require a kernel that supports debugging
 if [[ $GROUP == js-debugger ]]; then
-    pip install xeus-python">=0.9.0,<0.10.0"
+    pip install xeus-python">=0.12.3,<0.13.0"
 fi
 
 # Pin the jedi dependency to prevent a temporary breakage