(uri: string)
| 229 | } |
| 230 | |
| 231 | protected async initDebugger(uri: string): Promise<void> { |
| 232 | // On some cloud providers we get an IPv6 loopback which fails to connect |
| 233 | // correctly. Assume that if we get this, it's safe to use the "localhost" hostname. |
| 234 | uri = uri.replace("[::]", "localhost"); |
| 235 | this.log(`Initialising debugger for ${uri}`); |
| 236 | // Send the uri back to the editor so it can be used to launch browsers etc. |
| 237 | let browserFriendlyUri = uri; |
| 238 | if (browserFriendlyUri.endsWith("/ws")) |
| 239 | browserFriendlyUri = uri.substring(0, uri.length - 2); |
| 240 | if (browserFriendlyUri.startsWith("ws:")) |
| 241 | browserFriendlyUri = "http:" + browserFriendlyUri.substring(3); |
| 242 | |
| 243 | let vmServiceUri = uri; |
| 244 | if (vmServiceUri.startsWith("http:")) |
| 245 | vmServiceUri = "ws:" + browserFriendlyUri.substring(5); |
| 246 | |
| 247 | const evt = new Event("dart.debuggerUris", { |
| 248 | vmServiceUri: vmServiceUri.toString(), |
| 249 | }); |
| 250 | this.sendEvent(evt); |
| 251 | |
| 252 | if (!this.shouldConnectDebugger) |
| 253 | return; |
| 254 | |
| 255 | this.debuggerInit = new Promise<void>((resolve, reject) => { |
| 256 | this.log(`Connecting to VM Service at ${uri}`); |
| 257 | this.logToUser(`Connecting to VM Service at ${uri}\n`); |
| 258 | this.vmService = new VmServiceConnection(uri); |
| 259 | this.vmService.onLogging((message) => this.log(message)); |
| 260 | // TODO: Extract some code here and change to async/await. This is |
| 261 | // super confusing, for ex. it's not clear the resolve() inside onOpen |
| 262 | // fires immediately opon opening, not when all the code in the getVM |
| 263 | // callback fires (so it may as well have come first - unless it's |
| 264 | // a bug/race and it was supposed to be after all the setup!). |
| 265 | this.vmService.onOpen(async () => { |
| 266 | if (!this.vmService) |
| 267 | return; |
| 268 | |
| 269 | // Read the version to update capabilities before doing anything else. |
| 270 | await this.vmService.getVersion().then(async (versionResult) => { |
| 271 | const version: Version = versionResult.result as Version; |
| 272 | this.vmServiceCapabilities.version = `${version.major}.${version.minor}.0`; |
| 273 | |
| 274 | if (!this.vmService) |
| 275 | return; |
| 276 | |
| 277 | // Subscribe to streams before we get a list of active isolates, otherwise we could have a race |
| 278 | // between getting the list and then starting to listen for events. |
| 279 | await this.subscribeToStreams(); |
| 280 | |
| 281 | await this.vmService.getVM().then(async (vmResult): Promise<void> => { |
| 282 | if (!this.vmService) |
| 283 | return; |
| 284 | const vm: VM = vmResult.result as VM; |
| 285 | |
| 286 | // If we own this process (we launched it, didn't attach) and the PID we get from the VM service is different, then |
| 287 | // we should keep a ref to this process to terminate when we quit. This avoids issues where our process is a shell |
| 288 | // (we use shell execute to fix issues on Windows) and the kill signal isn't passed on correctly. |
nothing calls this directly
no test coverage detected