| 106 | } |
| 107 | |
| 108 | export class SessionManager<TSessionImpl extends IDebugSessionLike> |
| 109 | implements IDisposable, IBinderDelegate { |
| 110 | private _disposables: IDisposable[] = []; |
| 111 | private _sessions = new Map<string, Session<TSessionImpl>>(); |
| 112 | |
| 113 | private _pendingTarget = new Map<string, { target: ITarget; parent: Session<TSessionImpl> }>(); |
| 114 | private _sessionForTarget = new Map<ITarget, Promise<Session<TSessionImpl>>>(); |
| 115 | private _sessionForTargetCallbacks = new Map< |
| 116 | ITarget, |
| 117 | { fulfill: (session: Session<TSessionImpl>) => void; reject: (error: Error) => void } |
| 118 | >(); |
| 119 | |
| 120 | constructor( |
| 121 | private readonly globalContainer: Container, |
| 122 | private readonly sessionLauncher: SessionLauncher<TSessionImpl>, |
| 123 | ) {} |
| 124 | |
| 125 | public terminate(debugSession: TSessionImpl) { |
| 126 | const session = this._sessions.get(debugSession.id); |
| 127 | this._sessions.delete(debugSession.id); |
| 128 | if (session) session.dispose(); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @inheritdoc |
| 133 | */ |
| 134 | public createNewSession( |
| 135 | debugSession: TSessionImpl, |
| 136 | config: IPseudoAttachConfiguration, |
| 137 | transport: IDapTransport, |
| 138 | ): Session<TSessionImpl> { |
| 139 | let session: Session<TSessionImpl>; |
| 140 | |
| 141 | const pendingTargetId = config.__pendingTargetId; |
| 142 | if (pendingTargetId) { |
| 143 | const pending = this._pendingTarget.get(pendingTargetId); |
| 144 | if (!pending) { |
| 145 | throw new Error(`Cannot find target ${pendingTargetId}`); |
| 146 | } |
| 147 | |
| 148 | const { target, parent } = pending; |
| 149 | session = new Session<TSessionImpl>( |
| 150 | debugSession, |
| 151 | transport, |
| 152 | parent.logger, |
| 153 | parent.sessionStates, |
| 154 | ); |
| 155 | |
| 156 | this._pendingTarget.delete(pendingTargetId); |
| 157 | session.debugSession.name = target.name(); |
| 158 | session.listenToTarget(target); |
| 159 | const callbacks = this._sessionForTargetCallbacks.get(target); |
| 160 | this._sessionForTargetCallbacks.delete(target); |
| 161 | callbacks?.fulfill?.(session); |
| 162 | } else { |
| 163 | const root = new RootSession( |
| 164 | debugSession, |
| 165 | transport, |
nothing calls this directly
no outgoing calls
no test coverage detected