1import Protocol from 'devtools-protocol';
2
3import { CdpMessage, DebuggerRequest, DeviceResponse, InspectorHandler } from './types';
4import { ExpoDebuggerInfo } from '../device';
5
6/**
7 * Hermes doesn't seem to handle this request, but `locations` have to be returned.
8 * Respond with an empty location to make it "spec compliant" with Chrome DevTools.
9 */
10export class VscodeDebuggerGetPossibleBreakpointsHandler implements InspectorHandler {
11  onDebuggerMessage(
12    message: DebuggerRequest<DebuggerGetPossibleBreakpoints>,
13    { socket, debuggerType }: ExpoDebuggerInfo
14  ): boolean {
15    if (debuggerType === 'vscode' && message.method === 'Debugger.getPossibleBreakpoints') {
16      const response: DeviceResponse<DebuggerGetPossibleBreakpoints> = {
17        id: message.id,
18        result: { locations: [] },
19      };
20      socket.send(JSON.stringify(response));
21      return true;
22    }
23
24    return false;
25  }
26}
27
28/** @see https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#method-getPossibleBreakpoints */
29export type DebuggerGetPossibleBreakpoints = CdpMessage<
30  'Debugger.getPossibleBreakpoints',
31  Protocol.Debugger.GetPossibleBreakpointsRequest,
32  Protocol.Debugger.GetPossibleBreakpointsResponse
33>;
34