private async attachDebugger()

in src/test-runner/run-tracker.ts [260:307]


  private async attachDebugger(endpoint: {
    host: string
    port: number
  }): Promise<void> {
    if (!this.debugInfo?.launchConfig) return

    const endpointKey = `${endpoint.host}:${endpoint.port}`
    if (this.lastAttachedEndpoint === endpointKey) return
    this.lastAttachedEndpoint = endpointKey

    this.run.appendOutput(
      `Debug endpoint detected: ${endpoint.host}:${endpoint.port}\r\n`
    )

    const session = vscode.debug.activeDebugSession
    if (session) {
      try {
        await session.customRequest('continue', {threadId: 1})
      } catch {
        this.run.appendOutput(
          'Unable to resume active debug session for reattach. Keeping current session.\r\n'
        )
        this.lastAttachedEndpoint = undefined
        return
      }
      await vscode.debug.stopDebugging(session)
    }

    this.run.appendOutput(
      `Attaching debugger to ${endpoint.host}:${endpoint.port} [Launch config: '${this.debugInfo.launchConfig.name}']\r\n`
    )

    const debugConfig = {...this.debugInfo.launchConfig}
    debugConfig.port = endpoint.port
    debugConfig.address = endpoint.host
    if (this.debugInfo.localRoot && this.debugInfo.remoteRoot) {
      debugConfig.localRoot = this.debugInfo.localRoot
      debugConfig.remoteRoot = this.debugInfo.remoteRoot
      this.run.appendOutput(
        `Debug paths:\r\n  localRoot: ${debugConfig.localRoot}\r\n  remoteRoot: ${debugConfig.remoteRoot}\r\n`
      )
    }

    await vscode.debug.startDebugging(
      vscode.workspace.workspaceFolders?.[0],
      debugConfig
    )
  }