@codingame/monaco-vscode-debug-service-override 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/debug.js +4 -4
  2. package/external/rollup-plugin-styles/dist/runtime/inject-css.js +3 -0
  3. package/external/tslib/tslib.es6.js +11 -0
  4. package/override/vs/platform/dialogs/common/dialogs.js +10 -0
  5. package/package.json +2 -2
  6. package/vscode/src/vs/platform/debug/common/extensionHostDebugIpc.js +73 -0
  7. package/vscode/src/vs/workbench/contrib/debug/browser/callStackView.js +1026 -0
  8. package/vscode/src/vs/workbench/contrib/debug/browser/debug.contribution.js +1004 -0
  9. package/vscode/src/vs/workbench/contrib/debug/browser/debugANSIHandling.js +347 -0
  10. package/vscode/src/vs/workbench/contrib/debug/browser/debugActionViewItems.js +337 -0
  11. package/vscode/src/vs/workbench/contrib/debug/browser/debugAdapterManager.js +432 -0
  12. package/vscode/src/vs/workbench/contrib/debug/browser/debugCommands.js +1039 -0
  13. package/vscode/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.js +649 -0
  14. package/vscode/src/vs/workbench/contrib/debug/browser/debugConsoleQuickAccess.js +64 -0
  15. package/vscode/src/vs/workbench/contrib/debug/browser/debugEditorActions.js +636 -0
  16. package/vscode/src/vs/workbench/contrib/debug/browser/debugEditorContribution.js +740 -0
  17. package/vscode/src/vs/workbench/contrib/debug/browser/debugHover.js +408 -0
  18. package/vscode/src/vs/workbench/contrib/debug/browser/debugMemory.js +206 -0
  19. package/vscode/src/vs/workbench/contrib/debug/browser/debugProgress.js +80 -0
  20. package/vscode/src/vs/workbench/contrib/debug/browser/debugQuickAccess.js +169 -0
  21. package/vscode/src/vs/workbench/contrib/debug/browser/debugService.js +1271 -0
  22. package/vscode/src/vs/workbench/contrib/debug/browser/debugSession.js +1330 -0
  23. package/vscode/src/vs/workbench/contrib/debug/browser/debugSessionPicker.js +115 -0
  24. package/vscode/src/vs/workbench/contrib/debug/browser/debugStatus.js +77 -0
  25. package/vscode/src/vs/workbench/contrib/debug/browser/debugTaskRunner.js +307 -0
  26. package/vscode/src/vs/workbench/contrib/debug/browser/debugTitle.js +31 -0
  27. package/vscode/src/vs/workbench/contrib/debug/browser/debugToolBar.js +387 -0
  28. package/vscode/src/vs/workbench/contrib/debug/browser/debugViewlet.js +267 -0
  29. package/vscode/src/vs/workbench/contrib/debug/browser/disassemblyView.js +817 -0
  30. package/vscode/src/vs/workbench/contrib/debug/browser/exceptionWidget.js +131 -0
  31. package/vscode/src/vs/workbench/contrib/debug/browser/extensionHostDebugService.js +142 -0
  32. package/vscode/src/vs/workbench/contrib/debug/browser/linkDetector.js +262 -0
  33. package/vscode/src/vs/workbench/contrib/debug/browser/loadedScriptsView.js +669 -0
  34. package/vscode/src/vs/workbench/contrib/debug/browser/media/debug.contribution.css.js +6 -0
  35. package/vscode/src/vs/workbench/contrib/debug/browser/media/debugHover.css.js +6 -0
  36. package/vscode/src/vs/workbench/contrib/debug/browser/media/debugToolBar.css.js +6 -0
  37. package/vscode/src/vs/workbench/contrib/debug/browser/media/debugViewlet.css.js +6 -0
  38. package/vscode/src/vs/workbench/contrib/debug/browser/media/exceptionWidget.css.js +6 -0
  39. package/vscode/src/vs/workbench/contrib/debug/browser/media/repl.css.js +6 -0
  40. package/vscode/src/vs/workbench/contrib/debug/browser/rawDebugSession.js +709 -0
  41. package/vscode/src/vs/workbench/contrib/debug/browser/repl.js +1002 -0
  42. package/vscode/src/vs/workbench/contrib/debug/browser/replFilter.js +48 -0
  43. package/vscode/src/vs/workbench/contrib/debug/browser/replViewer.js +352 -0
  44. package/vscode/src/vs/workbench/contrib/debug/browser/statusbarColorProvider.js +129 -0
  45. package/vscode/src/vs/workbench/contrib/debug/browser/variablesView.js +734 -0
  46. package/vscode/src/vs/workbench/contrib/debug/browser/watchExpressionsView.js +501 -0
  47. package/vscode/src/vs/workbench/contrib/debug/browser/welcomeView.js +162 -0
  48. package/vscode/src/vs/workbench/contrib/debug/common/breakpoints.js +21 -0
  49. package/vscode/src/vs/workbench/contrib/debug/common/debugCompoundRoot.js +17 -0
  50. package/vscode/src/vs/workbench/contrib/debug/common/debugContentProvider.js +110 -0
  51. package/vscode/src/vs/workbench/contrib/debug/common/debugLifecycle.js +62 -0
  52. package/vscode/src/vs/workbench/contrib/debug/common/debugSchemas.js +460 -0
  53. package/vscode/src/vs/workbench/contrib/debug/common/debugStorage.js +166 -0
  54. package/vscode/src/vs/workbench/contrib/debug/common/debugTelemetry.js +36 -0
  55. package/vscode/src/vs/workbench/contrib/debug/common/debugViewModel.js +150 -0
  56. package/vscode/src/vs/workbench/contrib/debug/common/debugger.js +289 -0
  57. package/vscode/src/vs/workbench/contrib/debug/common/loadedScriptsPicker.js +87 -0
  58. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableCommands.js +64 -0
  59. package/vscode/src/vs/workbench/services/configurationResolver/browser/baseConfigurationResolverService.js +311 -0
  60. package/vscode/src/vs/workbench/services/configurationResolver/browser/configurationResolverService.js +29 -0
@@ -0,0 +1,1330 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { status } from 'vscode/vscode/vs/base/browser/ui/aria/aria';
3
+ import { distinct } from 'vscode/vscode/vs/base/common/arrays';
4
+ import { RunOnceScheduler, raceTimeout, Queue } from 'vscode/vscode/vs/base/common/async';
5
+ import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
6
+ import { canceled } from 'vscode/vscode/vs/base/common/errors';
7
+ import { Emitter } from 'vscode/vscode/vs/base/common/event';
8
+ import { normalizeDriveLetter } from 'vscode/vscode/vs/base/common/labels';
9
+ import { DisposableStore, MutableDisposable, dispose, Disposable, DisposableMap } from 'vscode/vscode/vs/base/common/lifecycle';
10
+ import { mixin } from 'vscode/vscode/vs/base/common/objects';
11
+ import { language } from 'vscode/vscode/vs/base/common/platform';
12
+ import { basenameOrAuthority } from 'vscode/vscode/vs/base/common/resources';
13
+ import Severity$1 from 'vscode/vscode/vs/base/common/severity';
14
+ import { URI } from 'vscode/vscode/vs/base/common/uri';
15
+ import { generateUuid } from 'vscode/vscode/vs/base/common/uuid';
16
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
17
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
18
+ import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
19
+ import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
20
+ import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
21
+ import { IProductService } from 'vscode/vscode/vs/platform/product/common/productService';
22
+ import { ITelemetryService, ICustomEndpointTelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
23
+ import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity';
24
+ import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace';
25
+ import { RawDebugSession } from './rawDebugSession.js';
26
+ import { IDebugService, VIEWLET_ID } from 'vscode/vscode/vs/workbench/contrib/debug/common/debug';
27
+ import { MemoryRegion, ExpressionContainer, Thread } from 'vscode/vscode/vs/workbench/contrib/debug/common/debugModel';
28
+ import { Source } from 'vscode/vscode/vs/workbench/contrib/debug/common/debugSource';
29
+ import { filterExceptionsFromTelemetry } from 'vscode/vscode/vs/workbench/contrib/debug/common/debugUtils';
30
+ import { ReplModel } from 'vscode/vscode/vs/workbench/contrib/debug/common/replModel';
31
+ import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
32
+ import { IHostService } from 'vscode/vscode/vs/workbench/services/host/browser/host';
33
+ import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
34
+ import { IPaneCompositePartService } from 'vscode/vscode/vs/workbench/services/panecomposite/browser/panecomposite';
35
+ import { getActiveWindow } from 'vscode/vscode/vs/base/browser/dom';
36
+ import { mainWindow } from 'vscode/vscode/vs/base/browser/window';
37
+ import { isDefined } from 'vscode/vscode/vs/base/common/types';
38
+
39
+ const TRIGGERED_BREAKPOINT_MAX_DELAY = 1500;
40
+ let DebugSession = class DebugSession {
41
+ constructor(id, _configuration, root, model, options, debugService, telemetryService, hostService, configurationService, paneCompositeService, workspaceContextService, productService, notificationService, lifecycleService, uriIdentityService, instantiationService, customEndpointTelemetryService, workbenchEnvironmentService, logService) {
42
+ this.id = id;
43
+ this._configuration = _configuration;
44
+ this.root = root;
45
+ this.model = model;
46
+ this.debugService = debugService;
47
+ this.telemetryService = telemetryService;
48
+ this.hostService = hostService;
49
+ this.configurationService = configurationService;
50
+ this.paneCompositeService = paneCompositeService;
51
+ this.workspaceContextService = workspaceContextService;
52
+ this.productService = productService;
53
+ this.notificationService = notificationService;
54
+ this.uriIdentityService = uriIdentityService;
55
+ this.instantiationService = instantiationService;
56
+ this.customEndpointTelemetryService = customEndpointTelemetryService;
57
+ this.workbenchEnvironmentService = workbenchEnvironmentService;
58
+ this.logService = logService;
59
+ this.initialized = false;
60
+ this.sources = ( new Map());
61
+ this.threads = ( new Map());
62
+ this.threadIds = [];
63
+ this.cancellationMap = ( new Map());
64
+ this.rawListeners = ( new DisposableStore());
65
+ this.globalDisposables = ( new DisposableStore());
66
+ this.stoppedDetails = [];
67
+ this.statusQueue = this.rawListeners.add(( new ThreadStatusScheduler()));
68
+ this._onDidChangeState = ( new Emitter());
69
+ this._onDidEndAdapter = ( new Emitter());
70
+ this._onDidLoadedSource = ( new Emitter());
71
+ this._onDidCustomEvent = ( new Emitter());
72
+ this._onDidProgressStart = ( new Emitter());
73
+ this._onDidProgressUpdate = ( new Emitter());
74
+ this._onDidProgressEnd = ( new Emitter());
75
+ this._onDidInvalidMemory = ( new Emitter());
76
+ this._onDidChangeREPLElements = ( new Emitter());
77
+ this._onDidChangeName = ( new Emitter());
78
+ this._options = options || {};
79
+ this.parentSession = this._options.parentSession;
80
+ if (this.hasSeparateRepl()) {
81
+ this.repl = ( new ReplModel(this.configurationService));
82
+ }
83
+ else {
84
+ this.repl = this.parentSession.repl;
85
+ }
86
+ const toDispose = this.globalDisposables;
87
+ const replListener = toDispose.add(( new MutableDisposable()));
88
+ replListener.value = this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire());
89
+ if (lifecycleService) {
90
+ toDispose.add(lifecycleService.onWillShutdown(() => {
91
+ this.shutdown();
92
+ dispose(toDispose);
93
+ }));
94
+ }
95
+ const compoundRoot = this._options.compoundRoot;
96
+ if (compoundRoot) {
97
+ toDispose.add(compoundRoot.onDidSessionStop(() => this.terminate()));
98
+ }
99
+ this.passFocusScheduler = ( new RunOnceScheduler(() => {
100
+ if (( this.debugService.getModel().getSessions().some(s => s.state === 2 )) || ( this.getAllThreads().some(t => t.stopped))) {
101
+ if (typeof this.lastContinuedThreadId === 'number') {
102
+ const thread = this.debugService.getViewModel().focusedThread;
103
+ if (thread && thread.threadId === this.lastContinuedThreadId && !thread.stopped) {
104
+ const toFocusThreadId = this.getStoppedDetails()?.threadId;
105
+ const toFocusThread = typeof toFocusThreadId === 'number' ? this.getThread(toFocusThreadId) : undefined;
106
+ this.debugService.focusStackFrame(undefined, toFocusThread);
107
+ }
108
+ }
109
+ else {
110
+ const session = this.debugService.getViewModel().focusedSession;
111
+ if (session && session.getId() === this.getId() && session.state !== 2 ) {
112
+ this.debugService.focusStackFrame(undefined);
113
+ }
114
+ }
115
+ }
116
+ }, 800));
117
+ const parent = this._options.parentSession;
118
+ if (parent) {
119
+ toDispose.add(parent.onDidEndAdapter(() => {
120
+ if (!this.hasSeparateRepl() && this.raw?.isInShutdown === false) {
121
+ this.repl = this.repl.clone();
122
+ replListener.value = this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire());
123
+ this.parentSession = undefined;
124
+ }
125
+ }));
126
+ }
127
+ }
128
+ getId() {
129
+ return this.id;
130
+ }
131
+ setSubId(subId) {
132
+ this._subId = subId;
133
+ }
134
+ getMemory(memoryReference) {
135
+ return ( new MemoryRegion(memoryReference, this));
136
+ }
137
+ get subId() {
138
+ return this._subId;
139
+ }
140
+ get configuration() {
141
+ return this._configuration.resolved;
142
+ }
143
+ get unresolvedConfiguration() {
144
+ return this._configuration.unresolved;
145
+ }
146
+ get lifecycleManagedByParent() {
147
+ return !!this._options.lifecycleManagedByParent;
148
+ }
149
+ get compact() {
150
+ return !!this._options.compact;
151
+ }
152
+ get saveBeforeRestart() {
153
+ return this._options.saveBeforeRestart ?? !this._options?.parentSession;
154
+ }
155
+ get compoundRoot() {
156
+ return this._options.compoundRoot;
157
+ }
158
+ get suppressDebugStatusbar() {
159
+ return this._options.suppressDebugStatusbar ?? false;
160
+ }
161
+ get suppressDebugToolbar() {
162
+ return this._options.suppressDebugToolbar ?? false;
163
+ }
164
+ get suppressDebugView() {
165
+ return this._options.suppressDebugView ?? false;
166
+ }
167
+ get autoExpandLazyVariables() {
168
+ return this.configurationService.getValue('debug').autoExpandLazyVariables;
169
+ }
170
+ setConfiguration(configuration) {
171
+ this._configuration = configuration;
172
+ }
173
+ getLabel() {
174
+ const includeRoot = this.workspaceContextService.getWorkspace().folders.length > 1;
175
+ return includeRoot && this.root ? `${this.name} (${basenameOrAuthority(this.root.uri)})` : this.name;
176
+ }
177
+ setName(name) {
178
+ this._name = name;
179
+ this._onDidChangeName.fire(name);
180
+ }
181
+ get name() {
182
+ return this._name || this.configuration.name;
183
+ }
184
+ get state() {
185
+ if (!this.initialized) {
186
+ return 1 ;
187
+ }
188
+ if (!this.raw) {
189
+ return 0 ;
190
+ }
191
+ const focusedThread = this.debugService.getViewModel().focusedThread;
192
+ if (focusedThread && focusedThread.session === this) {
193
+ return focusedThread.stopped ? 2 : 3 ;
194
+ }
195
+ if (( this.getAllThreads().some(t => t.stopped))) {
196
+ return 2 ;
197
+ }
198
+ return 3 ;
199
+ }
200
+ get capabilities() {
201
+ return this.raw ? this.raw.capabilities : Object.create(null);
202
+ }
203
+ get onDidChangeState() {
204
+ return this._onDidChangeState.event;
205
+ }
206
+ get onDidEndAdapter() {
207
+ return this._onDidEndAdapter.event;
208
+ }
209
+ get onDidChangeReplElements() {
210
+ return this._onDidChangeREPLElements.event;
211
+ }
212
+ get onDidChangeName() {
213
+ return this._onDidChangeName.event;
214
+ }
215
+ get onDidCustomEvent() {
216
+ return this._onDidCustomEvent.event;
217
+ }
218
+ get onDidLoadedSource() {
219
+ return this._onDidLoadedSource.event;
220
+ }
221
+ get onDidProgressStart() {
222
+ return this._onDidProgressStart.event;
223
+ }
224
+ get onDidProgressUpdate() {
225
+ return this._onDidProgressUpdate.event;
226
+ }
227
+ get onDidProgressEnd() {
228
+ return this._onDidProgressEnd.event;
229
+ }
230
+ get onDidInvalidateMemory() {
231
+ return this._onDidInvalidMemory.event;
232
+ }
233
+ async initialize(dbgr) {
234
+ if (this.raw) {
235
+ await this.shutdown();
236
+ }
237
+ try {
238
+ const debugAdapter = await dbgr.createDebugAdapter(this);
239
+ this.raw = this.instantiationService.createInstance(RawDebugSession, debugAdapter, dbgr, this.id, this.configuration.name);
240
+ await this.raw.start();
241
+ this.registerListeners();
242
+ await this.raw.initialize({
243
+ clientID: 'vscode',
244
+ clientName: this.productService.nameLong,
245
+ adapterID: this.configuration.type,
246
+ pathFormat: 'path',
247
+ linesStartAt1: true,
248
+ columnsStartAt1: true,
249
+ supportsVariableType: true,
250
+ supportsVariablePaging: true,
251
+ supportsRunInTerminalRequest: true,
252
+ locale: language,
253
+ supportsProgressReporting: true,
254
+ supportsInvalidatedEvent: true,
255
+ supportsMemoryReferences: true,
256
+ supportsArgsCanBeInterpretedByShell: true,
257
+ supportsMemoryEvent: true,
258
+ supportsStartDebuggingRequest: true
259
+ });
260
+ this.initialized = true;
261
+ this._onDidChangeState.fire();
262
+ this.debugService.setExceptionBreakpointsForSession(this, (this.raw && this.raw.capabilities.exceptionBreakpointFilters) || []);
263
+ this.debugService.getModel().registerBreakpointModes(this.configuration.type, this.raw.capabilities.breakpointModes || []);
264
+ }
265
+ catch (err) {
266
+ this.initialized = true;
267
+ this._onDidChangeState.fire();
268
+ await this.shutdown();
269
+ throw err;
270
+ }
271
+ }
272
+ async launchOrAttach(config) {
273
+ if (!this.raw) {
274
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'launch or attach'));
275
+ }
276
+ if (this.parentSession && this.parentSession.state === 0 ) {
277
+ throw canceled();
278
+ }
279
+ config.__sessionId = this.getId();
280
+ try {
281
+ await this.raw.launchOrAttach(config);
282
+ }
283
+ catch (err) {
284
+ this.shutdown();
285
+ throw err;
286
+ }
287
+ }
288
+ async terminate(restart = false) {
289
+ if (!this.raw) {
290
+ this.onDidExitAdapter();
291
+ }
292
+ this.cancelAllRequests();
293
+ if (this._options.lifecycleManagedByParent && this.parentSession) {
294
+ await this.parentSession.terminate(restart);
295
+ }
296
+ else if (this.raw) {
297
+ if (this.raw.capabilities.supportsTerminateRequest && this._configuration.resolved.request === 'launch') {
298
+ await this.raw.terminate(restart);
299
+ }
300
+ else {
301
+ await this.raw.disconnect({ restart, terminateDebuggee: true });
302
+ }
303
+ }
304
+ if (!restart) {
305
+ this._options.compoundRoot?.sessionStopped();
306
+ }
307
+ }
308
+ async disconnect(restart = false, suspend = false) {
309
+ if (!this.raw) {
310
+ this.onDidExitAdapter();
311
+ }
312
+ this.cancelAllRequests();
313
+ if (this._options.lifecycleManagedByParent && this.parentSession) {
314
+ await this.parentSession.disconnect(restart, suspend);
315
+ }
316
+ else if (this.raw) {
317
+ await this.raw.disconnect({ restart, terminateDebuggee: false, suspendDebuggee: suspend });
318
+ }
319
+ if (!restart) {
320
+ this._options.compoundRoot?.sessionStopped();
321
+ }
322
+ }
323
+ async restart() {
324
+ if (!this.raw) {
325
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'restart'));
326
+ }
327
+ this.cancelAllRequests();
328
+ if (this._options.lifecycleManagedByParent && this.parentSession) {
329
+ await this.parentSession.restart();
330
+ }
331
+ else {
332
+ await this.raw.restart({ arguments: this.configuration });
333
+ }
334
+ }
335
+ async sendBreakpoints(modelUri, breakpointsToSend, sourceModified) {
336
+ if (!this.raw) {
337
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'breakpoints'));
338
+ }
339
+ if (!this.raw.readyForBreakpoints) {
340
+ return Promise.resolve(undefined);
341
+ }
342
+ const rawSource = this.getRawSource(modelUri);
343
+ if (breakpointsToSend.length && !rawSource.adapterData) {
344
+ rawSource.adapterData = breakpointsToSend[0].adapterData;
345
+ }
346
+ if (rawSource.path) {
347
+ rawSource.path = normalizeDriveLetter(rawSource.path);
348
+ }
349
+ const response = await this.raw.setBreakpoints({
350
+ source: rawSource,
351
+ lines: ( breakpointsToSend.map(bp => bp.sessionAgnosticData.lineNumber)),
352
+ breakpoints: ( breakpointsToSend.map(bp => bp.toDAP())),
353
+ sourceModified
354
+ });
355
+ if (response?.body) {
356
+ const data = ( new Map());
357
+ for (let i = 0; i < breakpointsToSend.length; i++) {
358
+ data.set(breakpointsToSend[i].getId(), response.body.breakpoints[i]);
359
+ }
360
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
361
+ }
362
+ }
363
+ async sendFunctionBreakpoints(fbpts) {
364
+ if (!this.raw) {
365
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'function breakpoints'));
366
+ }
367
+ if (this.raw.readyForBreakpoints) {
368
+ const response = await this.raw.setFunctionBreakpoints({ breakpoints: ( fbpts.map(bp => bp.toDAP())) });
369
+ if (response?.body) {
370
+ const data = ( new Map());
371
+ for (let i = 0; i < fbpts.length; i++) {
372
+ data.set(fbpts[i].getId(), response.body.breakpoints[i]);
373
+ }
374
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
375
+ }
376
+ }
377
+ }
378
+ async sendExceptionBreakpoints(exbpts) {
379
+ if (!this.raw) {
380
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'exception breakpoints'));
381
+ }
382
+ if (this.raw.readyForBreakpoints) {
383
+ const args = this.capabilities.supportsExceptionFilterOptions ? {
384
+ filters: [],
385
+ filterOptions: ( exbpts.map(exb => {
386
+ if (exb.condition) {
387
+ return { filterId: exb.filter, condition: exb.condition };
388
+ }
389
+ return { filterId: exb.filter };
390
+ }))
391
+ } : { filters: ( exbpts.map(exb => exb.filter)) };
392
+ const response = await this.raw.setExceptionBreakpoints(args);
393
+ if (response?.body && response.body.breakpoints) {
394
+ const data = ( new Map());
395
+ for (let i = 0; i < exbpts.length; i++) {
396
+ data.set(exbpts[i].getId(), response.body.breakpoints[i]);
397
+ }
398
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
399
+ }
400
+ }
401
+ }
402
+ dataBytesBreakpointInfo(address, bytes) {
403
+ if (this.raw?.capabilities.supportsDataBreakpointBytes === false) {
404
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'sessionDoesNotSupporBytesBreakpoints', "Session does not support breakpoints with bytes"));
405
+ }
406
+ return this._dataBreakpointInfo({ name: address, bytes, asAddress: true });
407
+ }
408
+ dataBreakpointInfo(name, variablesReference) {
409
+ return this._dataBreakpointInfo({ name, variablesReference });
410
+ }
411
+ async _dataBreakpointInfo(args) {
412
+ if (!this.raw) {
413
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'data breakpoints info'));
414
+ }
415
+ if (!this.raw.readyForBreakpoints) {
416
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'sessionNotReadyForBreakpoints', "Session is not ready for breakpoints"));
417
+ }
418
+ const response = await this.raw.dataBreakpointInfo(args);
419
+ return response?.body;
420
+ }
421
+ async sendDataBreakpoints(dataBreakpoints) {
422
+ if (!this.raw) {
423
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'data breakpoints'));
424
+ }
425
+ if (this.raw.readyForBreakpoints) {
426
+ const converted = await Promise.all(( dataBreakpoints.map(async (bp) => {
427
+ try {
428
+ const dap = await bp.toDAP(this);
429
+ return { dap, bp };
430
+ }
431
+ catch (e) {
432
+ return { bp, message: e.message };
433
+ }
434
+ })));
435
+ const response = await this.raw.setDataBreakpoints({ breakpoints: ( converted.map(d => d.dap)).filter(isDefined) });
436
+ if (response?.body) {
437
+ const data = ( new Map());
438
+ let i = 0;
439
+ for (const dap of converted) {
440
+ if (!dap.dap) {
441
+ data.set(dap.bp.getId(), dap.message);
442
+ }
443
+ else if (i < response.body.breakpoints.length) {
444
+ data.set(dap.bp.getId(), response.body.breakpoints[i++]);
445
+ }
446
+ }
447
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
448
+ }
449
+ }
450
+ }
451
+ async sendInstructionBreakpoints(instructionBreakpoints) {
452
+ if (!this.raw) {
453
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'instruction breakpoints'));
454
+ }
455
+ if (this.raw.readyForBreakpoints) {
456
+ const response = await this.raw.setInstructionBreakpoints({ breakpoints: ( instructionBreakpoints.map(ib => ib.toDAP())) });
457
+ if (response?.body) {
458
+ const data = ( new Map());
459
+ for (let i = 0; i < instructionBreakpoints.length; i++) {
460
+ data.set(instructionBreakpoints[i].getId(), response.body.breakpoints[i]);
461
+ }
462
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
463
+ }
464
+ }
465
+ }
466
+ async breakpointsLocations(uri, lineNumber) {
467
+ if (!this.raw) {
468
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'breakpoints locations'));
469
+ }
470
+ const source = this.getRawSource(uri);
471
+ const response = await this.raw.breakpointLocations({ source, line: lineNumber });
472
+ if (!response || !response.body || !response.body.breakpoints) {
473
+ return [];
474
+ }
475
+ const positions = ( response.body.breakpoints.map(bp => ({ lineNumber: bp.line, column: bp.column || 1 })));
476
+ return distinct(positions, p => `${p.lineNumber}:${p.column}`);
477
+ }
478
+ getDebugProtocolBreakpoint(breakpointId) {
479
+ return this.model.getDebugProtocolBreakpoint(breakpointId, this.getId());
480
+ }
481
+ customRequest(request, args) {
482
+ if (!this.raw) {
483
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", request));
484
+ }
485
+ return this.raw.custom(request, args);
486
+ }
487
+ stackTrace(threadId, startFrame, levels, token) {
488
+ if (!this.raw) {
489
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'stackTrace'));
490
+ }
491
+ const sessionToken = this.getNewCancellationToken(threadId, token);
492
+ return this.raw.stackTrace({ threadId, startFrame, levels }, sessionToken);
493
+ }
494
+ async exceptionInfo(threadId) {
495
+ if (!this.raw) {
496
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'exceptionInfo'));
497
+ }
498
+ const response = await this.raw.exceptionInfo({ threadId });
499
+ if (response) {
500
+ return {
501
+ id: response.body.exceptionId,
502
+ description: response.body.description,
503
+ breakMode: response.body.breakMode,
504
+ details: response.body.details
505
+ };
506
+ }
507
+ return undefined;
508
+ }
509
+ scopes(frameId, threadId) {
510
+ if (!this.raw) {
511
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'scopes'));
512
+ }
513
+ const token = this.getNewCancellationToken(threadId);
514
+ return this.raw.scopes({ frameId }, token);
515
+ }
516
+ variables(variablesReference, threadId, filter, start, count) {
517
+ if (!this.raw) {
518
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'variables'));
519
+ }
520
+ const token = threadId ? this.getNewCancellationToken(threadId) : undefined;
521
+ return this.raw.variables({ variablesReference, filter, start, count }, token);
522
+ }
523
+ evaluate(expression, frameId, context) {
524
+ if (!this.raw) {
525
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'evaluate'));
526
+ }
527
+ return this.raw.evaluate({ expression, frameId, context });
528
+ }
529
+ async restartFrame(frameId, threadId) {
530
+ await this.waitForTriggeredBreakpoints();
531
+ if (!this.raw) {
532
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'restartFrame'));
533
+ }
534
+ await this.raw.restartFrame({ frameId }, threadId);
535
+ }
536
+ setLastSteppingGranularity(threadId, granularity) {
537
+ const thread = this.getThread(threadId);
538
+ if (thread) {
539
+ thread.lastSteppingGranularity = granularity;
540
+ }
541
+ }
542
+ async next(threadId, granularity) {
543
+ await this.waitForTriggeredBreakpoints();
544
+ if (!this.raw) {
545
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'next'));
546
+ }
547
+ this.setLastSteppingGranularity(threadId, granularity);
548
+ await this.raw.next({ threadId, granularity });
549
+ }
550
+ async stepIn(threadId, targetId, granularity) {
551
+ await this.waitForTriggeredBreakpoints();
552
+ if (!this.raw) {
553
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'stepIn'));
554
+ }
555
+ this.setLastSteppingGranularity(threadId, granularity);
556
+ await this.raw.stepIn({ threadId, targetId, granularity });
557
+ }
558
+ async stepOut(threadId, granularity) {
559
+ await this.waitForTriggeredBreakpoints();
560
+ if (!this.raw) {
561
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'stepOut'));
562
+ }
563
+ this.setLastSteppingGranularity(threadId, granularity);
564
+ await this.raw.stepOut({ threadId, granularity });
565
+ }
566
+ async stepBack(threadId, granularity) {
567
+ await this.waitForTriggeredBreakpoints();
568
+ if (!this.raw) {
569
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'stepBack'));
570
+ }
571
+ this.setLastSteppingGranularity(threadId, granularity);
572
+ await this.raw.stepBack({ threadId, granularity });
573
+ }
574
+ async continue(threadId) {
575
+ await this.waitForTriggeredBreakpoints();
576
+ if (!this.raw) {
577
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'continue'));
578
+ }
579
+ await this.raw.continue({ threadId });
580
+ }
581
+ async reverseContinue(threadId) {
582
+ await this.waitForTriggeredBreakpoints();
583
+ if (!this.raw) {
584
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'reverse continue'));
585
+ }
586
+ await this.raw.reverseContinue({ threadId });
587
+ }
588
+ async pause(threadId) {
589
+ if (!this.raw) {
590
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'pause'));
591
+ }
592
+ await this.raw.pause({ threadId });
593
+ }
594
+ async terminateThreads(threadIds) {
595
+ if (!this.raw) {
596
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'terminateThreads'));
597
+ }
598
+ await this.raw.terminateThreads({ threadIds });
599
+ }
600
+ setVariable(variablesReference, name, value) {
601
+ if (!this.raw) {
602
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'setVariable'));
603
+ }
604
+ return this.raw.setVariable({ variablesReference, name, value });
605
+ }
606
+ setExpression(frameId, expression, value) {
607
+ if (!this.raw) {
608
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'setExpression'));
609
+ }
610
+ return this.raw.setExpression({ expression, value, frameId });
611
+ }
612
+ gotoTargets(source, line, column) {
613
+ if (!this.raw) {
614
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'gotoTargets'));
615
+ }
616
+ return this.raw.gotoTargets({ source, line, column });
617
+ }
618
+ goto(threadId, targetId) {
619
+ if (!this.raw) {
620
+ throw new Error(localizeWithPath('vs/workbench/contrib/debug/browser/debugSession', 'noDebugAdapter', "No debugger available, can not send '{0}'", 'goto'));
621
+ }
622
+ return this.raw.goto({ threadId, targetId });
623
+ }
624
+ loadSource(resource) {
625
+ if (!this.raw) {
626
+ return Promise.reject(( new Error(( localizeWithPath(
627
+ 'vs/workbench/contrib/debug/browser/debugSession',
628
+ 'noDebugAdapter',
629
+ "No debugger available, can not send '{0}'",
630
+ 'loadSource'
631
+ )))));
632
+ }
633
+ const source = this.getSourceForUri(resource);
634
+ let rawSource;
635
+ if (source) {
636
+ rawSource = source.raw;
637
+ }
638
+ else {
639
+ const data = Source.getEncodedDebugData(resource);
640
+ rawSource = { path: data.path, sourceReference: data.sourceReference };
641
+ }
642
+ return this.raw.source({ sourceReference: rawSource.sourceReference || 0, source: rawSource });
643
+ }
644
+ async getLoadedSources() {
645
+ if (!this.raw) {
646
+ return Promise.reject(( new Error(( localizeWithPath(
647
+ 'vs/workbench/contrib/debug/browser/debugSession',
648
+ 'noDebugAdapter',
649
+ "No debugger available, can not send '{0}'",
650
+ 'getLoadedSources'
651
+ )))));
652
+ }
653
+ const response = await this.raw.loadedSources({});
654
+ if (response?.body && response.body.sources) {
655
+ return ( response.body.sources.map(src => this.getSource(src)));
656
+ }
657
+ else {
658
+ return [];
659
+ }
660
+ }
661
+ async completions(frameId, threadId, text, position, overwriteBefore, token) {
662
+ if (!this.raw) {
663
+ return Promise.reject(( new Error(( localizeWithPath(
664
+ 'vs/workbench/contrib/debug/browser/debugSession',
665
+ 'noDebugAdapter',
666
+ "No debugger available, can not send '{0}'",
667
+ 'completions'
668
+ )))));
669
+ }
670
+ const sessionCancelationToken = this.getNewCancellationToken(threadId, token);
671
+ return this.raw.completions({
672
+ frameId,
673
+ text,
674
+ column: position.column,
675
+ line: position.lineNumber,
676
+ }, sessionCancelationToken);
677
+ }
678
+ async stepInTargets(frameId) {
679
+ if (!this.raw) {
680
+ return Promise.reject(( new Error(( localizeWithPath(
681
+ 'vs/workbench/contrib/debug/browser/debugSession',
682
+ 'noDebugAdapter',
683
+ "No debugger available, can not send '{0}'",
684
+ 'stepInTargets'
685
+ )))));
686
+ }
687
+ const response = await this.raw.stepInTargets({ frameId });
688
+ return response?.body.targets;
689
+ }
690
+ async cancel(progressId) {
691
+ if (!this.raw) {
692
+ return Promise.reject(( new Error(( localizeWithPath(
693
+ 'vs/workbench/contrib/debug/browser/debugSession',
694
+ 'noDebugAdapter',
695
+ "No debugger available, can not send '{0}'",
696
+ 'cancel'
697
+ )))));
698
+ }
699
+ return this.raw.cancel({ progressId });
700
+ }
701
+ async disassemble(memoryReference, offset, instructionOffset, instructionCount) {
702
+ if (!this.raw) {
703
+ return Promise.reject(( new Error(( localizeWithPath(
704
+ 'vs/workbench/contrib/debug/browser/debugSession',
705
+ 'noDebugAdapter',
706
+ "No debugger available, can not send '{0}'",
707
+ 'disassemble'
708
+ )))));
709
+ }
710
+ const response = await this.raw.disassemble({ memoryReference, offset, instructionOffset, instructionCount, resolveSymbols: true });
711
+ return response?.body?.instructions;
712
+ }
713
+ readMemory(memoryReference, offset, count) {
714
+ if (!this.raw) {
715
+ return Promise.reject(( new Error(( localizeWithPath(
716
+ 'vs/workbench/contrib/debug/browser/debugSession',
717
+ 'noDebugAdapter',
718
+ "No debugger available, can not send '{0}'",
719
+ 'readMemory'
720
+ )))));
721
+ }
722
+ return this.raw.readMemory({ count, memoryReference, offset });
723
+ }
724
+ writeMemory(memoryReference, offset, data, allowPartial) {
725
+ if (!this.raw) {
726
+ return Promise.reject(( new Error(( localizeWithPath(
727
+ 'vs/workbench/contrib/debug/browser/debugSession',
728
+ 'noDebugAdapter',
729
+ "No debugger available, can not send '{0}'",
730
+ 'disassemble'
731
+ )))));
732
+ }
733
+ return this.raw.writeMemory({ memoryReference, offset, allowPartial, data });
734
+ }
735
+ getThread(threadId) {
736
+ return this.threads.get(threadId);
737
+ }
738
+ getAllThreads() {
739
+ const result = [];
740
+ this.threadIds.forEach((threadId) => {
741
+ const thread = this.threads.get(threadId);
742
+ if (thread) {
743
+ result.push(thread);
744
+ }
745
+ });
746
+ return result;
747
+ }
748
+ clearThreads(removeThreads, reference = undefined) {
749
+ if (reference !== undefined && reference !== null) {
750
+ const thread = this.threads.get(reference);
751
+ if (thread) {
752
+ thread.clearCallStack();
753
+ thread.stoppedDetails = undefined;
754
+ thread.stopped = false;
755
+ if (removeThreads) {
756
+ this.threads.delete(reference);
757
+ }
758
+ }
759
+ }
760
+ else {
761
+ this.threads.forEach(thread => {
762
+ thread.clearCallStack();
763
+ thread.stoppedDetails = undefined;
764
+ thread.stopped = false;
765
+ });
766
+ if (removeThreads) {
767
+ this.threads.clear();
768
+ this.threadIds = [];
769
+ ExpressionContainer.allValues.clear();
770
+ }
771
+ }
772
+ }
773
+ getStoppedDetails() {
774
+ return this.stoppedDetails.length >= 1 ? this.stoppedDetails[0] : undefined;
775
+ }
776
+ rawUpdate(data) {
777
+ this.threadIds = [];
778
+ data.threads.forEach(thread => {
779
+ this.threadIds.push(thread.id);
780
+ if (!( this.threads.has(thread.id))) {
781
+ this.threads.set(thread.id, ( new Thread(this, thread.name, thread.id)));
782
+ }
783
+ else if (thread.name) {
784
+ const oldThread = this.threads.get(thread.id);
785
+ if (oldThread) {
786
+ oldThread.name = thread.name;
787
+ }
788
+ }
789
+ });
790
+ this.threads.forEach(t => {
791
+ if (this.threadIds.indexOf(t.threadId) === -1) {
792
+ this.threads.delete(t.threadId);
793
+ }
794
+ });
795
+ const stoppedDetails = data.stoppedDetails;
796
+ if (stoppedDetails) {
797
+ if (stoppedDetails.allThreadsStopped) {
798
+ this.threads.forEach(thread => {
799
+ thread.stoppedDetails = thread.threadId === stoppedDetails.threadId ? stoppedDetails : { reason: thread.stoppedDetails?.reason };
800
+ thread.stopped = true;
801
+ thread.clearCallStack();
802
+ });
803
+ }
804
+ else {
805
+ const thread = typeof stoppedDetails.threadId === 'number' ? this.threads.get(stoppedDetails.threadId) : undefined;
806
+ if (thread) {
807
+ thread.stoppedDetails = stoppedDetails;
808
+ thread.clearCallStack();
809
+ thread.stopped = true;
810
+ }
811
+ }
812
+ }
813
+ }
814
+ waitForTriggeredBreakpoints() {
815
+ if (!this._waitToResume) {
816
+ return;
817
+ }
818
+ return raceTimeout(this._waitToResume, TRIGGERED_BREAKPOINT_MAX_DELAY);
819
+ }
820
+ async fetchThreads(stoppedDetails) {
821
+ if (this.raw) {
822
+ const response = await this.raw.threads();
823
+ if (response?.body && response.body.threads) {
824
+ this.model.rawUpdate({
825
+ sessionId: this.getId(),
826
+ threads: response.body.threads,
827
+ stoppedDetails
828
+ });
829
+ }
830
+ }
831
+ }
832
+ initializeForTest(raw) {
833
+ this.raw = raw;
834
+ this.registerListeners();
835
+ }
836
+ registerListeners() {
837
+ if (!this.raw) {
838
+ return;
839
+ }
840
+ this.rawListeners.add(this.raw.onDidInitialize(async () => {
841
+ status(this.configuration.noDebug
842
+ ? ( localizeWithPath(
843
+ 'vs/workbench/contrib/debug/browser/debugSession',
844
+ 'debuggingStartedNoDebug',
845
+ "Started running without debugging."
846
+ ))
847
+ : ( localizeWithPath(
848
+ 'vs/workbench/contrib/debug/browser/debugSession',
849
+ 'debuggingStarted',
850
+ "Debugging started."
851
+ )));
852
+ const sendConfigurationDone = async () => {
853
+ if (this.raw && this.raw.capabilities.supportsConfigurationDoneRequest) {
854
+ try {
855
+ await this.raw.configurationDone();
856
+ }
857
+ catch (e) {
858
+ this.notificationService.error(e);
859
+ this.raw?.disconnect({});
860
+ }
861
+ }
862
+ return undefined;
863
+ };
864
+ try {
865
+ await this.debugService.sendAllBreakpoints(this);
866
+ }
867
+ finally {
868
+ await sendConfigurationDone();
869
+ await this.fetchThreads();
870
+ }
871
+ }));
872
+ const statusQueue = this.statusQueue;
873
+ this.rawListeners.add(this.raw.onDidStop(event => this.handleStop(event.body)));
874
+ this.rawListeners.add(this.raw.onDidThread(event => {
875
+ statusQueue.cancel([event.body.threadId]);
876
+ if (event.body.reason === 'started') {
877
+ if (!this.fetchThreadsScheduler) {
878
+ this.fetchThreadsScheduler = ( new RunOnceScheduler(() => {
879
+ this.fetchThreads();
880
+ }, 100));
881
+ this.rawListeners.add(this.fetchThreadsScheduler);
882
+ }
883
+ if (!this.fetchThreadsScheduler.isScheduled()) {
884
+ this.fetchThreadsScheduler.schedule();
885
+ }
886
+ }
887
+ else if (event.body.reason === 'exited') {
888
+ this.model.clearThreads(this.getId(), true, event.body.threadId);
889
+ const viewModel = this.debugService.getViewModel();
890
+ const focusedThread = viewModel.focusedThread;
891
+ this.passFocusScheduler.cancel();
892
+ if (focusedThread && event.body.threadId === focusedThread.threadId) {
893
+ this.debugService.focusStackFrame(undefined, undefined, viewModel.focusedSession, { explicit: false });
894
+ }
895
+ }
896
+ }));
897
+ this.rawListeners.add(this.raw.onDidTerminateDebugee(async (event) => {
898
+ status(( localizeWithPath(
899
+ 'vs/workbench/contrib/debug/browser/debugSession',
900
+ 'debuggingStopped',
901
+ "Debugging stopped."
902
+ )));
903
+ if (event.body && event.body.restart) {
904
+ await this.debugService.restartSession(this, event.body.restart);
905
+ }
906
+ else if (this.raw) {
907
+ await this.raw.disconnect({ terminateDebuggee: false });
908
+ }
909
+ }));
910
+ this.rawListeners.add(this.raw.onDidContinued(event => {
911
+ const allThreads = event.body.allThreadsContinued !== false;
912
+ statusQueue.cancel(allThreads ? undefined : [event.body.threadId]);
913
+ const threadId = allThreads ? undefined : event.body.threadId;
914
+ if (typeof threadId === 'number') {
915
+ this.stoppedDetails = this.stoppedDetails.filter(sd => sd.threadId !== threadId);
916
+ const tokens = this.cancellationMap.get(threadId);
917
+ this.cancellationMap.delete(threadId);
918
+ tokens?.forEach(t => t.dispose(true));
919
+ }
920
+ else {
921
+ this.stoppedDetails = [];
922
+ this.cancelAllRequests();
923
+ }
924
+ this.lastContinuedThreadId = threadId;
925
+ this.passFocusScheduler.schedule();
926
+ this.model.clearThreads(this.getId(), false, threadId);
927
+ this._onDidChangeState.fire();
928
+ }));
929
+ const outputQueue = ( new Queue());
930
+ this.rawListeners.add(this.raw.onDidOutput(async (event) => {
931
+ const outputSeverity = event.body.category === 'stderr' ? Severity$1.Error : event.body.category === 'console' ? Severity$1.Warning : Severity$1.Info;
932
+ if (event.body.variablesReference) {
933
+ const source = event.body.source && event.body.line ? {
934
+ lineNumber: event.body.line,
935
+ column: event.body.column ? event.body.column : 1,
936
+ source: this.getSource(event.body.source)
937
+ } : undefined;
938
+ const container = ( new ExpressionContainer(this, undefined, event.body.variablesReference, generateUuid()));
939
+ const children = container.getChildren();
940
+ outputQueue.queue(async () => {
941
+ const resolved = await children;
942
+ if (resolved.length === 1) {
943
+ this.appendToRepl({ output: event.body.output, expression: resolved[0], sev: outputSeverity, source }, event.body.category === 'important');
944
+ return;
945
+ }
946
+ resolved.forEach((child) => {
947
+ child.name = null;
948
+ this.appendToRepl({ output: '', expression: child, sev: outputSeverity, source }, event.body.category === 'important');
949
+ });
950
+ });
951
+ return;
952
+ }
953
+ outputQueue.queue(async () => {
954
+ if (!event.body || !this.raw) {
955
+ return;
956
+ }
957
+ if (event.body.category === 'telemetry') {
958
+ const telemetryEndpoint = this.raw.dbgr.getCustomTelemetryEndpoint();
959
+ if (telemetryEndpoint && this.telemetryService.telemetryLevel !== 0 ) {
960
+ let data = event.body.data;
961
+ if (!telemetryEndpoint.sendErrorTelemetry && event.body.data) {
962
+ data = filterExceptionsFromTelemetry(event.body.data);
963
+ }
964
+ this.customEndpointTelemetryService.publicLog(telemetryEndpoint, event.body.output, data);
965
+ }
966
+ return;
967
+ }
968
+ const source = event.body.source && event.body.line ? {
969
+ lineNumber: event.body.line,
970
+ column: event.body.column ? event.body.column : 1,
971
+ source: this.getSource(event.body.source)
972
+ } : undefined;
973
+ if (event.body.group === 'start' || event.body.group === 'startCollapsed') {
974
+ const expanded = event.body.group === 'start';
975
+ this.repl.startGroup(event.body.output || '', expanded, source);
976
+ return;
977
+ }
978
+ if (event.body.group === 'end') {
979
+ this.repl.endGroup();
980
+ if (!event.body.output) {
981
+ return;
982
+ }
983
+ }
984
+ if (typeof event.body.output === 'string') {
985
+ this.appendToRepl({ output: event.body.output, sev: outputSeverity, source }, event.body.category === 'important');
986
+ }
987
+ });
988
+ }));
989
+ this.rawListeners.add(this.raw.onDidBreakpoint(event => {
990
+ const id = event.body && event.body.breakpoint ? event.body.breakpoint.id : undefined;
991
+ const breakpoint = this.model.getBreakpoints().find(bp => bp.getIdFromAdapter(this.getId()) === id);
992
+ const functionBreakpoint = this.model.getFunctionBreakpoints().find(bp => bp.getIdFromAdapter(this.getId()) === id);
993
+ const dataBreakpoint = this.model.getDataBreakpoints().find(dbp => dbp.getIdFromAdapter(this.getId()) === id);
994
+ const exceptionBreakpoint = this.model.getExceptionBreakpoints().find(excbp => excbp.getIdFromAdapter(this.getId()) === id);
995
+ if (event.body.reason === 'new' && event.body.breakpoint.source && event.body.breakpoint.line) {
996
+ const source = this.getSource(event.body.breakpoint.source);
997
+ const bps = this.model.addBreakpoints(source.uri, [{
998
+ column: event.body.breakpoint.column,
999
+ enabled: true,
1000
+ lineNumber: event.body.breakpoint.line,
1001
+ }], false);
1002
+ if (bps.length === 1) {
1003
+ const data = ( new Map([[bps[0].getId(), event.body.breakpoint]]));
1004
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
1005
+ }
1006
+ }
1007
+ if (event.body.reason === 'removed') {
1008
+ if (breakpoint) {
1009
+ this.model.removeBreakpoints([breakpoint]);
1010
+ }
1011
+ if (functionBreakpoint) {
1012
+ this.model.removeFunctionBreakpoints(functionBreakpoint.getId());
1013
+ }
1014
+ if (dataBreakpoint) {
1015
+ this.model.removeDataBreakpoints(dataBreakpoint.getId());
1016
+ }
1017
+ }
1018
+ if (event.body.reason === 'changed') {
1019
+ if (breakpoint) {
1020
+ if (!breakpoint.column) {
1021
+ event.body.breakpoint.column = undefined;
1022
+ }
1023
+ const data = ( new Map([[breakpoint.getId(), event.body.breakpoint]]));
1024
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
1025
+ }
1026
+ if (functionBreakpoint) {
1027
+ const data = ( new Map([[functionBreakpoint.getId(), event.body.breakpoint]]));
1028
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
1029
+ }
1030
+ if (dataBreakpoint) {
1031
+ const data = ( new Map([[dataBreakpoint.getId(), event.body.breakpoint]]));
1032
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
1033
+ }
1034
+ if (exceptionBreakpoint) {
1035
+ const data = ( new Map([[exceptionBreakpoint.getId(), event.body.breakpoint]]));
1036
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, data);
1037
+ }
1038
+ }
1039
+ }));
1040
+ this.rawListeners.add(this.raw.onDidLoadedSource(event => {
1041
+ this._onDidLoadedSource.fire({
1042
+ reason: event.body.reason,
1043
+ source: this.getSource(event.body.source)
1044
+ });
1045
+ }));
1046
+ this.rawListeners.add(this.raw.onDidCustomEvent(event => {
1047
+ this._onDidCustomEvent.fire(event);
1048
+ }));
1049
+ this.rawListeners.add(this.raw.onDidProgressStart(event => {
1050
+ this._onDidProgressStart.fire(event);
1051
+ }));
1052
+ this.rawListeners.add(this.raw.onDidProgressUpdate(event => {
1053
+ this._onDidProgressUpdate.fire(event);
1054
+ }));
1055
+ this.rawListeners.add(this.raw.onDidProgressEnd(event => {
1056
+ this._onDidProgressEnd.fire(event);
1057
+ }));
1058
+ this.rawListeners.add(this.raw.onDidInvalidateMemory(event => {
1059
+ this._onDidInvalidMemory.fire(event);
1060
+ }));
1061
+ this.rawListeners.add(this.raw.onDidInvalidated(async (event) => {
1062
+ const areas = event.body.areas || ['all'];
1063
+ if (areas.includes('threads') || areas.includes('stacks') || areas.includes('all')) {
1064
+ this.cancelAllRequests();
1065
+ this.model.clearThreads(this.getId(), true);
1066
+ const details = this.stoppedDetails;
1067
+ this.stoppedDetails.length = 1;
1068
+ await Promise.all(( details.map(d => this.handleStop(d))));
1069
+ }
1070
+ const viewModel = this.debugService.getViewModel();
1071
+ if (viewModel.focusedSession === this) {
1072
+ viewModel.updateViews();
1073
+ }
1074
+ }));
1075
+ this.rawListeners.add(this.raw.onDidExitAdapter(event => this.onDidExitAdapter(event)));
1076
+ }
1077
+ async handleStop(event) {
1078
+ this.passFocusScheduler.cancel();
1079
+ this.stoppedDetails.push(event);
1080
+ if (event.hitBreakpointIds) {
1081
+ this._waitToResume = this.enableDependentBreakpoints(event.hitBreakpointIds);
1082
+ }
1083
+ this.statusQueue.run(this.fetchThreads(event).then(() => event.threadId === undefined ? this.threadIds : [event.threadId]), async (threadId, token) => {
1084
+ const hasLotsOfThreads = event.threadId === undefined && this.threadIds.length > 10;
1085
+ const focusedThread = this.debugService.getViewModel().focusedThread;
1086
+ const focusedThreadDoesNotExist = focusedThread !== undefined && focusedThread.session === this && !( this.threads.has(focusedThread.threadId));
1087
+ if (focusedThreadDoesNotExist) {
1088
+ this.debugService.focusStackFrame(undefined, undefined);
1089
+ }
1090
+ const thread = typeof threadId === 'number' ? this.getThread(threadId) : undefined;
1091
+ if (thread) {
1092
+ const promises = this.model.refreshTopOfCallstack(thread, !hasLotsOfThreads);
1093
+ const focus = async () => {
1094
+ if (focusedThreadDoesNotExist || (!event.preserveFocusHint && thread.getCallStack().length)) {
1095
+ const focusedStackFrame = this.debugService.getViewModel().focusedStackFrame;
1096
+ if (!focusedStackFrame || focusedStackFrame.thread.session === this) {
1097
+ const preserveFocus = !this.configurationService.getValue('debug').focusEditorOnBreak;
1098
+ await this.debugService.focusStackFrame(undefined, thread, undefined, { preserveFocus });
1099
+ }
1100
+ if (thread.stoppedDetails && !token.isCancellationRequested) {
1101
+ if (thread.stoppedDetails.reason === 'breakpoint' && this.configurationService.getValue('debug').openDebug === 'openOnDebugBreak' && !this.suppressDebugView) {
1102
+ await this.paneCompositeService.openPaneComposite(VIEWLET_ID, 0 );
1103
+ }
1104
+ if (this.configurationService.getValue('debug').focusWindowOnBreak && !this.workbenchEnvironmentService.extensionTestsLocationURI) {
1105
+ const activeWindow = getActiveWindow();
1106
+ if (!activeWindow.document.hasFocus()) {
1107
+ await this.hostService.focus(mainWindow, { force: true });
1108
+ }
1109
+ }
1110
+ }
1111
+ }
1112
+ };
1113
+ await promises.topCallStack;
1114
+ if (!event.hitBreakpointIds) {
1115
+ this._waitToResume = this.enableDependentBreakpoints(thread);
1116
+ }
1117
+ if (token.isCancellationRequested) {
1118
+ return;
1119
+ }
1120
+ focus();
1121
+ await promises.wholeCallStack;
1122
+ if (token.isCancellationRequested) {
1123
+ return;
1124
+ }
1125
+ const focusedStackFrame = this.debugService.getViewModel().focusedStackFrame;
1126
+ if (!focusedStackFrame || !focusedStackFrame.source || focusedStackFrame.source.presentationHint === 'deemphasize' || focusedStackFrame.presentationHint === 'deemphasize') {
1127
+ focus();
1128
+ }
1129
+ }
1130
+ this._onDidChangeState.fire();
1131
+ });
1132
+ }
1133
+ async enableDependentBreakpoints(hitBreakpointIdsOrThread) {
1134
+ let breakpoints;
1135
+ if (Array.isArray(hitBreakpointIdsOrThread)) {
1136
+ breakpoints = this.model.getBreakpoints().filter(bp => hitBreakpointIdsOrThread.includes(bp.getIdFromAdapter(this.id)));
1137
+ }
1138
+ else {
1139
+ const frame = hitBreakpointIdsOrThread.getTopStackFrame();
1140
+ if (frame === undefined) {
1141
+ return;
1142
+ }
1143
+ if (hitBreakpointIdsOrThread.stoppedDetails && hitBreakpointIdsOrThread.stoppedDetails.reason !== 'breakpoint') {
1144
+ return;
1145
+ }
1146
+ breakpoints = this.getBreakpointsAtPosition(frame.source.uri, frame.range.startLineNumber, frame.range.endLineNumber, frame.range.startColumn, frame.range.endColumn);
1147
+ }
1148
+ const urisToResend = ( new Set());
1149
+ this.model.getBreakpoints({ triggeredOnly: true, enabledOnly: true }).forEach(bp => {
1150
+ breakpoints.forEach(cbp => {
1151
+ if (bp.enabled && bp.triggeredBy === cbp.getId()) {
1152
+ bp.setSessionDidTrigger(this.getId());
1153
+ urisToResend.add(( bp.uri.toString()));
1154
+ }
1155
+ });
1156
+ });
1157
+ const results = [];
1158
+ urisToResend.forEach((uri) => results.push(this.debugService.sendBreakpoints(( URI.parse(uri)), undefined, this)));
1159
+ return Promise.all(results);
1160
+ }
1161
+ getBreakpointsAtPosition(uri, startLineNumber, endLineNumber, startColumn, endColumn) {
1162
+ return this.model.getBreakpoints({ uri: uri }).filter(bp => {
1163
+ if (bp.lineNumber < startLineNumber || bp.lineNumber > endLineNumber) {
1164
+ return false;
1165
+ }
1166
+ if (bp.column && (bp.column < startColumn || bp.column > endColumn)) {
1167
+ return false;
1168
+ }
1169
+ return true;
1170
+ });
1171
+ }
1172
+ onDidExitAdapter(event) {
1173
+ this.initialized = true;
1174
+ this.model.setBreakpointSessionData(this.getId(), this.capabilities, undefined);
1175
+ this.shutdown();
1176
+ this._onDidEndAdapter.fire(event);
1177
+ }
1178
+ shutdown() {
1179
+ this.rawListeners.clear();
1180
+ if (this.raw) {
1181
+ this.raw.disconnect({});
1182
+ this.raw.dispose();
1183
+ this.raw = undefined;
1184
+ }
1185
+ this.fetchThreadsScheduler?.dispose();
1186
+ this.fetchThreadsScheduler = undefined;
1187
+ this.passFocusScheduler.cancel();
1188
+ this.passFocusScheduler.dispose();
1189
+ this.model.clearThreads(this.getId(), true);
1190
+ this._onDidChangeState.fire();
1191
+ }
1192
+ dispose() {
1193
+ this.cancelAllRequests();
1194
+ this.rawListeners.dispose();
1195
+ this.globalDisposables.dispose();
1196
+ }
1197
+ getSourceForUri(uri) {
1198
+ return this.sources.get(( this.uriIdentityService.asCanonicalUri(uri).toString()));
1199
+ }
1200
+ getSource(raw) {
1201
+ let source = ( new Source(raw, this.getId(), this.uriIdentityService, this.logService));
1202
+ const uriKey = ( source.uri.toString());
1203
+ const found = this.sources.get(uriKey);
1204
+ if (found) {
1205
+ source = found;
1206
+ source.raw = mixin(source.raw, raw);
1207
+ if (source.raw && raw) {
1208
+ source.raw.presentationHint = raw.presentationHint;
1209
+ }
1210
+ }
1211
+ else {
1212
+ this.sources.set(uriKey, source);
1213
+ }
1214
+ return source;
1215
+ }
1216
+ getRawSource(uri) {
1217
+ const source = this.getSourceForUri(uri);
1218
+ if (source) {
1219
+ return source.raw;
1220
+ }
1221
+ else {
1222
+ const data = Source.getEncodedDebugData(uri);
1223
+ return { name: data.name, path: data.path, sourceReference: data.sourceReference };
1224
+ }
1225
+ }
1226
+ getNewCancellationToken(threadId, token) {
1227
+ const tokenSource = ( new CancellationTokenSource(token));
1228
+ const tokens = this.cancellationMap.get(threadId) || [];
1229
+ tokens.push(tokenSource);
1230
+ this.cancellationMap.set(threadId, tokens);
1231
+ return tokenSource.token;
1232
+ }
1233
+ cancelAllRequests() {
1234
+ this.cancellationMap.forEach(tokens => tokens.forEach(t => t.dispose(true)));
1235
+ this.cancellationMap.clear();
1236
+ }
1237
+ getReplElements() {
1238
+ return this.repl.getReplElements();
1239
+ }
1240
+ hasSeparateRepl() {
1241
+ return !this.parentSession || this._options.repl !== 'mergeWithParent';
1242
+ }
1243
+ removeReplExpressions() {
1244
+ this.repl.removeReplExpressions();
1245
+ }
1246
+ async addReplExpression(stackFrame, name) {
1247
+ await this.repl.addReplExpression(this, stackFrame, name);
1248
+ this.debugService.getViewModel().updateViews();
1249
+ }
1250
+ appendToRepl(data, isImportant) {
1251
+ this.repl.appendToRepl(this, data);
1252
+ if (isImportant) {
1253
+ this.notificationService.notify({ message: ( data.output.toString()), severity: data.sev, source: this.name });
1254
+ }
1255
+ }
1256
+ };
1257
+ DebugSession = ( __decorate([
1258
+ ( __param(5, IDebugService)),
1259
+ ( __param(6, ITelemetryService)),
1260
+ ( __param(7, IHostService)),
1261
+ ( __param(8, IConfigurationService)),
1262
+ ( __param(9, IPaneCompositePartService)),
1263
+ ( __param(10, IWorkspaceContextService)),
1264
+ ( __param(11, IProductService)),
1265
+ ( __param(12, INotificationService)),
1266
+ ( __param(13, ILifecycleService)),
1267
+ ( __param(14, IUriIdentityService)),
1268
+ ( __param(15, IInstantiationService)),
1269
+ ( __param(16, ICustomEndpointTelemetryService)),
1270
+ ( __param(17, IWorkbenchEnvironmentService)),
1271
+ ( __param(18, ILogService))
1272
+ ], DebugSession));
1273
+ class ThreadStatusScheduler extends Disposable {
1274
+ constructor() {
1275
+ super(...arguments);
1276
+ this.pendingCancellations = [];
1277
+ this.threadOps = this._register(( new DisposableMap()));
1278
+ }
1279
+ async run(threadIdsP, operation) {
1280
+ const cancelledWhileLookingUpThreads = ( new Set());
1281
+ this.pendingCancellations.push(cancelledWhileLookingUpThreads);
1282
+ const threadIds = await threadIdsP;
1283
+ for (let i = 0; i < this.pendingCancellations.length; i++) {
1284
+ const s = this.pendingCancellations[i];
1285
+ if (s === cancelledWhileLookingUpThreads) {
1286
+ this.pendingCancellations.splice(i, 1);
1287
+ break;
1288
+ }
1289
+ else {
1290
+ for (const threadId of threadIds) {
1291
+ s.add(threadId);
1292
+ }
1293
+ }
1294
+ }
1295
+ if (( cancelledWhileLookingUpThreads.has(undefined))) {
1296
+ return;
1297
+ }
1298
+ await Promise.all(( threadIds.map(threadId => {
1299
+ if (( cancelledWhileLookingUpThreads.has(threadId))) {
1300
+ return;
1301
+ }
1302
+ this.threadOps.get(threadId)?.cancel();
1303
+ const cts = ( new CancellationTokenSource());
1304
+ this.threadOps.set(threadId, cts);
1305
+ return operation(threadId, cts.token);
1306
+ })));
1307
+ }
1308
+ cancel(threadIds) {
1309
+ if (!threadIds) {
1310
+ for (const [_, op] of this.threadOps) {
1311
+ op.cancel();
1312
+ }
1313
+ this.threadOps.clearAndDisposeAll();
1314
+ for (const s of this.pendingCancellations) {
1315
+ s.add(undefined);
1316
+ }
1317
+ }
1318
+ else {
1319
+ for (const threadId of threadIds) {
1320
+ this.threadOps.get(threadId)?.cancel();
1321
+ this.threadOps.deleteAndDispose(threadId);
1322
+ for (const s of this.pendingCancellations) {
1323
+ s.add(threadId);
1324
+ }
1325
+ }
1326
+ }
1327
+ }
1328
+ }
1329
+
1330
+ export { DebugSession, ThreadStatusScheduler };