Просмотр исходного кода

Add restart method to the service

Jeremy Tuloup 5 лет назад
Родитель
Сommit
5b3e918774
3 измененных файлов с 18 добавлено и 2 удалено
  1. 1 2
      src/index.ts
  2. 11 0
      src/service.ts
  3. 6 0
      src/tokens.ts

+ 1 - 2
src/index.ts

@@ -299,8 +299,7 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
         return service.isThreadStopped();
       },
       execute: async () => {
-        await service.stop();
-        await service.start();
+        await service.restart();
         commands.notifyCommandChanged();
       }
     });

+ 11 - 0
src/service.ts

@@ -172,6 +172,17 @@ export class DebugService implements IDebugger {
     this._stoppedThreads.clear();
   }
 
+  /**
+   * Restarts the debugger.
+   * Precondition: isStarted() and stopped.
+   */
+  async restart(): Promise<void> {
+    await this.stop();
+    this.clearModel();
+    this._stoppedThreads.clear();
+    await this.start();
+  }
+
   /**
    * Restore the state of a debug session.
    * @param autoStart - when true, starts the debugger

+ 6 - 0
src/tokens.ts

@@ -78,6 +78,12 @@ export interface IDebugger extends IDisposable {
    */
   stop(): Promise<void>;
 
+  /**
+   * Restart the debugger.
+   * Precondition: isStarted()
+   */
+  restart(): Promise<void>;
+
   /**
    * Restore the state of a debug session.
    * @param autoStart - when true, starts the debugger