| 41 | * @template TSessionImpl Type of the mplementation specific debug session |
| 42 | */ |
| 43 | export class Session<TSessionImpl extends IDebugSessionLike> implements IDisposable { |
| 44 | public readonly connection: DapConnection; |
| 45 | private readonly subscriptions = new DisposableList(); |
| 46 | |
| 47 | constructor( |
| 48 | public readonly debugSession: TSessionImpl, |
| 49 | transport: IDapTransport | DapConnection, |
| 50 | public readonly logger: ILogger, |
| 51 | public readonly sessionStates: SessionSubStates, |
| 52 | private readonly parent?: Session<TSessionImpl>, |
| 53 | ) { |
| 54 | if (transport instanceof DapConnection) { |
| 55 | this.connection = transport; |
| 56 | } else { |
| 57 | transport.setLogger(logger); |
| 58 | this.connection = new DapConnection(transport, this.logger); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | listenToTarget(target: ITarget) { |
| 63 | this.subscriptions.push( |
| 64 | target.onNameChanged(() => this.setName(target)), |
| 65 | this.sessionStates.onAdd( |
| 66 | ([sessionId]) => sessionId === this.debugSession.id && this.setName(target), |
| 67 | ), |
| 68 | this.sessionStates.onRemove( |
| 69 | ([sessionId]) => sessionId === this.debugSession.id && this.setName(target), |
| 70 | ), |
| 71 | ); |
| 72 | |
| 73 | this.setName(target); |
| 74 | } |
| 75 | |
| 76 | dispose() { |
| 77 | this.subscriptions.dispose(); |
| 78 | } |
| 79 | |
| 80 | private setName(target: ITarget) { |
| 81 | const substate = this.sessionStates.get(this.debugSession.id); |
| 82 | let name = target.name(); |
| 83 | if (this.parent instanceof RootSession) { |
| 84 | name = `${name} « ${this.parent.debugSession.name}`; |
| 85 | } |
| 86 | |
| 87 | this.debugSession.name = substate ? `${name} (${substate})` : name; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | export class RootSession<TSessionImpl extends IDebugSessionLike> extends Session<TSessionImpl> { |
| 92 | private _binder?: Binder; |
nothing calls this directly
no outgoing calls
no test coverage detected