* Starts a new debug adapter and sets up communication via stdin/stdout. * If a port number is specified the adapter is not launched but a connection to * a debug adapter running in server mode is established. This is useful for debugging * the adapter while running tests. For this reason all
(port?: number)
| 98 | * the adapter while running tests. For this reason all timeouts are disabled in server mode. |
| 99 | */ |
| 100 | public start(port?: number): Promise<void> { |
| 101 | |
| 102 | return new Promise<void>((resolve, reject) => { |
| 103 | if (typeof port === 'number') { |
| 104 | this._socket = net.createConnection(port, '127.0.0.1', () => { |
| 105 | this.connect(this._socket!, this._socket!); |
| 106 | resolve(); |
| 107 | }); |
| 108 | } else { |
| 109 | this._adapterProcess = cp.spawn(this._runtime!, [this._executable!, ...(this._args || [])], this._spawnOptions); |
| 110 | const sanitize = (s: string) => s.toString().replace(/\r?\n$/mg, ''); |
| 111 | this._adapterProcess.stderr!.on('data', (data: string) => { |
| 112 | if (this._enableStderr) { |
| 113 | data = sanitize(data).trim(); |
| 114 | if (data) |
| 115 | console.log(data); |
| 116 | } |
| 117 | }); |
| 118 | |
| 119 | this._adapterProcess.on('error', (err) => { |
| 120 | console.log(err); |
| 121 | reject(err); |
| 122 | }); |
| 123 | this._adapterProcess.stdin!.on('error', (err) => { |
| 124 | if (!this._adapterProcess) |
| 125 | console.info(`Ignoring error writing to stdin because shutting down: ${err}`); |
| 126 | else |
| 127 | throw err; |
| 128 | }); |
| 129 | this._adapterProcess.on('exit', (code: number, signal: string) => { |
| 130 | if (code) { |
| 131 | // done(new Error('debug adapter exit code: ' + code)); |
| 132 | } |
| 133 | }); |
| 134 | |
| 135 | this.connect(this._adapterProcess.stdout!, this._adapterProcess.stdin!); |
| 136 | resolve(); |
| 137 | } |
| 138 | }); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Shutdown the debuggee and the debug adapter (or disconnect if in server mode). |