Commit 15ef6257 authored by abbycin's avatar abbycin

fix restart and stop issue

parent 32f0f937
{ {
"name": "topjs-debugger", "name": "topjs-debugger",
"displayName": "TopJS Debugger", "displayName": "TopJS Debugger",
"version": "0.0.2", "version": "0.0.3",
"publisher": "AbbyCin", "publisher": "AbbyCin",
"description": "TopJS debugger extension for VS Code.", "description": "TopJS debugger extension for VS Code.",
"author": { "author": {
......
...@@ -43,6 +43,20 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { ...@@ -43,6 +43,20 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession {
this.setDebuggerColumnsStartAt1(false); this.setDebuggerColumnsStartAt1(false);
this._cachedBreakpoints = {}; 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 // runtime instance for interacting with debugger backend
this._runtime = new topjsRuntime.topjsRuntime(); this._runtime = new topjsRuntime.topjsRuntime();
...@@ -150,7 +164,7 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { ...@@ -150,7 +164,7 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession {
spawn.execSync(`${TASK_KILL} /F /T /PID ${processId}`); spawn.execSync(`${TASK_KILL} /F /T /PID ${processId}`);
} }
catch (err) { catch (err) {
this.err(err); //this.err(err.message);
} }
} }
else { else {
...@@ -168,7 +182,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { ...@@ -168,7 +182,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession {
let argv = [`--remote-debugging-port=${args.port}`, args.program]; let argv = [`--remote-debugging-port=${args.port}`, args.program];
this._backend = spawn.spawn(args.runtimeExecutable, argv); this._backend = spawn.spawn(args.runtimeExecutable, argv);
this._backend.on('exit', () => { 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()) { if(this.isExtensionHost()) {
this.terminateSession(msg); this.terminateSession(msg);
} }
...@@ -178,7 +195,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { ...@@ -178,7 +195,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession {
if(!this.isExtensionHost()) { if(!this.isExtensionHost()) {
this.terminateSession(msg); this.terminateSession(msg);
} }
this.sendEvent(new vscode_debugadapter.TerminatedEvent()); if(!this._restart) {
this._restart = false;
this.sendEvent(new vscode_debugadapter.TerminatedEvent());
}
process.exit(0); process.exit(0);
}); });
this._backend.stdout.on('data', (data) => { this._backend.stdout.on('data', (data) => {
...@@ -190,7 +210,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { ...@@ -190,7 +210,10 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession {
this._backend.on('error', (err) => { this._backend.on('error', (err) => {
this.err(err.message()); this.err(err.message());
this.err('main process exit...'); 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); process.exit(1);
}); });
this.log([args.runtimeExecutable, `--remote-debugging-port=${args.port}`, Path.basename(args.program)].join(' ')); this.log([args.runtimeExecutable, `--remote-debugging-port=${args.port}`, Path.basename(args.program)].join(' '));
...@@ -362,6 +385,7 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession { ...@@ -362,6 +385,7 @@ class TopJSDebugSession extends vscode_debugadapter.LoggingDebugSession {
} }
restartRequest(response, args) { restartRequest(response, args) {
this._restart = true;
this._runtime.quit(); this._runtime.quit();
this.terminateSession('restart'); this.terminateSession('restart');
this.spawnBackend(this._args); this.spawnBackend(this._args);
......
...@@ -277,9 +277,9 @@ class topjsRuntime extends events.EventEmitter { ...@@ -277,9 +277,9 @@ class topjsRuntime extends events.EventEmitter {
quit() { quit() {
try { try {
this.client.disconnect(); this.client.destroy('close');
} catch(e) { } catch(e) {
//this._logger.log(`disconnect: ${e}`);
} }
this._started = false; this._started = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment