MCPcopy Create free account
hub / github.com/Snapchat/Valdi / registerAutoAttach

Function registerAutoAttach

valdi/vscode_debugger/src/ui/autoAttach.ts:13–66  ·  view source on GitHub ↗
(
  context: vscode.ExtensionContext,
  delegate: DelegateLauncherFactory,
)

Source from the content-addressed store, hash-verified

11import { ProxyLogger } from '../common/logging/proxyLogger';
12
13export 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}

Callers 1

activateFunction · 0.90

Calls 6

registerCommandFunction · 0.90
acquireLauncherFunction · 0.85
terminateMethod · 0.65
pushMethod · 0.45
spawnForChildMethod · 0.45
clearVariablesMethod · 0.45

Tested by

no test coverage detected