MCPcopy
hub / github.com/microsoft/vscode-js-debug / collectInitialize

Function collectInitialize

src/dapDebugServer.ts:51–130  ·  view source on GitHub ↗

* 'Collects' DAP calls made until the launch/attach request comes in, and * returns a promise for the DA to resolve when the launch is processed. * * This is needed since until the 'launch' comes in, we don't know what session * the incoming connection refers to.

(dap: Dap.Api)

Source from the content-addressed store, hash-verified

49 * the incoming connection refers to.
50 */
51function collectInitialize(dap: Dap.Api) {
52 let setExceptionBreakpointsParams: Dap.SetExceptionBreakpointsParams | undefined;
53 const setBreakpointsParams: { params: Dap.SetBreakpointsParams; ids: number[] }[] = [];
54 let customBreakpoints: string[] = [];
55 let xhrBreakpoints: string[] = [];
56 const configurationDone = getDeferred<void>();
57 let lastBreakpointId = 0;
58 let initializeParams: Dap.InitializeParams;
59
60 dap.on('setBreakpoints', async params => {
61 const ids = params.breakpoints?.map(() => ++lastBreakpointId) ?? [];
62 setBreakpointsParams.push({ params, ids });
63 const breakpoints = ids.map(id => ({
64 id,
65 verified: false,
66 message: l10n.t('breakpoint.provisionalBreakpoint', `Unbound breakpoint`),
67 })); // TODO: Put a useful message here
68 return { breakpoints };
69 });
70
71 dap.on('setExceptionBreakpoints', async params => {
72 setExceptionBreakpointsParams = params;
73 return {};
74 });
75
76 dap.on('setCustomBreakpoints', async params => {
77 customBreakpoints = params.ids;
78 xhrBreakpoints = params.xhr;
79 return {};
80 });
81
82 dap.on('configurationDone', async () => {
83 configurationDone.resolve();
84 return {};
85 });
86
87 dap.on('threads', async () => {
88 return { threads: [] };
89 });
90
91 dap.on('loadedSources', async () => {
92 return { sources: [] };
93 });
94
95 dap.on('initialize', async params => {
96 initializeParams = params;
97 setTimeout(() => dap.initialized({}), 0);
98 return DebugAdapter.capabilities();
99 });
100
101 return new Promise<IInitializationCollection>(resolve => {
102 const handle = async (
103 launchParams: Dap.LaunchParams | Dap.AttachParams,
104 ): Promise<Dap.LaunchResult | Dap.AttachResult> => {
105 // By spec, clients should not call launch until after ConfigurationDone...
106 // but VS Code doesn't actually do this, and breakpoints aren't sent
107 // until ConfigurationDone happens, so make sure to wait on it.
108 await configurationDone.promise;

Callers 1

startDebugServerFunction · 0.85

Calls 8

getDeferredFunction · 0.90
mapMethod · 0.80
resolveMethod · 0.80
handleFunction · 0.70
onMethod · 0.65
pushMethod · 0.65
initializedMethod · 0.65
capabilitiesMethod · 0.65

Tested by

no test coverage detected