Skip to content

Commit

Permalink
debug: on restart, make sure to first disconnect and only then run th…
Browse files Browse the repository at this point in the history
…e prelaunch tasks

fixes #60593
  • Loading branch information
isidorn committed Oct 11, 2018
1 parent ae2f5e1 commit 812b241
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/vs/workbench/parts/debug/electron-browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,32 +547,39 @@ export class DebugService implements IDebugService {

restartSession(session: IDebugSession, restartData?: any): TPromise<any> {
return this.textFileService.saveAll().then(() => {
// Do not run preLaunch and postDebug tasks for automatic restarts
const isAutoRestart = !!restartData;
const taskThenable: Thenable<TaskRunResult> = isAutoRestart ? Promise.resolve(TaskRunResult.Success) :
this.runTask(session.root, session.configuration.postDebugTask).then(() => this.runTaskAndCheckErrors(session.root, session.configuration.preLaunchTask));

return taskThenable.then(taskRunResult => {
if (taskRunResult !== TaskRunResult.Success) {
return;
}
if (session.capabilities.supportsRestartRequest) {
return session.restart().then(() => void 0);
const runTasks: () => Thenable<TaskRunResult> = () => {
if (isAutoRestart) {
// Do not run preLaunch and postDebug tasks for automatic restarts
return Promise.resolve(TaskRunResult.Success);
}

const shouldFocus = this.viewModel.focusedSession && session.getId() === this.viewModel.focusedSession.getId();
if (isExtensionHostDebugging(session.configuration) && session.root) {
return this.broadcastService.broadcast({
channel: EXTENSION_RELOAD_BROADCAST_CHANNEL,
payload: [session.root.uri.toString()]
});
}
return this.runTask(session.root, session.configuration.postDebugTask)
.then(() => this.runTaskAndCheckErrors(session.root, session.configuration.preLaunchTask));
};

// If the restart is automatic -> disconnect, otherwise -> terminate #55064
return (isAutoRestart ? session.disconnect(true) : session.terminate(true)).then(() => {
if (session.capabilities.supportsRestartRequest) {
return runTasks().then(taskResult => taskResult === TaskRunResult.Success ? session.restart() : undefined);
}

if (isExtensionHostDebugging(session.configuration) && session.root) {
return runTasks().then(taskResult => taskResult === TaskRunResult.Success ? this.broadcastService.broadcast({
channel: EXTENSION_RELOAD_BROADCAST_CHANNEL,
payload: [session.root.uri.toString()]
}) : undefined);
}

const shouldFocus = this.viewModel.focusedSession && session.getId() === this.viewModel.focusedSession.getId();
// If the restart is automatic -> disconnect, otherwise -> terminate #55064
return (isAutoRestart ? session.disconnect(true) : session.terminate(true)).then(() => {

return new Promise<void>((c, e) => {
setTimeout(() => {
runTasks().then(taskResult => {
if (taskResult !== TaskRunResult.Success) {
return;
}

return new Promise<void>((c, e) => {
setTimeout(() => {
// Read the configuration again if a launch.json has been changed, if not just use the inmemory configuration
let needsToSubstitute = false;
let unresolved: IConfig;
Expand Down Expand Up @@ -601,8 +608,8 @@ export class DebugService implements IDebugService {
c(null);
}, err => e(err));
});
}, 300);
});
});
}, 300);
});
});
});
Expand Down

0 comments on commit 812b241

Please sign in to comment.