MCPcopy
hub / github.com/microsoft/vscode-js-debug / getOrLaunchSession

Method getOrLaunchSession

src/sessionManager.ts:211–253  ·  view source on GitHub ↗

* Creates a debug session for the given target.

(target: ITarget)

Source from the content-addressed store, hash-verified

209 * Creates a debug session for the given target.
210 */
211 public getOrLaunchSession(target: ITarget): Promise<Session<TSessionImpl>> {
212 const existingSession = this._sessionForTarget.get(target);
213 if (existingSession) {
214 return existingSession;
215 }
216
217 const newSession = new Promise<Session<TSessionImpl>>(async (fulfill, reject) => {
218 let parentSession: Session<TSessionImpl> | undefined;
219 const parentTarget = target.parent();
220 if (parentTarget) {
221 parentSession = await this.getOrLaunchSession(parentTarget);
222 } else {
223 parentSession = this._sessions.get(target.targetOrigin().id);
224 }
225
226 if (!parentSession) {
227 throw new Error('Expected to get a parent debug session for target');
228 }
229
230 this._pendingTarget.set(target.id(), { target, parent: parentSession });
231 this._sessionForTargetCallbacks.set(target, { fulfill, reject });
232
233 const parentConfig = parentSession.debugSession.configuration as IMandatedConfiguration;
234 const config: IPseudoAttachConfiguration = {
235 // see https://github.com/microsoft/vscode/issues/98993
236 type: parentConfig.type === DebugType.ExtensionHost
237 ? DebugType.Chrome
238 : (parentConfig.type as DebugType),
239 name: target.name(),
240 request: parentSession.debugSession.configuration.request as 'attach' | 'launch',
241 __pendingTargetId: target.id(),
242 internalConsoleOptions: parentConfig.internalConsoleOptions,
243 // fix for https://github.com/microsoft/vscode/issues/102296
244 preRestartTask: parentConfig.preRestartTask ?? parentConfig.postDebugTask,
245 postRestartTask: parentConfig.postRestartTask ?? parentConfig.preLaunchTask,
246 };
247
248 this.sessionLauncher.launch(parentSession, target, config);
249 });
250
251 this._sessionForTarget.set(target, newSession);
252 return newSession;
253 }
254
255 /**
256 * @inheritdoc

Callers 1

acquireDapMethod · 0.95

Calls 7

getMethod · 0.65
parentMethod · 0.65
targetOriginMethod · 0.65
setMethod · 0.65
idMethod · 0.65
nameMethod · 0.65
launchMethod · 0.65

Tested by

no test coverage detected