Skip to content

Commit

Permalink
debug: support canceling requests
Browse files Browse the repository at this point in the history
fixes #80374
  • Loading branch information
isidorn committed Sep 12, 2019
1 parent f6df256 commit 4285736
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/vs/workbench/api/browser/mainThreadDebugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ class ExtensionHostDebugAdapter extends AbstractDebugAdapter {
}

public stopSession(): Promise<void> {
this.cancelPending();
return Promise.resolve(this._proxy.$stopDASession(this._handle));
}
}
20 changes: 19 additions & 1 deletion src/vs/workbench/contrib/debug/browser/rawDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export class RawDebugSession implements IDisposable {
}
}));

this.toDispose.push(this.onDidContinued(() => this.cancelPendingRequests()));

this.debugAdapter.onEvent(event => {
switch (event.event) {
case 'initialized':
Expand Down Expand Up @@ -466,13 +468,16 @@ export class RawDebugSession implements IDisposable {
return Promise.reject(new Error('goto is not supported'));
}

cancel(args: DebugProtocol.CancelArguments): Promise<DebugProtocol.CancelResponse> {
return this.send('cancel', args);
}

custom(request: string, args: any): Promise<DebugProtocol.Response> {
return this.send(request, args);
}

//---- private


private shutdown(error?: Error, restart = false): Promise<any> {
if (!this.inShutdown) {
this.inShutdown = true;
Expand All @@ -489,10 +494,23 @@ export class RawDebugSession implements IDisposable {
return Promise.resolve(undefined);
}

private cancelPendingRequests(): void {
if (this.debugAdapter) {
if (this.capabilities.supportsCancelRequest) {
this.debugAdapter.getPendingRequestIds().forEach(requestId => {
this.cancel({ requestId });
});
} else {
this.debugAdapter.cancelPendingRequests();
}
}
}

private stopAdapter(error?: Error): Promise<any> {
if (this.debugAdapter) {
const da = this.debugAdapter;
this.debugAdapter = null;
this.cancelPendingRequests();
return da.stopSession().then(_ => {
this.debugAdapterStopped = true;
this.fireAdapterExitEvent(error);
Expand Down
12 changes: 8 additions & 4 deletions src/vs/workbench/contrib/debug/common/abstractDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ export abstract class AbstractDebugAdapter implements IDebugAdapter {
this.sendMessage(message);
}

async cancelPending(): Promise<void> {
async cancelPendingRequests(): Promise<void> {
const pending = new Map<number, (e: DebugProtocol.Response) => void>();
this.pendingRequests.forEach((value, key) => pending.set(key, value));
this.pendingRequests.clear();
await timeout(1000);
await timeout(500);
pending.forEach((callback, request_seq) => {
const err: DebugProtocol.Response = {
type: 'response',
Expand All @@ -152,10 +151,15 @@ export abstract class AbstractDebugAdapter implements IDebugAdapter {
message: 'canceled'
};
callback(err);
this.pendingRequests.delete(request_seq);
});
}

getPendingRequestIds(): number[] {
return Array.from(this.pendingRequests.keys());
}

dispose(): void {
this.cancelPending();
// noop
}
}
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ export interface IDebugAdapter extends IDisposable {
sendResponse(response: DebugProtocol.Response): void;
sendRequest(command: string, args: any, clb: (result: DebugProtocol.Response) => void, timeout?: number): void;
stopSession(): Promise<void>;
cancelPendingRequests(): void;
getPendingRequestIds(): number[];
}

export interface IDebugAdapterFactory extends ITerminalLauncher {
Expand Down
6 changes: 0 additions & 6 deletions src/vs/workbench/contrib/debug/node/debugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ export class SocketDebugAdapter extends StreamDebugAdapter {

stopSession(): Promise<void> {

// Cancel all sent promises on disconnect so debug trees are not left in a broken state #3666.
this.cancelPending();

if (this.socket) {
this.socket.end();
this.socket = undefined;
Expand Down Expand Up @@ -254,9 +251,6 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter {

stopSession(): Promise<void> {

// Cancel all sent promises on disconnect so debug trees are not left in a broken state #3666.
this.cancelPending();

if (!this.serverProcess) {
return Promise.resolve(undefined);
}
Expand Down

0 comments on commit 4285736

Please sign in to comment.