| 12 | */ |
| 13 | @injectable() |
| 14 | export class DebugSessionTracker implements vscode.Disposable { |
| 15 | /** |
| 16 | * Returns whether the session is a concrete debug |
| 17 | * session -- that is, not a logical session wrapper. |
| 18 | */ |
| 19 | public static isConcreteSession(session: vscode.DebugSession) { |
| 20 | return !!session.configuration.__pendingTargetId; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Prompts the user to pick one of the given debug sessions. Will not show |
| 25 | * a prompt if candidates < 2. |
| 26 | */ |
| 27 | public static pickSession(candidates: vscode.DebugSession[], title: string) { |
| 28 | if (candidates.length < 2) { |
| 29 | return candidates[0]; |
| 30 | } |
| 31 | |
| 32 | const qp = vscode.window.createQuickPick<{ id: string; label: string }>(); |
| 33 | qp.title = title; |
| 34 | qp.items = candidates.map(c => ({ label: c.name, id: c.id })); |
| 35 | qp.ignoreFocusOut = true; |
| 36 | |
| 37 | return new Promise<vscode.DebugSession | undefined>(resolve => { |
| 38 | qp.onDidAccept(() => resolve(candidates.find(i => i.id === qp.selectedItems[0]?.id))); |
| 39 | qp.onDidHide(() => resolve(undefined)); |
| 40 | qp.show(); |
| 41 | }).finally(() => qp.dispose()); |
| 42 | } |
| 43 | |
| 44 | private _onSessionAddedEmitter = new vscode.EventEmitter<vscode.DebugSession>(); |
| 45 | private _onSessionEndedEmitter = new vscode.EventEmitter<vscode.DebugSession>(); |
| 46 | private _disposables: vscode.Disposable[] = []; |
| 47 | private readonly sessions = new Map<string, vscode.DebugSession>(); |
| 48 | |
| 49 | /** |
| 50 | * Fires when any new js-debug session comes in. |
| 51 | */ |
| 52 | public onSessionAdded = this._onSessionAddedEmitter.event; |
| 53 | |
| 54 | /** |
| 55 | * Fires when any js-debug session ends. |
| 56 | */ |
| 57 | public onSessionEnded = this._onSessionEndedEmitter.event; |
| 58 | |
| 59 | /** |
| 60 | * Gets whether there's any active JS debug session. |
| 61 | */ |
| 62 | public get isDebugging() { |
| 63 | return this.sessions.size > 0; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the session with the given ID. |
| 68 | */ |
| 69 | public getById(id: string) { |
| 70 | return this.sessions.get(id); |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected