MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / initDebugger

Function initDebugger

src/debug/dart_debug_impl.ts:231–367  ·  view source on GitHub ↗
(uri: string)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 13

sendEventMethod · 0.80
onLoggingMethod · 0.80
onOpenMethod · 0.80
getVersionMethod · 0.80
getVMMethod · 0.80
getIsolateMethod · 0.80
loadMethod · 0.80
registerThreadMethod · 0.80
endProgressMethod · 0.80
onCloseMethod · 0.80
logMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected