1
>
/*---------------------------------------------------------------------------------------------
abstractDebugAdapter.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Emitter, Event } from '../../../../base/common/event.js';
7
>
import { IDebugAdapter } from './debug.js';
8
>
import { timeout } from '../../../../base/common/async.js';
9
>
import { localize } from '../../../../nls.js';
10
>
11
>
/**
12
>
* Abstract implementation of the low level API for a debug adapter.
13
>
* Missing is how this API communicates with the debug adapter.
14
>
*/
15
>
export abstract class AbstractDebugAdapter implements IDebugAdapter {
16
>
private sequence: number;
17
>
private pendingRequests = new Map<number, (e: DebugProtocol.Response) => void>();
18
>
private pendingRequestTimers = new Map<number, Timeout>();
19
>
private requestCallback: ((request: DebugProtocol.Request) => void) | undefined;
20
>
private eventCallback: ((request: DebugProtocol.Event) => void) | undefined;
21
>
private messageCallback: ((message: DebugProtocol.ProtocolMessage) => void) | undefined;
22
>
private queue: DebugProtocol.ProtocolMessage[] = [];
23
>
protected readonly _onError = new Emitter<Error>();
24
>
protected readonly _onExit = new Emitter<number | null>();
25
>
26
>
constructor() {
27
this.sequence = 1;
28
}
30
>
abstract startSession(): Promise<void>;
31
>
32
>
abstract stopSession(): Promise<void>;
33
>
34
>
abstract sendMessage(message: DebugProtocol.ProtocolMessage): void;
35
>
36
>
get onError(): Event<Error> {
37
return this._onError.event;
38
}
40
>
get onExit(): Event<number | null> {
41
return this._onExit.event;
42
}
44
>
onMessage(callback: (message: DebugProtocol.ProtocolMessage) => void): void {
45
if (this.messageCallback) {
46
this._onError.fire(new Error(`attempt to set more than one 'Message' callback`));