Skip to content

Commit 22e16c7

Browse files
committed
debug: support termiante request
fixes #54384
1 parent 0344920 commit 22e16c7

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

src/vs/workbench/parts/debug/common/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface IRawSession {
115115
evaluate(args: DebugProtocol.EvaluateArguments): TPromise<DebugProtocol.EvaluateResponse>;
116116

117117
readonly capabilities: DebugProtocol.Capabilities;
118-
disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
118+
terminate(restart?: boolean): TPromise<DebugProtocol.TerminateResponse>;
119119
custom(request: string, args: any): TPromise<DebugProtocol.Response>;
120120
onDidEvent: Event<DebugProtocol.Event>;
121121
onDidInitialize: Event<DebugProtocol.InitializedEvent>;

src/vs/workbench/parts/debug/electron-browser/debugService.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,16 @@ export class DebugService implements debug.IDebugService {
167167
(<RawDebugSession>session.raw).attach(session.configuration);
168168
});
169169
} else {
170-
raw.disconnect().done(undefined, errors.onUnexpectedError);
171-
this.doCreateSession(session.raw.root, { resolved: session.configuration, unresolved: session.unresolvedConfiguration }, session.getId());
170+
const root = raw.root;
171+
raw.dispose();
172+
this.doCreateSession(root, { resolved: session.configuration, unresolved: session.unresolvedConfiguration }, session.getId());
172173
}
173174

174175
return;
175176
}
176177

177178
if (broadcast.channel === EXTENSION_TERMINATE_BROADCAST_CHANNEL) {
178-
raw.disconnect().done(undefined, errors.onUnexpectedError);
179+
raw.terminate().done(undefined, errors.onUnexpectedError);
179180
return;
180181
}
181182

@@ -292,7 +293,7 @@ export class DebugService implements debug.IDebugService {
292293
return raw.configurationDone().done(null, e => {
293294
// Disconnect the debug session on configuration done error #10596
294295
if (raw) {
295-
raw.disconnect().done(null, errors.onUnexpectedError);
296+
raw.dispose();
296297
}
297298
this.notificationService.error(e.message);
298299
});
@@ -342,7 +343,7 @@ export class DebugService implements debug.IDebugService {
342343
if (event.body && event.body.restart && session) {
343344
this.restartSession(session, event.body.restart).done(null, err => this.notificationService.error(err.message));
344345
} else {
345-
raw.disconnect().done(null, errors.onUnexpectedError);
346+
raw.dispose();
346347
}
347348
}
348349
}));
@@ -975,7 +976,7 @@ export class DebugService implements debug.IDebugService {
975976
this.telemetryService.publicLog('debugMisconfiguration', { type: resolved ? resolved.type : undefined, error: errorMessage });
976977
this.updateStateAndEmit(raw.getId(), debug.State.Inactive);
977978
if (!raw.disconnected) {
978-
raw.disconnect().done(null, errors.onUnexpectedError);
979+
raw.dispose();
979980
} else if (session) {
980981
this.model.removeSession(session.getId());
981982
}
@@ -1115,7 +1116,7 @@ export class DebugService implements debug.IDebugService {
11151116
// Do not run preLaunch and postDebug tasks for automatic restarts
11161117
this.skipRunningTask = !!restartData;
11171118

1118-
return session.raw.disconnect(true).then(() => {
1119+
return session.raw.terminate(true).then(() => {
11191120
if (strings.equalsIgnoreCase(session.configuration.type, 'extensionHost') && session.raw.root) {
11201121
return this.broadcastService.broadcast({
11211122
channel: EXTENSION_RELOAD_BROADCAST_CHANNEL,
@@ -1157,12 +1158,12 @@ export class DebugService implements debug.IDebugService {
11571158

11581159
public stopSession(session: debug.ISession): TPromise<any> {
11591160
if (session) {
1160-
return session.raw.disconnect(false, true);
1161+
return session.raw.terminate();
11611162
}
11621163

11631164
const sessions = this.model.getSessions();
11641165
if (sessions.length) {
1165-
return TPromise.join(sessions.map(s => s.raw.disconnect(false, true)));
1166+
return TPromise.join(sessions.map(s => s.raw.terminate(false)));
11661167
}
11671168

11681169
this.sessionStates.clear();

src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class RawDebugSession implements debug.IRawSession {
4343
private cachedInitServerP: TPromise<void>;
4444
private startTime: number;
4545
public disconnected: boolean;
46+
private terminated: boolean;
4647
private sentPromises: TPromise<DebugProtocol.Response>[];
4748
private _capabilities: DebugProtocol.Capabilities;
4849
private allThreadsContinued: boolean;
@@ -339,24 +340,13 @@ export class RawDebugSession implements debug.IRawSession {
339340
return this.send<DebugProtocol.CompletionsResponse>('completions', args);
340341
}
341342

342-
public disconnect(restart = false, force = false): TPromise<DebugProtocol.DisconnectResponse> {
343-
if (this.disconnected && force) {
344-
return this.stopServer();
345-
}
346-
347-
// Cancel all sent promises on disconnect so debug trees are not left in a broken state #3666.
348-
// Give a 1s timeout to give a chance for some promises to complete.
349-
setTimeout(() => {
350-
this.sentPromises.forEach(p => p && p.cancel());
351-
this.sentPromises = [];
352-
}, 1000);
353-
354-
if (this.debugAdapter && !this.disconnected) {
355-
// point of no return: from now on don't report any errors
356-
this.disconnected = true;
357-
return this.send('disconnect', { restart }, false).then(() => this.stopServer(), () => this.stopServer());
343+
public terminate(restart = false): TPromise<DebugProtocol.TerminateResponse> {
344+
if (this.capabilities.supportsTerminateRequest && !this.terminated) {
345+
this.terminated = true;
346+
return this.send('terminate', { restart });
358347
}
359348

349+
this.dispose(restart);
360350
return TPromise.as(null);
361351
}
362352

@@ -483,6 +473,26 @@ export class RawDebugSession implements debug.IRawSession {
483473
});
484474
}
485475

476+
public dispose(restart = false): void {
477+
if (this.disconnected) {
478+
this.stopServer().done(undefined, errors.onUnexpectedError);
479+
} else {
480+
481+
// Cancel all sent promises on disconnect so debug trees are not left in a broken state #3666.
482+
// Give a 1s timeout to give a chance for some promises to complete.
483+
setTimeout(() => {
484+
this.sentPromises.forEach(p => p && p.cancel());
485+
this.sentPromises = [];
486+
}, 1000);
487+
488+
if (this.debugAdapter && !this.disconnected) {
489+
// point of no return: from now on don't report any errors
490+
this.disconnected = true;
491+
this.send('disconnect', { restart }, false).then(() => this.stopServer(), () => this.stopServer()).done(undefined, errors.onUnexpectedError);
492+
}
493+
}
494+
}
495+
486496
private stopServer(): TPromise<any> {
487497

488498
if (/* this.socket !== null */ this.debugAdapter instanceof SocketDebugAdapter) {

src/vs/workbench/parts/debug/test/common/mockDebug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class MockSession implements IRawSession {
186186
return TPromise.as(null);
187187
}
188188

189-
public disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse> {
189+
public terminate(restart = false): TPromise<DebugProtocol.TerminateResponse> {
190190
return TPromise.as(null);
191191
}
192192

0 commit comments

Comments
 (0)