From 15ef6257c464e8a253ceb28b60abb6199281fcbf Mon Sep 17 00:00:00 2001 From: abbycin Date: Wed, 15 May 2019 16:05:20 +0800 Subject: [PATCH] fix restart and stop issue --- package.json | 2 +- src/topjsDebug.js | 32 ++++++++++++++++++++++++++++---- src/topjsRuntime.js | 4 ++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 40b1a57..1c74976 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "topjs-debugger", "displayName": "TopJS Debugger", - "version": "0.0.2", + "version": "0.0.3", "publisher": "AbbyCin", "description": "TopJS debugger extension for VS Code.", "author": { diff --git a/src/topjsDebug.js b/src/topjsDebug.js index 074ca31..89d54ad 100644 --- a/src/topjsDebug.js +++ b/src/topjsDebug.js @@ -43,6 +43,20 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { this.setDebuggerColumnsStartAt1(false); this._cachedBreakpoints = {}; + this._restart = false; + + // overwrite event in base class + + // when close stop button + this.on('close', () => { + this.terminateSession('exit'); + super.shutdown(); + }); + + this.on('error', (error) => { + this.terminateSession('exit'); + super.shutdown(); + }); // runtime instance for interacting with debugger backend this._runtime = new topjsRuntime.topjsRuntime(); @@ -150,7 +164,7 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { spawn.execSync(`${TASK_KILL} /F /T /PID ${processId}`); } catch (err) { - this.err(err); + //this.err(err.message); } } else { @@ -168,7 +182,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { let argv = [`--remote-debugging-port=${args.port}`, args.program]; this._backend = spawn.spawn(args.runtimeExecutable, argv); this._backend.on('exit', () => { - this.sendEvent(new vscode_debugadapter.TerminatedEvent()); + if(!this._restart) { + this._restart = false; + this.sendEvent(new vscode_debugadapter.TerminatedEvent()); + } if(this.isExtensionHost()) { this.terminateSession(msg); } @@ -178,7 +195,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { if(!this.isExtensionHost()) { this.terminateSession(msg); } - this.sendEvent(new vscode_debugadapter.TerminatedEvent()); + if(!this._restart) { + this._restart = false; + this.sendEvent(new vscode_debugadapter.TerminatedEvent()); + } process.exit(0); }); this._backend.stdout.on('data', (data) => { @@ -190,7 +210,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { this._backend.on('error', (err) => { this.err(err.message()); this.err('main process exit...'); - this.sendEvent(new vscode_debugadapter.TerminatedEvent()); + if(!this._restart) { + this._restart = false; + this.sendEvent(new vscode_debugadapter.TerminatedEvent()); + } process.exit(1); }); this.log([args.runtimeExecutable, `--remote-debugging-port=${args.port}`, Path.basename(args.program)].join(' ')); @@ -362,6 +385,7 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { } restartRequest(response, args) { + this._restart = true; this._runtime.quit(); this.terminateSession('restart'); this.spawnBackend(this._args); diff --git a/src/topjsRuntime.js b/src/topjsRuntime.js index 57a9605..314cbf3 100644 --- a/src/topjsRuntime.js +++ b/src/topjsRuntime.js @@ -277,9 +277,9 @@ class topjsRuntime extends events.EventEmitter { quit() { try { - this.client.disconnect(); + this.client.destroy('close'); } catch(e) { - + //this._logger.log(`disconnect: ${e}`); } this._started = false; }