(public readonly debuggerType: DebuggerType, daArgs: DebugClientArgs, private readonly debugCommands: DebugCommandHandler, readonly testCoordinator: TestSessionCoordinator | undefined, private readonly debugTrackerFactories: DebugAdapterTrackerFactory[], private readonly dartCapabitilies: DartCapabilities)
| 26 | public hasTerminated = false; |
| 27 | |
| 28 | constructor(public readonly debuggerType: DebuggerType, daArgs: DebugClientArgs, private readonly debugCommands: DebugCommandHandler, readonly testCoordinator: TestSessionCoordinator | undefined, private readonly debugTrackerFactories: DebugAdapterTrackerFactory[], private readonly dartCapabitilies: DartCapabilities) { |
| 29 | const useShell = daArgs.runtime?.endsWith(".sh") || daArgs.runtime?.endsWith(".bat"); |
| 30 | const runtime = useShell ? `"${daArgs.runtime}"` : daArgs.runtime; |
| 31 | const executable = useShell ? `"${daArgs.executable}"` : daArgs.executable; |
| 32 | const args = useShell ? daArgs.args?.map((a) => `"${a}"`) : daArgs.args; |
| 33 | super(runtime, executable, args, "dart", { shell: useShell ? true : undefined }, true); |
| 34 | |
| 35 | // Tests can attach a lot of listeners, so bump the threshold for warning. |
| 36 | this.setMaxListeners(30); |
| 37 | |
| 38 | // HACK to handle incoming requests.. |
| 39 | const me = (this as unknown as { dispatch(body: string): void }); |
| 40 | const oldDispatch = me.dispatch.bind(this); |
| 41 | me.dispatch = (body: string) => { |
| 42 | const rawData = JSON.parse(body); |
| 43 | for (const tracker of this.currentTrackers) { |
| 44 | if (tracker.onDidSendMessage) |
| 45 | tracker.onDidSendMessage(rawData); |
| 46 | } |
| 47 | if (rawData.type === "request") { |
| 48 | const request = rawData as DebugProtocol.Request; |
| 49 | this.emit(request.command, request); |
| 50 | } else { |
| 51 | oldDispatch(body); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | // Set up handlers for any custom events our tests may rely on (can't find |
| 56 | // a way to just do them all 🤷♂️). |
| 57 | customEventsToForward.forEach((evt) => this.on(evt, (e: DebugSessionCustomEvent) => this.handleCustomEvent(e))); |
| 58 | |
| 59 | // Log important events to make troubleshooting tests easier. |
| 60 | this.on("output", (event) => { |
| 61 | logger.info(`[${event.body.category}] ${event.body.output}`); |
| 62 | }); |
| 63 | this.on("terminated", () => { |
| 64 | this.hasTerminated = true; |
| 65 | logger.info(`[terminated]`); |
| 66 | }); |
| 67 | this.on("stopped", (event: DebugProtocol.StoppedEvent) => { |
| 68 | logger.info(`[stopped] ${event.body.reason}`); |
| 69 | }); |
| 70 | this.on("initialized", () => { |
| 71 | logger.info(`[initialized]`); |
| 72 | }); |
| 73 | this.on("runInTerminal", (request: DebugProtocol.RunInTerminalRequest) => { |
| 74 | logger.info(`[runInTerminal]`); |
| 75 | |
| 76 | const terminal = window.createTerminal({ |
| 77 | cwd: request.arguments.cwd, |
| 78 | env: request.arguments.env, |
| 79 | name: request.arguments.title, |
| 80 | shellArgs: request.arguments.args.slice(1), |
| 81 | shellPath: request.arguments.args[0], |
| 82 | }); |
| 83 | |
| 84 | terminal.show(); |
| 85 | void terminal.processId.then((pid) => { |
nothing calls this directly
no test coverage detected