提交 4285736f 编写于 作者: I isidor

debug: support canceling requests

fixes #80374
上级 f6df256c
......@@ -378,7 +378,6 @@ class ExtensionHostDebugAdapter extends AbstractDebugAdapter {
}
public stopSession(): Promise<void> {
this.cancelPending();
return Promise.resolve(this._proxy.$stopDASession(this._handle));
}
}
......@@ -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':
......@@ -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;
......@@ -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);
......
......@@ -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',
......@@ -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
}
}
......@@ -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 {
......
......@@ -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;
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册