Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/common/extHostDebugService.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type * as vscode from 'vscode';
7
import { coalesce } from '../../../base/common/arrays.js';
8
import { asPromise } from '../../../base/common/async.js';
9
import { CancellationToken } from '../../../base/common/cancellation.js';
10
import { Emitter, Event } from '../../../base/common/event.js';
11
import { Disposable as DisposableCls, toDisposable } from '../../../base/common/lifecycle.js';
12
import { ThemeIcon as ThemeIconUtils } from '../../../base/common/themables.js';
13
import { URI, UriComponents } from '../../../base/common/uri.js';
14
import { ExtensionIdentifier, IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
15
import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
16
import { ISignService } from '../../../platform/sign/common/sign.js';
17
import { IWorkspaceFolder } from '../../../platform/workspace/common/workspace.js';
18
import { AbstractDebugAdapter } from '../../contrib/debug/common/abstractDebugAdapter.js';
19
import { DebugVisualizationType, IAdapterDescriptor, IConfig, IDebugAdapter, IDebugAdapterExecutable, IDebugAdapterImpl, IDebugAdapterNamedPipeServer, IDebugAdapterServer, IDebuggerContribution, IDebugVisualization, IDebugVisualizationContext, IDebugVisualizationTreeItem, MainThreadDebugVisualization } from '../../contrib/debug/common/debug.js';
20
import { convertToDAPaths, convertToVSCPaths, isDebuggerMainContribution } from '../../contrib/debug/common/debugUtils.js';
21
import { ExtensionDescriptionRegistry } from '../../services/extensions/common/extensionDescriptionRegistry.js';
22
import { Dto } from '../../services/extensions/common/proxyIdentifier.js';
23
import { DebugSessionUUID, ExtHostDebugServiceShape, IBreakpointsDeltaDto, IDebugSessionDto, IFunctionBreakpointDto, ISourceMultiBreakpointDto, IStackFrameFocusDto, IThreadFocusDto, MainContext, MainThreadDebugServiceShape, MainThreadTelemetryShape } from './extHost.protocol.js';
24
import { IExtHostCommands } from './extHostCommands.js';
25
import { IExtHostConfiguration } from './extHostConfiguration.js';
26
import { IExtHostEditorTabs } from './extHostEditorTabs.js';
27
import { IExtHostExtensionService } from './extHostExtensionService.js';
28
import { IExtHostRpcService } from './extHostRpcService.js';
29
import { IExtHostTesting } from './extHostTesting.js';
30
import * as Convert from './extHostTypeConverters.js';
31
import { Breakpoint, DataBreakpoint, DebugAdapterExecutable, DebugAdapterInlineImplementation, DebugAdapterNamedPipeServer, DebugAdapterServer, DebugConsoleMode, DebugStackFrame, DebugThread, Disposable, FunctionBreakpoint, Location, Position, setBreakpointId, SourceBreakpoint, ThemeIcon } from './extHostTypes.js';
32
import { IExtHostVariableResolverProvider } from './extHostVariableResolverService.js';
33
import { IExtHostWorkspace } from './extHostWorkspace.js';
34
35
export const IExtHostDebugService = createDecorator<IExtHostDebugService>('IExtHostDebugService');
36
37
export interface IExtHostDebugService extends ExtHostDebugServiceShape {
38
39
readonly _serviceBrand: undefined;
40
41
onDidStartDebugSession: Event<vscode.DebugSession>;
42
onDidTerminateDebugSession: Event<vscode.DebugSession>;
43
onDidChangeActiveDebugSession: Event<vscode.DebugSession | undefined>;
44
activeDebugSession: vscode.DebugSession | undefined;
45
activeDebugConsole: vscode.DebugConsole;
46
onDidReceiveDebugSessionCustomEvent: Event<vscode.DebugSessionCustomEvent>;
47
onDidChangeBreakpoints: Event<vscode.BreakpointsChangeEvent>;
48
breakpoints: vscode.Breakpoint[];
49
onDidChangeActiveStackItem: Event<vscode.DebugThread | vscode.DebugStackFrame | undefined>;
50
activeStackItem: vscode.DebugThread | vscode.DebugStackFrame | undefined;
51
52
addBreakpoints(breakpoints0: readonly vscode.Breakpoint[]): Promise<void>;
53
removeBreakpoints(breakpoints0: readonly vscode.Breakpoint[]): Promise<void>;
54
startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration, options: vscode.DebugSessionOptions): Promise<boolean>;
55
stopDebugging(session?: vscode.DebugSession): Promise<void>;
56
registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider, trigger: vscode.DebugConfigurationProviderTriggerKind): vscode.Disposable;
57
registerDebugAdapterDescriptorFactory(extension: IExtensionDescription, type: string, factory: vscode.DebugAdapterDescriptorFactory): vscode.Disposable;
58
registerDebugAdapterTrackerFactory(type: string, factory: vscode.DebugAdapterTrackerFactory): vscode.Disposable;
59
registerDebugVisualizationProvider<T extends vscode.DebugVisualization>(extension: IExtensionDescription, id: string, provider: vscode.DebugVisualizationProvider<T>): vscode.Disposable;
60
registerDebugVisualizationTree<T extends vscode.DebugTreeItem>(extension: IExtensionDescription, id: string, provider: vscode.DebugVisualizationTree<T>): vscode.Disposable;
61
asDebugSourceUri(source: vscode.DebugProtocolSource, session?: vscode.DebugSession): vscode.Uri;
62
}
63
64
export abstract class ExtHostDebugServiceBase extends DisposableCls implements IExtHostDebugService, ExtHostDebugServiceShape {
65
66
declare readonly _serviceBrand: undefined;
67
68
private _configProviderHandleCounter: number;
69
private _configProviders: ConfigProviderTuple[];
70
71
private _adapterFactoryHandleCounter: number;
72
private _adapterFactories: DescriptorFactoryTuple[];
73
74
private _trackerFactoryHandleCounter: number;
75
private _trackerFactories: TrackerFactoryTuple[];
76
77
private _debugServiceProxy: MainThreadDebugServiceShape;
78
private _debugSessions: Map<DebugSessionUUID, ExtHostDebugSession> = new Map<DebugSessionUUID, ExtHostDebugSession>();
79
80
private readonly _onDidStartDebugSession: Emitter<vscode.DebugSession>;
81
get onDidStartDebugSession(): Event<vscode.DebugSession> { return this._onDidStartDebugSession.event; }
82
83
private readonly _onDidTerminateDebugSession: Emitter<vscode.DebugSession>;
84
get onDidTerminateDebugSession(): Event<vscode.DebugSession> { return this._onDidTerminateDebugSession.event; }
85
86
private readonly _onDidChangeActiveDebugSession: Emitter<vscode.DebugSession | undefined>;
87
get onDidChangeActiveDebugSession(): Event<vscode.DebugSession | undefined> { return this._onDidChangeActiveDebugSession.event; }
88
89
private _activeDebugSession: ExtHostDebugSession | undefined;
90
get activeDebugSession(): vscode.DebugSession | undefined { return this._activeDebugSession?.api; }
91
92
private readonly _onDidReceiveDebugSessionCustomEvent: Emitter<vscode.DebugSessionCustomEvent>;
93
get onDidReceiveDebugSessionCustomEvent(): Event<vscode.DebugSessionCustomEvent> { return this._onDidReceiveDebugSessionCustomEvent.event; }
94
95
private _activeDebugConsole: ExtHostDebugConsole;
96
get activeDebugConsole(): vscode.DebugConsole { return this._activeDebugConsole.value; }
97
98
private _breakpoints: Map<string, vscode.Breakpoint>;
99
100
private readonly _onDidChangeBreakpoints: Emitter<vscode.BreakpointsChangeEvent>;
101
102
private _activeStackItem: vscode.DebugThread | vscode.DebugStackFrame | undefined;
103
private readonly _onDidChangeActiveStackItem: Emitter<vscode.DebugThread | vscode.DebugStackFrame | undefined>;
104
105
private _debugAdapters: Map<number, IDebugAdapter>;
106
private _debugAdaptersTrackers: Map<number, vscode.DebugAdapterTracker>;
107
108
private _debugVisualizationTreeItemIdsCounter = 0;
109
private readonly _debugVisualizationProviders = new Map<string, vscode.DebugVisualizationProvider>();
110
private readonly _debugVisualizationTrees = new Map<string, vscode.DebugVisualizationTree>();
111
private readonly _debugVisualizationTreeItemIds = new WeakMap<vscode.DebugTreeItem, number>();
112
private readonly _debugVisualizationElements = new Map<number, { provider: string; item: vscode.DebugTreeItem; children?: number[] }>();
113
114
private _signService: ISignService | undefined;
115
116
private readonly _visualizers = new Map<number, { v: vscode.DebugVisualization; provider: vscode.DebugVisualizationProvider; extensionId: string }>();
117
private _visualizerIdCounter = 0;
118
119
private _telemetryProxy: MainThreadTelemetryShape;
120
121
constructor(
122
@IExtHostRpcService extHostRpcService: IExtHostRpcService,
123
@IExtHostWorkspace protected readonly _workspaceService: IExtHostWorkspace,
124
@IExtHostExtensionService private readonly _extensionService: IExtHostExtensionService,
125
@IExtHostConfiguration protected readonly _configurationService: IExtHostConfiguration,
126
@IExtHostEditorTabs protected readonly _editorTabs: IExtHostEditorTabs,
127
@IExtHostVariableResolverProvider private readonly _variableResolver: IExtHostVariableResolverProvider,
128
@IExtHostCommands private readonly _commands: IExtHostCommands,
129
@IExtHostTesting private readonly _testing: IExtHostTesting,
130
) {
131
super();
132
133
this._configProviderHandleCounter = 0;
134
this._configProviders = [];
135
136
this._adapterFactoryHandleCounter = 0;
137
this._adapterFactories = [];
138
139
this._trackerFactoryHandleCounter = 0;
140
this._trackerFactories = [];
141
142
this._debugAdapters = new Map();
143
this._debugAdaptersTrackers = new Map();
144
145
this._onDidStartDebugSession = this._register(new Emitter<vscode.DebugSession>());
146
this._onDidTerminateDebugSession = this._register(new Emitter<vscode.DebugSession>());
147
this._onDidChangeActiveDebugSession = this._register(new Emitter<vscode.DebugSession | undefined>());
148
this._onDidReceiveDebugSessionCustomEvent = this._register(new Emitter<vscode.DebugSessionCustomEvent>());
149
150
this._debugServiceProxy = extHostRpcService.getProxy(MainContext.MainThreadDebugService);
151
152
this._onDidChangeBreakpoints = this._register(new Emitter<vscode.BreakpointsChangeEvent>());
153
154
this._onDidChangeActiveStackItem = this._register(new Emitter<vscode.DebugThread | vscode.DebugStackFrame | undefined>());
155
156
this._activeDebugConsole = new ExtHostDebugConsole(this._debugServiceProxy);
157
158
this._breakpoints = new Map<string, vscode.Breakpoint>();
159
160
this._extensionService.getExtensionRegistry().then((extensionRegistry: ExtensionDescriptionRegistry) => {
161
this._register(extensionRegistry.onDidChange(_ => {
162
this.registerAllDebugTypes(extensionRegistry);
163
}));
164
this.registerAllDebugTypes(extensionRegistry);
165
});
166
167
this._telemetryProxy = extHostRpcService.getProxy(MainContext.MainThreadTelemetry);
168
}
169
170
public async $getVisualizerTreeItem(treeId: string, element: IDebugVisualizationContext): Promise<IDebugVisualizationTreeItem | undefined> {
171
const context = this.hydrateVisualizationContext(element);
172
if (!context) {
173
return undefined;
174
}
175
176
const item = await this._debugVisualizationTrees.get(treeId)?.getTreeItem?.(context);
177
return item ? this.convertVisualizerTreeItem(treeId, item) : undefined;
178
}
179
180
public registerDebugVisualizationTree<T extends vscode.DebugTreeItem>(manifest: IExtensionDescription, id: string, provider: vscode.DebugVisualizationTree<T>): vscode.Disposable {
181
const extensionId = ExtensionIdentifier.toKey(manifest.identifier);
182
const key = this.extensionVisKey(extensionId, id);
183
if (this._debugVisualizationProviders.has(key)) {
184
throw new Error(`A debug visualization provider with id '${id}' is already registered`);
185
}
186
187
this._debugVisualizationTrees.set(key, provider);
188
this._debugServiceProxy.$registerDebugVisualizerTree(key, !!provider.editItem);
189
return toDisposable(() => {
190
this._debugServiceProxy.$unregisterDebugVisualizerTree(key);
191
this._debugVisualizationTrees.delete(id);
192
});
193
}
194
195
public async $getVisualizerTreeItemChildren(treeId: string, element: number): Promise<IDebugVisualizationTreeItem[]> {
196
const item = this._debugVisualizationElements.get(element)?.item;
197
if (!item) {
198
return [];
199
}
200
201
const children = await this._debugVisualizationTrees.get(treeId)?.getChildren?.(item);
202
return children?.map(i => this.convertVisualizerTreeItem(treeId, i)) || [];
203
}
204
205
public async $editVisualizerTreeItem(element: number, value: string): Promise<IDebugVisualizationTreeItem | undefined> {
206
const e = this._debugVisualizationElements.get(element);
207
if (!e) { return undefined; }
208
209
const r = await this._debugVisualizationTrees.get(e.provider)?.editItem?.(e.item, value);
210
return this.convertVisualizerTreeItem(e.provider, r || e.item);
211
}
212
213
public $disposeVisualizedTree(element: number): void {
214
const root = this._debugVisualizationElements.get(element);
215
if (!root) {
216
return;
217
}
218
219
const queue = [root.children];
220
for (const children of queue) {
221
if (children) {
222
for (const child of children) {
223
queue.push(this._debugVisualizationElements.get(child)?.children);
224
this._debugVisualizationElements.delete(child);
225
}
226
}
227
}
228
}
229
230
private convertVisualizerTreeItem(treeId: string, item: vscode.DebugTreeItem): IDebugVisualizationTreeItem {
231
let id = this._debugVisualizationTreeItemIds.get(item);
232
if (!id) {
233
id = this._debugVisualizationTreeItemIdsCounter++;
234
this._debugVisualizationTreeItemIds.set(item, id);
235
this._debugVisualizationElements.set(id, { provider: treeId, item });
236
}
237
238
return Convert.DebugTreeItem.from(item, id);
239
}
240
241
public asDebugSourceUri(src: vscode.DebugProtocolSource, session?: vscode.DebugSession): URI {
242
243
const source = <any>src;
244
245
if (typeof source.sourceReference === 'number' && source.sourceReference > 0) {
246
// src can be retrieved via DAP's "source" request
247
248
let debug = `debug:${encodeURIComponent(source.path || '')}`;
249
let sep = '?';
250
251
if (session) {
252
debug += `${sep}session=${encodeURIComponent(session.id)}`;
253
sep = '&';
254
}
255
256
debug += `${sep}ref=${source.sourceReference}`;
257
258
return URI.parse(debug);
259
} else if (source.path) {
260
// src is just a local file path
261
return URI.file(source.path);
262
} else {
263
throw new Error(`cannot create uri from DAP 'source' object; properties 'path' and 'sourceReference' are both missing.`);
264
}
265
}
266
267
private registerAllDebugTypes(extensionRegistry: ExtensionDescriptionRegistry) {
268
269
const debugTypes: string[] = [];
270
271
for (const ed of extensionRegistry.getAllExtensionDescriptions()) {
272
if (ed.contributes) {
273
const debuggers = <IDebuggerContribution[]>ed.contributes['debuggers'];
274
if (debuggers && debuggers.length > 0) {
275
for (const dbg of debuggers) {
276
if (isDebuggerMainContribution(dbg)) {
277
debugTypes.push(dbg.type);
278
}
279
}
280
}
281
}
282
}
283
284
this._debugServiceProxy.$registerDebugTypes(debugTypes);
285
}
286
287
// extension debug API
288
289
290
get activeStackItem(): vscode.DebugThread | vscode.DebugStackFrame | undefined {
291
return this._activeStackItem;
292
}
293
294
get onDidChangeActiveStackItem(): Event<vscode.DebugThread | vscode.DebugStackFrame | undefined> {
295
return this._onDidChangeActiveStackItem.event;
296
}
297
298
get onDidChangeBreakpoints(): Event<vscode.BreakpointsChangeEvent> {
299
return this._onDidChangeBreakpoints.event;
300
}
301
302
get breakpoints(): vscode.Breakpoint[] {
303
const result: vscode.Breakpoint[] = [];
304
this._breakpoints.forEach(bp => result.push(bp));
305
return result;
306
}
307
308
public async $resolveDebugVisualizer(id: number, token: CancellationToken): Promise<MainThreadDebugVisualization> {
309
const visualizer = this._visualizers.get(id);
310
if (!visualizer) {
311
throw new Error(`No debug visualizer found with id '${id}'`);
312
}
313
314
let { v, provider, extensionId } = visualizer;
315
if (!v.visualization) {
316
v = await provider.resolveDebugVisualization?.(v, token) || v;
317
visualizer.v = v;
318
}
319
320
if (!v.visualization) {
321
throw new Error(`No visualization returned from resolveDebugVisualization in '${provider}'`);
322
}
323
324
return this.serializeVisualization(extensionId, v.visualization)!;
325
}
326
327
public async $executeDebugVisualizerCommand(id: number): Promise<void> {
328
const visualizer = this._visualizers.get(id);
329
if (!visualizer) {
330
throw new Error(`No debug visualizer found with id '${id}'`);
331
}
332
333
const command = visualizer.v.visualization;
334
if (command && 'command' in command) {
335
this._commands.executeCommand(command.command, ...(command.arguments || []));
336
}
337
}
338
339
private hydrateVisualizationContext(context: IDebugVisualizationContext): vscode.DebugVisualizationContext | undefined {
340
const session = this._debugSessions.get(context.sessionId);
341
return session && {
342
session: session.api,
343
variable: context.variable,
344
containerId: context.containerId,
345
frameId: context.frameId,
346
threadId: context.threadId,
347
};
348
}
349
350
public async $provideDebugVisualizers(extensionId: string, id: string, context: IDebugVisualizationContext, token: CancellationToken): Promise<IDebugVisualization.Serialized[]> {
351
const contextHydrated = this.hydrateVisualizationContext(context);
352
const key = this.extensionVisKey(extensionId, id);
353
const provider = this._debugVisualizationProviders.get(key);
354
if (!contextHydrated || !provider) {
355
return []; // probably ended in the meantime
356
}
357
358
const visualizations = await provider.provideDebugVisualization(contextHydrated, token);
359
360
if (!visualizations) {
361
return [];
362
}
363
364
return visualizations.map(v => {
365
const id = ++this._visualizerIdCounter;
366
this._visualizers.set(id, { v, provider, extensionId });
367
const icon = v.iconPath ? this.getIconPathOrClass(v.iconPath) : undefined;
368
return {
369
id,
370
name: v.name,
371
iconClass: icon?.iconClass,
372
iconPath: icon?.iconPath,
373
visualization: this.serializeVisualization(extensionId, v.visualization),
374
};
375
});
376
}
377
378
public $disposeDebugVisualizers(ids: number[]): void {
379
for (const id of ids) {
380
this._visualizers.delete(id);
381
}
382
}
383
384
public registerDebugVisualizationProvider<T extends vscode.DebugVisualization>(manifest: IExtensionDescription, id: string, provider: vscode.DebugVisualizationProvider<T>): vscode.Disposable {
385
if (!manifest.contributes?.debugVisualizers?.some(r => r.id === id)) {
386
throw new Error(`Extensions may only call registerDebugVisualizationProvider() for renderers they contribute (got ${id})`);
387
}
388
389
const extensionId = ExtensionIdentifier.toKey(manifest.identifier);
390
const key = this.extensionVisKey(extensionId, id);
391
if (this._debugVisualizationProviders.has(key)) {
392
throw new Error(`A debug visualization provider with id '${id}' is already registered`);
393
}
394
395
this._debugVisualizationProviders.set(key, provider);
396
this._debugServiceProxy.$registerDebugVisualizer(extensionId, id);
397
return toDisposable(() => {
398
this._debugServiceProxy.$unregisterDebugVisualizer(extensionId, id);
399
this._debugVisualizationProviders.delete(id);
400
});
401
}
402
403
public addBreakpoints(breakpoints0: vscode.Breakpoint[]): Promise<void> {
404
// filter only new breakpoints
405
const breakpoints = breakpoints0.filter(bp => {
406
const id = bp.id;
407
if (!this._breakpoints.has(id)) {
408
this._breakpoints.set(id, bp);
409
return true;
410
}
411
return false;
412
});
413
414
// send notification for added breakpoints
415
this.fireBreakpointChanges(breakpoints, [], []);
416
417
// convert added breakpoints to DTOs
418
const dtos: Array<ISourceMultiBreakpointDto | IFunctionBreakpointDto> = [];
419
const map = new Map<string, ISourceMultiBreakpointDto>();
420
for (const bp of breakpoints) {
421
if (bp instanceof SourceBreakpoint) {
422
let dto = map.get(bp.location.uri.toString());
423
if (!dto) {
424
dto = {
425
type: 'sourceMulti',
426
uri: bp.location.uri,
427
lines: []
428
} satisfies ISourceMultiBreakpointDto;
429
map.set(bp.location.uri.toString(), dto);
430
dtos.push(dto);
431
}
432
dto.lines.push({
433
id: bp.id,
434
enabled: bp.enabled,
435
condition: bp.condition,
436
hitCondition: bp.hitCondition,
437
logMessage: bp.logMessage,
438
line: bp.location.range.start.line,
439
character: bp.location.range.start.character,
440
mode: bp.mode,
441
});
442
} else if (bp instanceof FunctionBreakpoint) {
443
dtos.push({
444
type: 'function',
445
id: bp.id,
446
enabled: bp.enabled,
447
hitCondition: bp.hitCondition,
448
logMessage: bp.logMessage,
449
condition: bp.condition,
450
functionName: bp.functionName,
451
mode: bp.mode,
452
});
453
}
454
}
455
456
// send DTOs to VS Code
457
return this._debugServiceProxy.$registerBreakpoints(dtos);
458
}
459
460
public removeBreakpoints(breakpoints0: vscode.Breakpoint[]): Promise<void> {
461
// remove from array
462
const breakpoints = breakpoints0.filter(b => this._breakpoints.delete(b.id));
463
464
// send notification
465
this.fireBreakpointChanges([], breakpoints, []);
466
467
// unregister with VS Code
468
const ids = breakpoints.filter(bp => bp instanceof SourceBreakpoint).map(bp => bp.id);
469
const fids = breakpoints.filter(bp => bp instanceof FunctionBreakpoint).map(bp => bp.id);
470
const dids = breakpoints.filter(bp => bp instanceof DataBreakpoint).map(bp => bp.id);
471
return this._debugServiceProxy.$unregisterBreakpoints(ids, fids, dids);
472
}
473
474
public startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration, options: vscode.DebugSessionOptions): Promise<boolean> {
475
const testRunMeta = options.testRun && this._testing.getMetadataForRun(options.testRun);
476
477
return this._debugServiceProxy.$startDebugging(folder ? folder.uri : undefined, nameOrConfig, {
478
parentSessionID: options.parentSession ? options.parentSession.id : undefined,
479
lifecycleManagedByParent: options.lifecycleManagedByParent,
480
repl: options.consoleMode === DebugConsoleMode.MergeWithParent ? 'mergeWithParent' : 'separate',
481
noDebug: options.noDebug,
482
compact: options.compact,
483
suppressSaveBeforeStart: options.suppressSaveBeforeStart,
484
testRun: testRunMeta && {
485
runId: testRunMeta.runId,
486
taskId: testRunMeta.taskId,
487
},
488
489
// Check debugUI for back-compat, #147264
490
suppressDebugStatusbar: options.suppressDebugStatusbar ?? (options as any).debugUI?.simple,
491
suppressDebugToolbar: options.suppressDebugToolbar ?? (options as any).debugUI?.simple,
492
suppressDebugView: options.suppressDebugView ?? (options as any).debugUI?.simple,
493
});
494
}
495
496
public stopDebugging(session?: vscode.DebugSession): Promise<void> {
497
return this._debugServiceProxy.$stopDebugging(session ? session.id : undefined);
498
}
499
500
public registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider, trigger: vscode.DebugConfigurationProviderTriggerKind): vscode.Disposable {
501
502
if (!provider) {
503
return new Disposable(() => { });
504
}
505
506
const handle = this._configProviderHandleCounter++;
507
this._configProviders.push({ type, handle, provider });
508
509
this._debugServiceProxy.$registerDebugConfigurationProvider(type, trigger,
510
!!provider.provideDebugConfigurations,
511
!!provider.resolveDebugConfiguration,
512
!!provider.resolveDebugConfigurationWithSubstitutedVariables,
513
handle);
514
515
return new Disposable(() => {
516
this._configProviders = this._configProviders.filter(p => p.provider !== provider); // remove
517
this._debugServiceProxy.$unregisterDebugConfigurationProvider(handle);
518
});
519
}
520
521
public registerDebugAdapterDescriptorFactory(extension: IExtensionDescription, type: string, factory: vscode.DebugAdapterDescriptorFactory): vscode.Disposable {
522
523
if (!factory) {
524
return new Disposable(() => { });
525
}
526
527
// a DebugAdapterDescriptorFactory can only be registered in the extension that contributes the debugger
528
if (!this.definesDebugType(extension, type)) {
529
throw new Error(`a DebugAdapterDescriptorFactory can only be registered from the extension that defines the '${type}' debugger.`);
530
}
531
532
// make sure that only one factory for this type is registered
533
if (this.getAdapterDescriptorFactoryByType(type)) {
534
throw new Error(`a DebugAdapterDescriptorFactory can only be registered once per a type.`);
535
}
536
537
const handle = this._adapterFactoryHandleCounter++;
538
this._adapterFactories.push({ type, handle, factory });
539
540
this._debugServiceProxy.$registerDebugAdapterDescriptorFactory(type, handle);
541
542
return new Disposable(() => {
543
this._adapterFactories = this._adapterFactories.filter(p => p.factory !== factory); // remove
544
this._debugServiceProxy.$unregisterDebugAdapterDescriptorFactory(handle);
545
});
546
}
547
548
public registerDebugAdapterTrackerFactory(type: string, factory: vscode.DebugAdapterTrackerFactory): vscode.Disposable {
549
550
if (!factory) {
551
return new Disposable(() => { });
552
}
553
554
const handle = this._trackerFactoryHandleCounter++;
555
this._trackerFactories.push({ type, handle, factory });
556
557
return new Disposable(() => {
558
this._trackerFactories = this._trackerFactories.filter(p => p.factory !== factory); // remove
559
});
560
}
561
562
// RPC methods (ExtHostDebugServiceShape)
563
564
public async $runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments, sessionId: string): Promise<number | undefined> {
565
return Promise.resolve(undefined);
566
}
567
568
public async $substituteVariables(folderUri: UriComponents | undefined, config: IConfig): Promise<IConfig> {
569
let ws: IWorkspaceFolder | undefined;
570
const folder = await this.getFolder(folderUri);
571
if (folder) {
572
ws = {
573
uri: folder.uri,
574
name: folder.name,
575
index: folder.index,
576
toResource: () => {
577
throw new Error('Not implemented');
578
}
579
};
580
}
581
const variableResolver = await this._variableResolver.getResolver();
582
return variableResolver.resolveAsync(ws, config);
583
}
584
585
protected createDebugAdapter(adapter: vscode.DebugAdapterDescriptor, session: ExtHostDebugSession): AbstractDebugAdapter | undefined {
586
if (adapter instanceof DebugAdapterInlineImplementation) {
587
return new DirectDebugAdapter(adapter.implementation);
588
}
589
return undefined;
590
}
591
592
protected createSignService(): ISignService | undefined {
593
return undefined;
594
}
595
596
public async $startDASession(debugAdapterHandle: number, sessionDto: IDebugSessionDto): Promise<void> {
597
const mythis = this;
598
599
const session = await this.getSession(sessionDto);
600
601
return this.getAdapterDescriptor(this.getAdapterDescriptorFactoryByType(session.type), session).then(daDescriptor => {
602
603
if (!daDescriptor) {
604
throw new Error(`Couldn't find a debug adapter descriptor for debug type '${session.type}' (extension might have failed to activate)`);
605
}
606
607
const da = this.createDebugAdapter(daDescriptor, session);
608
if (!da) {
609
throw new Error(`Couldn't create a debug adapter for type '${session.type}'.`);
610
}
611
612
const debugAdapter = da;
613
614
this._debugAdapters.set(debugAdapterHandle, debugAdapter);
615
616
return this.getDebugAdapterTrackers(session).then(tracker => {
617
618
if (tracker) {
619
this._debugAdaptersTrackers.set(debugAdapterHandle, tracker);
620
}
621
622
debugAdapter.onMessage(async message => {
623
624
if (message.type === 'request' && (<DebugProtocol.Request>message).command === 'handshake') {
625
626
const request = <DebugProtocol.Request>message;
627
628
const response: DebugProtocol.Response = {
629
type: 'response',
630
seq: 0,
631
command: request.command,
632
request_seq: request.seq,
633
success: true
634
};
635
636
if (!this._signService) {
637
this._signService = this.createSignService();
638
}
639
640
try {
641
if (this._signService) {
642
const signature = await this._signService.sign(request.arguments.value);
643
response.body = {
644
signature: signature
645
};
646
debugAdapter.sendResponse(response);
647
} else {
648
throw new Error('no signer');
649
}
650
} catch (e) {
651
response.success = false;
652
response.message = e.message;
653
debugAdapter.sendResponse(response);
654
}
655
} else {
656
if (tracker && tracker.onDidSendMessage) {
657
tracker.onDidSendMessage(message);
658
}
659
660
// DA -> VS Code
661
try {
662
// Try to catch details for #233167
663
message = convertToVSCPaths(message, true);
664
} catch (e) {
665
const type = message.type + '_' + ((message as any).command ?? (message as any).event ?? '');
666
this._telemetryProxy.$publicLog2<DebugProtocolMessageErrorEvent, DebugProtocolMessageErrorClassification>('debugProtocolMessageError', { type, from: session.type });
667
throw e;
668
}
669
670
mythis._debugServiceProxy.$acceptDAMessage(debugAdapterHandle, message);
671
}
672
});
673
debugAdapter.onError(err => {
674
if (tracker && tracker.onError) {
675
tracker.onError(err);
676
}
677
this._debugServiceProxy.$acceptDAError(debugAdapterHandle, err.name, err.message, err.stack);
678
});
679
debugAdapter.onExit((code: number | null) => {
680
if (tracker && tracker.onExit) {
681
tracker.onExit(code ?? undefined, undefined);
682
}
683
this._debugServiceProxy.$acceptDAExit(debugAdapterHandle, code ?? undefined, undefined);
684
});
685
686
if (tracker && tracker.onWillStartSession) {
687
tracker.onWillStartSession();
688
}
689
690
return debugAdapter.startSession();
691
});
692
});
693
}
694
695
public $sendDAMessage(debugAdapterHandle: number, message: DebugProtocol.ProtocolMessage): void {
696
697
// VS Code -> DA
698
message = convertToDAPaths(message, false);
699
700
const tracker = this._debugAdaptersTrackers.get(debugAdapterHandle); // TODO@AW: same handle?
701
if (tracker && tracker.onWillReceiveMessage) {
702
tracker.onWillReceiveMessage(message);
703
}
704
705
const da = this._debugAdapters.get(debugAdapterHandle);
706
da?.sendMessage(message);
707
}
708
709
public $stopDASession(debugAdapterHandle: number): Promise<void> {
710
711
const tracker = this._debugAdaptersTrackers.get(debugAdapterHandle);
712
this._debugAdaptersTrackers.delete(debugAdapterHandle);
713
if (tracker && tracker.onWillStopSession) {
714
tracker.onWillStopSession();
715
}
716
717
const da = this._debugAdapters.get(debugAdapterHandle);
718
this._debugAdapters.delete(debugAdapterHandle);
719
if (da) {
720
return da.stopSession();
721
} else {
722
return Promise.resolve(void 0);
723
}
724
}
725
726
public $acceptBreakpointsDelta(delta: IBreakpointsDeltaDto): void {
727
728
const a: vscode.Breakpoint[] = [];
729
const r: vscode.Breakpoint[] = [];
730
const c: vscode.Breakpoint[] = [];
731
732
if (delta.added) {
733
for (const bpd of delta.added) {
734
const id = bpd.id;
735
if (id && !this._breakpoints.has(id)) {
736
let bp: Breakpoint;
737
if (bpd.type === 'function') {
738
bp = new FunctionBreakpoint(bpd.functionName, bpd.enabled, bpd.condition, bpd.hitCondition, bpd.logMessage, bpd.mode);
739
} else if (bpd.type === 'data') {
740
bp = new DataBreakpoint(bpd.label, bpd.dataId, bpd.canPersist, bpd.enabled, bpd.hitCondition, bpd.condition, bpd.logMessage, bpd.mode);
741
} else {
742
const uri = URI.revive(bpd.uri);
743
bp = new SourceBreakpoint(new Location(uri, new Position(bpd.line, bpd.character)), bpd.enabled, bpd.condition, bpd.hitCondition, bpd.logMessage, bpd.mode);
744
}
745
setBreakpointId(bp, id);
746
this._breakpoints.set(id, bp);
747
a.push(bp);
748
}
749
}
750
}
751
752
if (delta.removed) {
753
for (const id of delta.removed) {
754
const bp = this._breakpoints.get(id);
755
if (bp) {
756
this._breakpoints.delete(id);
757
r.push(bp);
758
}
759
}
760
}
761
762
if (delta.changed) {
763
for (const bpd of delta.changed) {
764
if (bpd.id) {
765
const bp = this._breakpoints.get(bpd.id);
766
if (bp) {
767
if (bp instanceof FunctionBreakpoint && bpd.type === 'function') {
768
const fbp = <any>bp;
769
fbp.enabled = bpd.enabled;
770
fbp.condition = bpd.condition;
771
fbp.hitCondition = bpd.hitCondition;
772
fbp.logMessage = bpd.logMessage;
773
fbp.functionName = bpd.functionName;
774
} else if (bp instanceof SourceBreakpoint && bpd.type === 'source') {
775
const sbp = <any>bp;
776
sbp.enabled = bpd.enabled;
777
sbp.condition = bpd.condition;
778
sbp.hitCondition = bpd.hitCondition;
779
sbp.logMessage = bpd.logMessage;
780
sbp.location = new Location(URI.revive(bpd.uri), new Position(bpd.line, bpd.character));
781
}
782
c.push(bp);
783
}
784
}
785
}
786
}
787
788
this.fireBreakpointChanges(a, r, c);
789
}
790
791
public async $acceptStackFrameFocus(focusDto: IThreadFocusDto | IStackFrameFocusDto | undefined): Promise<void> {
792
let focus: vscode.DebugThread | vscode.DebugStackFrame | undefined;
793
if (focusDto) {
794
const session = await this.getSession(focusDto.sessionId);
795
if (focusDto.kind === 'thread') {
796
focus = new DebugThread(session.api, focusDto.threadId);
797
} else {
798
focus = new DebugStackFrame(session.api, focusDto.threadId, focusDto.frameId);
799
}
800
}
801
802
this._activeStackItem = focus;
803
this._onDidChangeActiveStackItem.fire(this._activeStackItem);
804
}
805
806
public $provideDebugConfigurations(configProviderHandle: number, folderUri: UriComponents | undefined, token: CancellationToken): Promise<vscode.DebugConfiguration[]> {
807
return asPromise(async () => {
808
const provider = this.getConfigProviderByHandle(configProviderHandle);
809
if (!provider) {
810
throw new Error('no DebugConfigurationProvider found');
811
}
812
if (!provider.provideDebugConfigurations) {
813
throw new Error('DebugConfigurationProvider has no method provideDebugConfigurations');
814
}
815
const folder = await this.getFolder(folderUri);
816
return provider.provideDebugConfigurations(folder, token);
817
}).then(debugConfigurations => {
818
if (!debugConfigurations) {
819
throw new Error('nothing returned from DebugConfigurationProvider.provideDebugConfigurations');
820
}
821
return debugConfigurations;
822
});
823
}
824
825
public $resolveDebugConfiguration(configProviderHandle: number, folderUri: UriComponents | undefined, debugConfiguration: vscode.DebugConfiguration, token: CancellationToken): Promise<vscode.DebugConfiguration | null | undefined> {
826
return asPromise(async () => {
827
const provider = this.getConfigProviderByHandle(configProviderHandle);
828
if (!provider) {
829
throw new Error('no DebugConfigurationProvider found');
830
}
831
if (!provider.resolveDebugConfiguration) {
832
throw new Error('DebugConfigurationProvider has no method resolveDebugConfiguration');
833
}
834
const folder = await this.getFolder(folderUri);
835
return provider.resolveDebugConfiguration(folder, debugConfiguration, token);
836
});
837
}
838
839
public $resolveDebugConfigurationWithSubstitutedVariables(configProviderHandle: number, folderUri: UriComponents | undefined, debugConfiguration: vscode.DebugConfiguration, token: CancellationToken): Promise<vscode.DebugConfiguration | null | undefined> {
840
return asPromise(async () => {
841
const provider = this.getConfigProviderByHandle(configProviderHandle);
842
if (!provider) {
843
throw new Error('no DebugConfigurationProvider found');
844
}
845
if (!provider.resolveDebugConfigurationWithSubstitutedVariables) {
846
throw new Error('DebugConfigurationProvider has no method resolveDebugConfigurationWithSubstitutedVariables');
847
}
848
const folder = await this.getFolder(folderUri);
849
return provider.resolveDebugConfigurationWithSubstitutedVariables(folder, debugConfiguration, token);
850
});
851
}
852
853
public async $provideDebugAdapter(adapterFactoryHandle: number, sessionDto: IDebugSessionDto): Promise<Dto<IAdapterDescriptor>> {
854
const adapterDescriptorFactory = this.getAdapterDescriptorFactoryByHandle(adapterFactoryHandle);
855
if (!adapterDescriptorFactory) {
856
return Promise.reject(new Error('no adapter descriptor factory found for handle'));
857
}
858
const session = await this.getSession(sessionDto);
859
return this.getAdapterDescriptor(adapterDescriptorFactory, session).then(adapterDescriptor => {
860
if (!adapterDescriptor) {
861
throw new Error(`Couldn't find a debug adapter descriptor for debug type '${session.type}'`);
862
}
863
return this.convertToDto(adapterDescriptor);
864
});
865
}
866
867
public async $acceptDebugSessionStarted(sessionDto: IDebugSessionDto): Promise<void> {
868
const session = await this.getSession(sessionDto);
869
this._onDidStartDebugSession.fire(session.api);
870
}
871
872
public async $acceptDebugSessionTerminated(sessionDto: IDebugSessionDto): Promise<void> {
873
const session = await this.getSession(sessionDto);
874
if (session) {
875
this._onDidTerminateDebugSession.fire(session.api);
876
this._debugSessions.delete(session.id);
877
}
878
}
879
880
public async $acceptDebugSessionActiveChanged(sessionDto: IDebugSessionDto | undefined): Promise<void> {
881
this._activeDebugSession = sessionDto ? await this.getSession(sessionDto) : undefined;
882
this._onDidChangeActiveDebugSession.fire(this._activeDebugSession?.api);
883
}
884
885
public async $acceptDebugSessionNameChanged(sessionDto: IDebugSessionDto, name: string): Promise<void> {
886
const session = await this.getSession(sessionDto);
887
session?._acceptNameChanged(name);
888
}
889
890
public async $acceptDebugSessionCustomEvent(sessionDto: IDebugSessionDto, event: any): Promise<void> {
891
const session = await this.getSession(sessionDto);
892
const ee: vscode.DebugSessionCustomEvent = {
893
session: session.api,
894
event: event.event,
895
body: event.body
896
};
897
this._onDidReceiveDebugSessionCustomEvent.fire(ee);
898
}
899
900
// private & dto helpers
901
902
private convertToDto(x: vscode.DebugAdapterDescriptor): Dto<IAdapterDescriptor> {
903
if (x instanceof DebugAdapterExecutable) {
904
return this.convertExecutableToDto(x);
905
} else if (x instanceof DebugAdapterServer) {
906
return this.convertServerToDto(x);
907
} else if (x instanceof DebugAdapterNamedPipeServer) {
908
return this.convertPipeServerToDto(x);
909
} else if (x instanceof DebugAdapterInlineImplementation) {
910
return this.convertImplementationToDto(x);
911
} else {
912
throw new Error('convertToDto unexpected type');
913
}
914
}
915
916
protected convertExecutableToDto(x: DebugAdapterExecutable): IDebugAdapterExecutable {
917
return {
918
type: 'executable',
919
command: x.command,
920
args: x.args,
921
options: x.options
922
};
923
}
924
925
protected convertServerToDto(x: DebugAdapterServer): IDebugAdapterServer {
926
return {
927
type: 'server',
928
port: x.port,
929
host: x.host
930
};
931
}
932
933
protected convertPipeServerToDto(x: DebugAdapterNamedPipeServer): IDebugAdapterNamedPipeServer {
934
return {
935
type: 'pipeServer',
936
path: x.path
937
};
938
}
939
940
protected convertImplementationToDto(x: DebugAdapterInlineImplementation): IDebugAdapterImpl {
941
return {
942
type: 'implementation',
943
};
944
}
945
946
private getAdapterDescriptorFactoryByType(type: string): vscode.DebugAdapterDescriptorFactory | undefined {
947
const results = this._adapterFactories.filter(p => p.type === type);
948
if (results.length > 0) {
949
return results[0].factory;
950
}
951
return undefined;
952
}
953
954
private getAdapterDescriptorFactoryByHandle(handle: number): vscode.DebugAdapterDescriptorFactory | undefined {
955
const results = this._adapterFactories.filter(p => p.handle === handle);
956
if (results.length > 0) {
957
return results[0].factory;
958
}
959
return undefined;
960
}
961
962
private getConfigProviderByHandle(handle: number): vscode.DebugConfigurationProvider | undefined {
963
const results = this._configProviders.filter(p => p.handle === handle);
964
if (results.length > 0) {
965
return results[0].provider;
966
}
967
return undefined;
968
}
969
970
private definesDebugType(ed: IExtensionDescription, type: string) {
971
if (ed.contributes) {
972
const debuggers = ed.contributes['debuggers'];
973
if (debuggers && debuggers.length > 0) {
974
for (const dbg of debuggers) {
975
// only debugger contributions with a "label" are considered a "defining" debugger contribution
976
if (dbg.label && dbg.type) {
977
if (dbg.type === type) {
978
return true;
979
}
980
}
981
}
982
}
983
}
984
return false;
985
}
986
987
private getDebugAdapterTrackers(session: ExtHostDebugSession): Promise<vscode.DebugAdapterTracker | undefined> {
988
989
const config = session.configuration;
990
const type = config.type;
991
992
const promises = this._trackerFactories
993
.filter(tuple => tuple.type === type || tuple.type === '*')
994
.map(tuple => asPromise<vscode.ProviderResult<vscode.DebugAdapterTracker>>(() => tuple.factory.createDebugAdapterTracker(session.api)).then(p => p, err => null));
995
996
return Promise.race([
997
Promise.all(promises).then(result => {
998
const trackers = coalesce(result); // filter null
999
if (trackers.length > 0) {
1000
return new MultiTracker(trackers);
1001
}
1002
return undefined;
1003
}),
1004
new Promise<undefined>(resolve => setTimeout(() => resolve(undefined), 1000)),
1005
]).catch(err => {
1006
// ignore errors
1007
return undefined;
1008
});
1009
}
1010
1011
private async getAdapterDescriptor(adapterDescriptorFactory: vscode.DebugAdapterDescriptorFactory | undefined, session: ExtHostDebugSession): Promise<vscode.DebugAdapterDescriptor | undefined> {
1012
1013
// a "debugServer" attribute in the launch config takes precedence
1014
const serverPort = session.configuration.debugServer;
1015
if (typeof serverPort === 'number') {
1016
return Promise.resolve(new DebugAdapterServer(serverPort));
1017
}
1018
1019
if (adapterDescriptorFactory) {
1020
const extensionRegistry = await this._extensionService.getExtensionRegistry();
1021
return asPromise(() => adapterDescriptorFactory.createDebugAdapterDescriptor(session.api, this.daExecutableFromPackage(session, extensionRegistry))).then(daDescriptor => {
1022
if (daDescriptor) {
1023
return daDescriptor;
1024
}
1025
return undefined;
1026
});
1027
}
1028
1029
// fallback: use executable information from package.json
1030
const extensionRegistry = await this._extensionService.getExtensionRegistry();
1031
return Promise.resolve(this.daExecutableFromPackage(session, extensionRegistry));
1032
}
1033
1034
protected daExecutableFromPackage(session: ExtHostDebugSession, extensionRegistry: ExtensionDescriptionRegistry): DebugAdapterExecutable | undefined {
1035
return undefined;
1036
}
1037
1038
private fireBreakpointChanges(added: vscode.Breakpoint[], removed: vscode.Breakpoint[], changed: vscode.Breakpoint[]) {
1039
if (added.length > 0 || removed.length > 0 || changed.length > 0) {
1040
this._onDidChangeBreakpoints.fire(Object.freeze({
1041
added,
1042
removed,
1043
changed,
1044
}));
1045
}
1046
}
1047
1048
private async getSession(dto: IDebugSessionDto): Promise<ExtHostDebugSession> {
1049
if (dto) {
1050
if (typeof dto === 'string') {
1051
const ds = this._debugSessions.get(dto);
1052
if (ds) {
1053
return ds;
1054
}
1055
} else {
1056
let ds = this._debugSessions.get(dto.id);
1057
if (!ds) {
1058
const folder = await this.getFolder(dto.folderUri);
1059
const parent = dto.parent ? this._debugSessions.get(dto.parent) : undefined;
1060
ds = new ExtHostDebugSession(this._debugServiceProxy, dto.id, dto.type, dto.name, folder, dto.configuration, parent?.api);
1061
this._debugSessions.set(ds.id, ds);
1062
this._debugServiceProxy.$sessionCached(ds.id);
1063
}
1064
return ds;
1065
}
1066
}
1067
throw new Error('cannot find session');
1068
}
1069
1070
private getFolder(_folderUri: UriComponents | undefined): Promise<vscode.WorkspaceFolder | undefined> {
1071
if (_folderUri) {
1072
const folderURI = URI.revive(_folderUri);
1073
return this._workspaceService.resolveWorkspaceFolder(folderURI);
1074
}
1075
return Promise.resolve(undefined);
1076
}
1077
1078
private extensionVisKey(extensionId: string, id: string) {
1079
return `${extensionId}\0${id}`;
1080
}
1081
1082
private serializeVisualization(extensionId: string, viz: vscode.DebugVisualization['visualization']): MainThreadDebugVisualization | undefined {
1083
if (!viz) {
1084
return undefined;
1085
}
1086
1087
if ('title' in viz && 'command' in viz) {
1088
return { type: DebugVisualizationType.Command };
1089
}
1090
1091
if ('treeId' in viz) {
1092
return { type: DebugVisualizationType.Tree, id: `${extensionId}\0${viz.treeId}` };
1093
}
1094
1095
throw new Error('Unsupported debug visualization type');
1096
}
1097
1098
private getIconPathOrClass(icon: vscode.DebugVisualization['iconPath']) {
1099
const iconPathOrIconClass = this.getIconUris(icon);
1100
let iconPath: { dark: URI; light?: URI | undefined } | undefined;
1101
let iconClass: string | undefined;
1102
if ('id' in iconPathOrIconClass) {
1103
iconClass = ThemeIconUtils.asClassName(iconPathOrIconClass);
1104
} else {
1105
iconPath = iconPathOrIconClass;
1106
}
1107
1108
return {
1109
iconPath,
1110
iconClass
1111
};
1112
}
1113
1114
private getIconUris(iconPath: vscode.DebugVisualization['iconPath']): { dark: URI; light?: URI } | { id: string } {
1115
if (iconPath instanceof ThemeIcon) {
1116
return { id: iconPath.id };
1117
}
1118
const dark = typeof iconPath === 'object' && 'dark' in iconPath ? iconPath.dark : iconPath;
1119
const light = typeof iconPath === 'object' && 'light' in iconPath ? iconPath.light : iconPath;
1120
return {
1121
dark: (typeof dark === 'string' ? URI.file(dark) : dark) as URI,
1122
light: (typeof light === 'string' ? URI.file(light) : light) as URI,
1123
};
1124
}
1125
}
1126
1127
export class ExtHostDebugSession {
1128
private apiSession?: vscode.DebugSession;
1129
constructor(
1130
private _debugServiceProxy: MainThreadDebugServiceShape,
1131
private _id: DebugSessionUUID,
1132
private _type: string,
1133
private _name: string,
1134
private _workspaceFolder: vscode.WorkspaceFolder | undefined,
1135
private _configuration: vscode.DebugConfiguration,
1136
private _parentSession: vscode.DebugSession | undefined) {
1137
}
1138
1139
public get api(): vscode.DebugSession {
1140
const that = this;
1141
return this.apiSession ??= Object.freeze({
1142
id: that._id,
1143
type: that._type,
1144
get name() {
1145
return that._name;
1146
},
1147
set name(name: string) {
1148
that._name = name;
1149
that._debugServiceProxy.$setDebugSessionName(that._id, name);
1150
},
1151
parentSession: that._parentSession,
1152
workspaceFolder: that._workspaceFolder,
1153
configuration: that._configuration,
1154
customRequest(command: string, args: any): Promise<any> {
1155
return that._debugServiceProxy.$customDebugAdapterRequest(that._id, command, args);
1156
},
1157
getDebugProtocolBreakpoint(breakpoint: vscode.Breakpoint): Promise<vscode.DebugProtocolBreakpoint | undefined> {
1158
return that._debugServiceProxy.$getDebugProtocolBreakpoint(that._id, breakpoint.id);
1159
}
1160
});
1161
}
1162
1163
public get id(): string {
1164
return this._id;
1165
}
1166
1167
public get type(): string {
1168
return this._type;
1169
}
1170
1171
_acceptNameChanged(name: string) {
1172
this._name = name;
1173
}
1174
1175
public get configuration(): vscode.DebugConfiguration {
1176
return this._configuration;
1177
}
1178
}
1179
1180
export class ExtHostDebugConsole {
1181
1182
readonly value: vscode.DebugConsole;
1183
1184
constructor(proxy: MainThreadDebugServiceShape) {
1185
1186
this.value = Object.freeze({
1187
append(value: string): void {
1188
proxy.$appendDebugConsole(value);
1189
},
1190
appendLine(value: string): void {
1191
this.append(value + '\n');
1192
}
1193
});
1194
}
1195
}
1196
1197
interface ConfigProviderTuple {
1198
type: string;
1199
handle: number;
1200
provider: vscode.DebugConfigurationProvider;
1201
}
1202
1203
interface DescriptorFactoryTuple {
1204
type: string;
1205
handle: number;
1206
factory: vscode.DebugAdapterDescriptorFactory;
1207
}
1208
1209
interface TrackerFactoryTuple {
1210
type: string;
1211
handle: number;
1212
factory: vscode.DebugAdapterTrackerFactory;
1213
}
1214
1215
class MultiTracker implements vscode.DebugAdapterTracker {
1216
1217
constructor(private trackers: vscode.DebugAdapterTracker[]) {
1218
}
1219
1220
onWillStartSession(): void {
1221
this.trackers.forEach(t => t.onWillStartSession ? t.onWillStartSession() : undefined);
1222
}
1223
1224
onWillReceiveMessage(message: any): void {
1225
this.trackers.forEach(t => t.onWillReceiveMessage ? t.onWillReceiveMessage(message) : undefined);
1226
}
1227
1228
onDidSendMessage(message: any): void {
1229
this.trackers.forEach(t => t.onDidSendMessage ? t.onDidSendMessage(message) : undefined);
1230
}
1231
1232
onWillStopSession(): void {
1233
this.trackers.forEach(t => t.onWillStopSession ? t.onWillStopSession() : undefined);
1234
}
1235
1236
onError(error: Error): void {
1237
this.trackers.forEach(t => t.onError ? t.onError(error) : undefined);
1238
}
1239
1240
onExit(code: number, signal: string): void {
1241
this.trackers.forEach(t => t.onExit ? t.onExit(code, signal) : undefined);
1242
}
1243
}
1244
1245
/*
1246
* Call directly into a debug adapter implementation
1247
*/
1248
class DirectDebugAdapter extends AbstractDebugAdapter {
1249
1250
constructor(private implementation: vscode.DebugAdapter) {
1251
super();
1252
1253
implementation.onDidSendMessage((message: vscode.DebugProtocolMessage) => {
1254
this.acceptMessage(message as DebugProtocol.ProtocolMessage);
1255
});
1256
}
1257
1258
startSession(): Promise<void> {
1259
return Promise.resolve(undefined);
1260
}
1261
1262
sendMessage(message: DebugProtocol.ProtocolMessage): void {
1263
this.implementation.handleMessage(message);
1264
}
1265
1266
stopSession(): Promise<void> {
1267
this.implementation.dispose();
1268
return Promise.resolve(undefined);
1269
}
1270
}
1271
1272
1273
export class WorkerExtHostDebugService extends ExtHostDebugServiceBase {
1274
constructor(
1275
@IExtHostRpcService extHostRpcService: IExtHostRpcService,
1276
@IExtHostWorkspace workspaceService: IExtHostWorkspace,
1277
@IExtHostExtensionService extensionService: IExtHostExtensionService,
1278
@IExtHostConfiguration configurationService: IExtHostConfiguration,
1279
@IExtHostEditorTabs editorTabs: IExtHostEditorTabs,
1280
@IExtHostVariableResolverProvider variableResolver: IExtHostVariableResolverProvider,
1281
@IExtHostCommands commands: IExtHostCommands,
1282
@IExtHostTesting testing: IExtHostTesting,
1283
) {
1284
super(extHostRpcService, workspaceService, extensionService, configurationService, editorTabs, variableResolver, commands, testing);
1285
}
1286
}
1287
1288
// Collecting info for #233167 specifically
1289
type DebugProtocolMessageErrorClassification = {
1290
from: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The type of the debug adapter that the event is from.' };
1291
type: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The type of the event that was malformed.' };
1292
owner: 'roblourens';
1293
comment: 'Sent to collect details about misbehaving debug extensions.';
1294
};
1295
1296
type DebugProtocolMessageErrorEvent = {
1297
from: string;
1298
type: string;
1299
};
1300
1301