src/vs/workbench/contrib/debug/common/debugger.ts

325 LOC · 250 covered · 75 uncovered · 36 ranges · 5 concepts · 4 introducers · 3 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/base/common/objects.ts · 286 LOCcommon/objects.tssrc/vs/platform/configuration/test/common/testConfigurationService.ts · 91 LOCcommon/testConfiguration…src/vs/workbench/contrib/debug/common/debugUtils.ts · 445 LOCcommon/debugUtils.tssrc/vs/workbench/services/configurationResolver/common/configurationResolverUtils.ts · 12 LOCcommon/configurationReso…debugAdapter.ts ×16 · 67 introduced LOCdebugAdapter.ts ×16debugger.ts ×3 · 27 introduced LOCdebugger.ts ×3debugger.ts ×5 · 89 introduced LOCdebugger.ts ×5debugger.ts ×2 · 4 introduced LOCdebugger.ts ×2debugger.ts ×26 · 153 introduced LOCdebugger.ts ×26debugger.test|title=Debug - Debugger attributes|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/debug/test/node/debugger.test|title=Debug - Debugger attributes|occurrence=1debugger.test|title=Debu…debugger.test|title=Debug - Debugger getSchemaAttributes logs malformed properties and ignores them|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/debug/test/node/debugger.test|title=Debug - Debugger getSchemaAttributes logs malformed properties and ignores them|occurrence=1debugger.test|title=Debu…debugger.test|title=Debug - Debugger initial config file content|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/debug/test/node/debugger.test|title=Debug - Debugger initial config file content|occurrence=1debugger.test|title=Debu…Focused file · src/vs/workbench/contrib/debug/common/debugger.ts · 325 LOCcommon/debugger.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- debugger.ts ×26
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 * as nls from '../../../../nls.js';
7 > import { isObject } from '../../../../base/common/types.js';
8 > import { IJSONSchema, IJSONSchemaMap, IJSONSchemaSnippet } from '../../../../base/common/jsonSchema.js';
9 > import { IWorkspaceFolder } from '../../../../platform/workspace/common/workspace.js';
10 > import { IConfig, IDebuggerContribution, IDebugAdapter, IDebugger, IDebugSession, IAdapterManager, IDebugService, debuggerDisabledMessage, IDebuggerMetadata, DebugConfigurationProviderTriggerKind } from './debug.js';
11 > import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
12 > import { IConfigurationResolverService } from '../../../services/configurationResolver/common/configurationResolver.js';
13 > import * as ConfigurationResolverUtils from '../../../services/configurationResolver/common/configurationResolverUtils.js';
14 > import { ITextResourcePropertiesService } from '../../../../editor/common/services/textResourceConfiguration.js';
15 > import { URI } from '../../../../base/common/uri.js';
16 > import { Schemas } from '../../../../base/common/network.js';
17 > import { isDebuggerMainContribution } from './debugUtils.js';
18 > import { IExtensionDescription } from '../../../../platform/extensions/common/extensions.js';
19 > import { ITelemetryEndpoint } from '../../../../platform/telemetry/common/telemetry.js';
20 > import { cleanRemoteAuthority } from '../../../../platform/telemetry/common/telemetryUtils.js';
21 > import { IWorkbenchEnvironmentService } from '../../../services/environment/common/environmentService.js';
22 > import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
23 > import { filter } from '../../../../base/common/objects.js';
24 > import { IProductService } from '../../../../platform/product/common/productService.js';
25 > import { ILogService } from '../../../../platform/log/common/log.js';
26 >
27 > export class Debugger implements IDebugger, IDebuggerMetadata {
28 >
29 > private debuggerContribution: IDebuggerContribution;
30 > private mergedExtensionDescriptions: IExtensionDescription[] = [];
31 > private mainExtensionDescription: IExtensionDescription | undefined;
32 >
33 > private debuggerWhen: ContextKeyExpression | undefined;
34 > private debuggerHiddenWhen: ContextKeyExpression | undefined;
35 >
36 > constructor(
37 > private adapterManager: IAdapterManager,
38 > dbgContribution: IDebuggerContribution,
39 > extensionDescription: IExtensionDescription,
40 > @IConfigurationService private readonly configurationService: IConfigurationService,
41 > @ITextResourcePropertiesService private readonly resourcePropertiesService: ITextResourcePropertiesService,
42 > @IConfigurationResolverService private readonly configurationResolverService: IConfigurationResolverService,
43 > @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
44 > @IDebugService private readonly debugService: IDebugService,
45 > @IContextKeyService private readonly contextKeyService: IContextKeyService,
46 > @IProductService private readonly productService: IProductService,
47 > @ILogService private readonly logService: ILogService,
48 > ) {
49 > this.debuggerContribution = { type: dbgContribution.type };
50 > this.merge(dbgContribution, extensionDescription);
51 >
52 > this.debuggerWhen = typeof this.debuggerContribution.when === 'string' ? ContextKeyExpr.deserialize(this.debuggerContribution.when) : undefined;
53 > this.debuggerHiddenWhen = typeof this.debuggerContribution.hiddenWhen === 'string' ? ContextKeyExpr.deserialize(this.debuggerContribution.hiddenWhen) : undefined;
54 > }
55 >
56 > merge(otherDebuggerContribution: IDebuggerContribution, extensionDescription: IExtensionDescription): void {
57 >
58 > /**
59 > * Copies all properties of source into destination. The optional parameter "overwrite" allows to control
60 > * if existing non-structured properties on the destination should be overwritten or not. Defaults to true (overwrite).
61 > */
62 > function mixin(destination: any, source: any, overwrite: boolean, level = 0): any {
63 >
64 > if (!isObject(destination)) {
65 return source;
66 }
68 > if (isObject(source)) {
69 > Object.keys(source).forEach(key => {
70 > if (key !== '__proto__') {
71 > if (isObject(destination[key]) && isObject(source[key])) {
72 mixin(destination[key], source[key], overwrite, level + 1);
73 > } else { debugger.ts ×26
74 > if (key in destination) {
75 > if (overwrite) {
76 if (level === 0 && key === 'type') {
77 // don't merge the 'type' property
78 } else {
79 destination[key] = source[key];
80 }
81 }
82 > } else { debugger.ts ×26
83 > destination[key] = source[key];
84 > }
85 > }
86 > }
87 > });
88 > }
89 >
90 > return destination;
91 > }
92 >
93 > // only if not already merged
94 > if (this.mergedExtensionDescriptions.indexOf(extensionDescription) < 0) {
95 >
96 > // remember all extensions that have been merged for this debugger
97 > this.mergedExtensionDescriptions.push(extensionDescription);
98 >
99 > // merge new debugger contribution into existing contributions (and don't overwrite values in built-in extensions)
100 > mixin(this.debuggerContribution, otherDebuggerContribution, extensionDescription.isBuiltin);
101 >
102 > // remember the extension that is considered the "main" debugger contribution
103 > if (isDebuggerMainContribution(otherDebuggerContribution)) {
104 > this.mainExtensionDescription = extensionDescription;
105 > }
106 > }
107 > }
108 >
109 > async startDebugging(configuration: IConfig, parentSessionId: string): Promise<boolean> {
110 const parentSession = this.debugService.getModel().getSession(parentSessionId);
111 return await this.debugService.startDebugging(undefined, configuration, { parentSession }, undefined);
112 }
114 > async createDebugAdapter(session: IDebugSession): Promise<IDebugAdapter> {
115 await this.adapterManager.activateDebuggers('onDebugAdapterProtocolTracker', this.type);
116 const da = this.adapterManager.createDebugAdapter(session);
117 if (da) {
118 return Promise.resolve(da);
119 }
120 throw new Error(nls.localize('cannot.find.da', "Cannot find debug adapter for type '{0}'.", this.type));
121 }
123 > async substituteVariables(folder: IWorkspaceFolder | undefined, config: IConfig): Promise<IConfig | undefined> {
124 const substitutedConfig = await this.adapterManager.substituteVariables(this.type, folder, config);
125 return await this.configurationResolverService.resolveWithInteractionReplace(folder, substitutedConfig, 'launch', this.variables, substitutedConfig.__configurationTarget);
126 }
128 > runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments, sessionId: string): Promise<number | undefined> {
129 return this.adapterManager.runInTerminal(this.type, args, sessionId);
130 }
132 > get label(): string {
133 > return this.debuggerContribution.label || this.debuggerContribution.type; debugger.ts ×2
134 > }
136 > get type(): string {
137 > return this.debuggerContribution.type; debugger.ts ×2
138 > }
140 > get variables(): { [key: string]: string } | undefined {
141 return this.debuggerContribution.variables;
142 }
144 > get configurationSnippets(): IJSONSchemaSnippet[] | undefined {
145 return this.debuggerContribution.configurationSnippets;
146 }
148 > get languages(): string[] | undefined {
149 return this.debuggerContribution.languages;
150 }
152 > get when(): ContextKeyExpression | undefined {
153 return this.debuggerWhen;
154 }
156 > get hiddenWhen(): ContextKeyExpression | undefined {
157 return this.debuggerHiddenWhen;
158 }
160 > get enabled() {
161 > return !this.debuggerWhen || this.contextKeyService.contextMatchesRules(this.debuggerWhen); debugger.ts ×5
162 > }
164 > get isHiddenFromDropdown() {
165 if (!this.debuggerHiddenWhen) {
166 return false;
167 }
168 return this.contextKeyService.contextMatchesRules(this.debuggerHiddenWhen);
169 }
171 > get strings() {
172 return this.debuggerContribution.strings ?? this.debuggerContribution.uiMessages;
173 }
175 > interestedInLanguage(languageId: string): boolean {
176 return !!(this.languages && this.languages.indexOf(languageId) >= 0);
177 }
179 > hasInitialConfiguration(): boolean {
180 return !!this.debuggerContribution.initialConfigurations;
181 }
183 > hasDynamicConfigurationProviders(): boolean {
184 return this.debugService.getConfigurationManager().hasDebugConfigurationProvider(this.type, DebugConfigurationProviderTriggerKind.Dynamic);
185 }
187 > hasConfigurationProvider(): boolean {
188 return this.debugService.getConfigurationManager().hasDebugConfigurationProvider(this.type);
189 }
191 > getInitialConfigurationContent(initialConfigs?: IConfig[]): Promise<string> {
192 > // at this point we got some configs from the package.json and/or from registered DebugConfigurationProviders debugger.ts ×3
193 > let initialConfigurations = this.debuggerContribution.initialConfigurations || [];
194 > if (initialConfigs) {
195 initialConfigurations = initialConfigurations.concat(initialConfigs);
196 }
198 > const eol = this.resourcePropertiesService.getEOL(URI.from({ scheme: Schemas.untitled, path: '1' })) === '\r\n' ? '\r\n' : '\n';
199 > const configs = JSON.stringify(initialConfigurations, null, '\t').split('\n').map(line => '\t' + line).join(eol).trim();
200 > const comment1 = nls.localize('launch.config.comment1', "Use IntelliSense to learn about possible attributes.");
201 > const comment2 = nls.localize('launch.config.comment2', "Hover to view descriptions of existing attributes.");
202 > const comment3 = nls.localize('launch.config.comment3', "For more information, visit: {0}", 'https://go.microsoft.com/fwlink/?linkid=830387');
203 >
204 > let content = [
205 > '{',
206 > `\t// ${comment1}`,
207 > `\t// ${comment2}`,
208 > `\t// ${comment3}`,
209 > `\t"version": "0.2.0",`,
210 > `\t"configurations": ${configs}`,
211 > '}'
212 > ].join(eol);
213 >
214 > // fix formatting
215 > const editorConfig = this.configurationService.getValue<any>();
216 > if (editorConfig.editor && editorConfig.editor.insertSpaces) {
217 content = content.replace(new RegExp('\t', 'g'), ' '.repeat(editorConfig.editor.tabSize));
218 }
220 > return Promise.resolve(content);
221 > }
223 > getMainExtensionDescriptor(): IExtensionDescription {
224 return this.mainExtensionDescription || this.mergedExtensionDescriptions[0];
225 }
227 > getCustomTelemetryEndpoint(): ITelemetryEndpoint | undefined {
228 const aiKey = this.debuggerContribution.aiKey;
229 if (!aiKey) {
230 return undefined;
231 }
232
233 const sendErrorTelemtry = cleanRemoteAuthority(this.environmentService.remoteAuthority, this.productService) !== 'other';
234 return {
235 id: `${this.getMainExtensionDescriptor().publisher}.${this.type}`,
236 aiKey,
237 sendErrorTelemetry: sendErrorTelemtry
238 };
239 }
241 > getSchemaAttributes(definitions: IJSONSchemaMap): IJSONSchema[] | null {
243 > if (!this.debuggerContribution.configurationAttributes) {
244 return null;
245 }
247 > // fill in the default configuration attributes shared by all adapters.
248 > return Object.entries(this.debuggerContribution.configurationAttributes).map(([request, attributes]) => {
249 > const definitionId = `${this.type}:${request}`;
250 > const platformSpecificDefinitionId = `${this.type}:${request}:platform`;
251 > const defaultRequired = ['name', 'type', 'request'];
252 > attributes.required = attributes.required && attributes.required.length ? defaultRequired.concat(attributes.required) : defaultRequired;
253 > attributes.additionalProperties = false;
254 > attributes.type = 'object';
255 > if (!attributes.properties) {
256 attributes.properties = {};
257 }
258 > const properties = attributes.properties; debugger.ts ×5
259 > properties['type'] = {
260 > enum: [this.type],
261 > enumDescriptions: [this.label],
262 > description: nls.localize('debugType', "Type of configuration."),
263 > pattern: '^(?!node2)',
264 > deprecationMessage: this.debuggerContribution.deprecated || (this.enabled ? undefined : debuggerDisabledMessage(this.type)),
265 > doNotSuggest: !!this.debuggerContribution.deprecated,
266 > errorMessage: nls.localize('debugTypeNotRecognised', "The debug type is not recognized. Make sure that you have a corresponding debug extension installed and that it is enabled."),
267 > patternErrorMessage: nls.localize('node2NotSupported', "\"node2\" is no longer supported, use \"node\" instead and set the \"protocol\" attribute to \"inspector\".")
268 > };
269 > properties['request'] = {
270 > enum: [request],
271 > description: nls.localize('debugRequest', "Request type of configuration. Can be \"launch\" or \"attach\"."),
272 > };
273 > for (const prop in definitions['common'].properties) {
274 properties[prop] = {
275 $ref: `#/definitions/common/properties/${prop}`
276 };
277 }
278 > const malformedPropertyNames: string[] = []; debugger.ts ×5
279 > Object.keys(properties).forEach(name => {
280 > const property = properties[name];
281 > // A debugger extension may contribute a malformed property whose value is not a schema
282 > // object (e.g. the bare string 'integer' instead of `{ "type": "integer" }`). Skip those so
283 > // one bad contribution does not throw and abort schema generation for every debugger.
284 > if (isObject(property)) {
285 > // Use schema allOf property to get independent error reporting #21113
286 > ConfigurationResolverUtils.applyDeprecatedVariableMessage(property);
287 > } else {
288 > malformedPropertyNames.push(name);
289 > }
290 > });
291 > if (malformedPropertyNames.length) {
292 > this.logService.warn(`Ignoring malformed debug configuration schema properties for type '${this.type}': ${malformedPropertyNames.join(', ')}`);
293 > }
294 >
295 > definitions[definitionId] = { ...attributes };
296 > definitions[platformSpecificDefinitionId] = {
297 > type: 'object',
298 > additionalProperties: false,
299 > properties: filter(properties, key => key !== 'type' && key !== 'request' && key !== 'name')
300 > };
301 >
302 > // Don't add the OS props to the real attributes object so they don't show up in 'definitions'
303 > const attributesCopy = { ...attributes };
304 > attributesCopy.properties = {
305 > ...properties,
306 > ...{
307 > windows: {
308 > $ref: `#/definitions/${platformSpecificDefinitionId}`,
309 > description: nls.localize('debugWindowsConfiguration', "Windows specific launch configuration attributes."),
310 > },
311 > osx: {
312 > $ref: `#/definitions/${platformSpecificDefinitionId}`,
313 > description: nls.localize('debugOSXConfiguration', "OS X specific launch configuration attributes."),
314 > },
315 > linux: {
316 > $ref: `#/definitions/${platformSpecificDefinitionId}`,
317 > description: nls.localize('debugLinuxConfiguration', "Linux specific launch configuration attributes."),
318 > }
319 > }
320 > };
321 >
322 > return attributesCopy;
323 > });
324 > }