فهرست منبع

Restore debugger session state

Johan Mabille 5 سال پیش
والد
کامیت
5fd035644e
4فایلهای تغییر یافته به همراه59 افزوده شده و 10 حذف شده
  1. 1 1
      azure-pipelines.yml
  2. 13 5
      src/index.ts
  3. 12 0
      src/session.ts
  4. 33 4
      src/tokens.ts

+ 1 - 1
azure-pipelines.yml

@@ -16,7 +16,7 @@ steps:
 
 - bash: |
     source activate jupyterlab-debugger
-    conda install --yes --quiet -c conda-forge nodejs xeus-python=0.5.3 ptvsd python=$PYTHON_VERSION
+    conda install --yes --quiet -c conda-forge nodejs xeus-python=0.6.1 ptvsd python=$PYTHON_VERSION
     python -m pip install -U --pre jupyterlab
   displayName: Install dependencies
 

+ 13 - 5
src/index.ts

@@ -64,7 +64,7 @@ const consoles: JupyterFrontEndPlugin<void> = {
   autoStart: true,
   requires: [IDebugger, IConsoleTracker, ILabShell],
   activate: (
-    _,
+    app: JupyterFrontEnd,
     debug: IDebugger,
     tracker: IConsoleTracker,
     labShell: ILabShell
@@ -74,7 +74,7 @@ const consoles: JupyterFrontEndPlugin<void> = {
       handler: DebuggerConsoleHandler;
     };
 
-    labShell.currentChanged.connect((_, update) => {
+    labShell.currentChanged.connect(async (_, update) => {
       const widget = update.newValue;
 
       if (!(widget instanceof ConsolePanel)) {
@@ -86,6 +86,10 @@ const consoles: JupyterFrontEndPlugin<void> = {
       } else {
         debug.session.client = widget.session;
       }
+      if (debug.session) {
+        await debug.session.restoreState();
+        app.commands.notifyCommandChanged();
+      }
       if (debug.tracker.currentWidget) {
         const handler = new DebuggerConsoleHandler({
           consoleTracker: tracker,
@@ -163,7 +167,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
   autoStart: true,
   requires: [IDebugger, INotebookTracker, ILabShell],
   activate: (
-    _,
+    app: JupyterFrontEnd,
     debug: IDebugger,
     tracker: INotebookTracker,
     labShell: ILabShell
@@ -173,7 +177,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
       handler: DebuggerNotebookHandler;
     };
 
-    labShell.currentChanged.connect((_, update) => {
+    labShell.currentChanged.connect(async (_, update) => {
       const widget = update.newValue;
       if (!(widget instanceof NotebookPanel)) {
         return;
@@ -183,6 +187,10 @@ const notebooks: JupyterFrontEndPlugin<void> = {
       } else {
         debug.session.client = widget.session;
       }
+      if (debug.session) {
+        await debug.session.restoreState();
+        app.commands.notifyCommandChanged();
+      }
       if (debug.tracker.currentWidget) {
         const handler = new DebuggerNotebookHandler({
           notebookTracker: tracker,
@@ -394,7 +402,7 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
         },
         session: {
           get: (): IDebugger.ISession | null => {
-            return null;
+            return widget ? widget.content.model.session : null;
           },
           set: (src: IDebugger.ISession | null) => {
             if (widget) {

+ 12 - 0
src/session.ts

@@ -135,6 +135,18 @@ export class DebugSession implements IDebugger.ISession {
     }
   }
 
+  /**
+   * Restore the state of a debug session.
+   */
+  async restoreState(): Promise<void> {
+    try {
+      const message = await this.sendRequest('debugInfo', {});
+      this._isStarted = message.body.isStarted;
+    } catch (err) {
+      console.error('Error: ', err.message);
+    }
+  }
+
   /**
    * Send a custom debug request to the kernel.
    * @param command debug command.

+ 33 - 4
src/tokens.ts

@@ -79,13 +79,18 @@ export namespace IDebugger {
      * Stop a running debug session.
      */
     stop(): Promise<void>;
+
+    /**
+     * Restore the state of a debug session.
+     */
+    restoreState(): Promise<void>;
   }
 
   export namespace ISession {
     /**
      * Arguments for 'dumpCell' request.
      * This is an addition to the Debug Adapter Protocol to support
-     * setting breakpoints for cells
+     * setting breakpoints for cells.
      */
     export interface IDumpCellArguments {
       code: string;
@@ -94,7 +99,7 @@ export namespace IDebugger {
     /**
      * Response to 'dumpCell' request.
      * This is an addition to the Debug Adapter Protocol to support
-     * setting breakpoints for cells
+     * setting breakpoints for cells.
      */
     export interface IDumpCellResponse extends DebugProtocol.Response {
       body: {
@@ -102,6 +107,28 @@ export namespace IDebugger {
       };
     }
 
+    /**
+     * List of breakpoints in a source file.
+     */
+    export interface IDebugInfoBreakpoints {
+      source: string;
+      lines: number[];
+    }
+
+    /**
+     * 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[];
+      };
+    }
+
     /**
      * Expose all the debug requests types.
      */
@@ -110,7 +137,9 @@ export namespace IDebugger {
       completions: DebugProtocol.CompletionsArguments;
       configurationDone: DebugProtocol.ConfigurationDoneArguments;
       continue: DebugProtocol.ContinueArguments;
+      debugInfo: {};
       disconnect: DebugProtocol.DisconnectArguments;
+      dumpCell: IDumpCellArguments;
       evaluate: DebugProtocol.EvaluateArguments;
       exceptionInfo: DebugProtocol.ExceptionInfoArguments;
       goto: DebugProtocol.GotoArguments;
@@ -139,7 +168,6 @@ export namespace IDebugger {
       terminate: DebugProtocol.TerminateArguments;
       terminateThreads: DebugProtocol.TerminateThreadsArguments;
       threads: {};
-      dumpCell: IDumpCellArguments;
       variables: DebugProtocol.VariablesArguments;
     };
 
@@ -151,7 +179,9 @@ export namespace IDebugger {
       completions: DebugProtocol.CompletionsResponse;
       configurationDone: DebugProtocol.ConfigurationDoneResponse;
       continue: DebugProtocol.ContinueResponse;
+      debugInfo: IDebugInfoResponse;
       disconnect: DebugProtocol.DisconnectResponse;
+      dumpCell: IDumpCellResponse;
       evaluate: DebugProtocol.EvaluateResponse;
       exceptionInfo: DebugProtocol.ExceptionInfoResponse;
       goto: DebugProtocol.GotoResponse;
@@ -180,7 +210,6 @@ export namespace IDebugger {
       terminate: DebugProtocol.TerminateResponse;
       terminateThreads: DebugProtocol.TerminateThreadsResponse;
       threads: DebugProtocol.ThreadsResponse;
-      dumpCell: IDumpCellResponse;
       variables: DebugProtocol.VariablesResponse;
     };