( context: vscode.ExtensionContext, delegate: DelegateLauncherFactory, )
| 11 | import { ProxyLogger } from '../common/logging/proxyLogger'; |
| 12 | |
| 13 | export function registerAutoAttach( |
| 14 | context: vscode.ExtensionContext, |
| 15 | delegate: DelegateLauncherFactory, |
| 16 | ) { |
| 17 | let launcher: Promise<AutoAttachLauncher> | undefined; |
| 18 | let disposeTimeout: NodeJS.Timeout | undefined; |
| 19 | |
| 20 | const acquireLauncher = () => { |
| 21 | if (launcher) { |
| 22 | return launcher; |
| 23 | } |
| 24 | |
| 25 | launcher = (async () => { |
| 26 | const inst = new AutoAttachLauncher(new NodeBinaryProvider(), new ProxyLogger(), context, fs); |
| 27 | await launchVirtualTerminalParent(delegate, inst); |
| 28 | |
| 29 | inst.onTargetListChanged(() => { |
| 30 | if (inst.targetList().length === 0 && !disposeTimeout) { |
| 31 | disposeTimeout = setTimeout(() => { |
| 32 | launcher = undefined; |
| 33 | inst.terminate(); |
| 34 | }, 5 * 60 * 1000); |
| 35 | } else if (disposeTimeout) { |
| 36 | clearTimeout(disposeTimeout); |
| 37 | disposeTimeout = undefined; |
| 38 | } |
| 39 | }); |
| 40 | |
| 41 | return inst; |
| 42 | })(); |
| 43 | |
| 44 | return launcher; |
| 45 | }; |
| 46 | |
| 47 | context.subscriptions.push( |
| 48 | registerCommand(vscode.commands, Commands.AutoAttachSetVariables, async () => { |
| 49 | const launcher = await acquireLauncher(); |
| 50 | return { ipcAddress: launcher.deferredSocketName as string }; |
| 51 | }), |
| 52 | registerCommand(vscode.commands, Commands.AutoAttachToProcess, async info => { |
| 53 | const launcher = await acquireLauncher(); |
| 54 | launcher.spawnForChild(info); |
| 55 | }), |
| 56 | registerCommand(vscode.commands, Commands.AutoAttachClearVariables, async () => { |
| 57 | AutoAttachLauncher.clearVariables(context); |
| 58 | |
| 59 | const inst = await launcher; |
| 60 | if (inst) { |
| 61 | inst.terminate(); |
| 62 | launcher = undefined; |
| 63 | } |
| 64 | }), |
| 65 | ); |
| 66 | } |
no test coverage detected