Skip to content

Commit 9a72cf0

Browse files
committed
null checking in debugger.ts
1 parent b91adad commit 9a72cf0

4 files changed

Lines changed: 48 additions & 37 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
"./vs/workbench/contrib/debug/common/debugViewModel.ts",
244244
"./vs/workbench/contrib/debug/electron-browser/rawDebugSession.ts",
245245
"./vs/workbench/contrib/debug/node/debugAdapter.ts",
246+
"./vs/workbench/contrib/debug/node/debugger.ts",
246247
"./vs/workbench/contrib/debug/node/telemetryApp.ts",
247248
"./vs/workbench/contrib/debug/test/common/debugSource.test.ts",
248249
"./vs/workbench/contrib/debug/test/common/debugUtils.test.ts",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export interface IExpression extends IReplElement, IExpressionContainer {
112112
export interface IDebugger {
113113
createDebugAdapter(session: IDebugSession, outputService: IOutputService): Promise<IDebugAdapter>;
114114
runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments): Promise<number | undefined>;
115-
getCustomTelemetryService(): Promise<TelemetryService>;
115+
getCustomTelemetryService(): Promise<TelemetryService | undefined>;
116116
}
117117

118118
export const enum State {
@@ -516,7 +516,7 @@ export interface IPlatformSpecificAdapterContribution {
516516
}
517517

518518
export interface IDebuggerContribution extends IPlatformSpecificAdapterContribution {
519-
type?: string;
519+
type: string;
520520
label?: string;
521521
// debug adapter executable
522522
adapterExecutableCommand?: string;

src/vs/workbench/contrib/debug/node/debugAdapter.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,33 +435,35 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter {
435435
}
436436
}
437437

438-
private static extract(contribution: IDebuggerContribution, extensionFolderPath: string): IDebuggerContribution | undefined {
439-
if (!contribution) {
438+
private static extract(platformContribution: IPlatformSpecificAdapterContribution, extensionFolderPath: string): IDebuggerContribution | undefined {
439+
if (!platformContribution) {
440440
return undefined;
441441
}
442442

443443
const result: IDebuggerContribution = Object.create(null);
444-
if (contribution.runtime) {
445-
if (contribution.runtime.indexOf('./') === 0) { // TODO
446-
result.runtime = path.join(extensionFolderPath, contribution.runtime);
444+
if (platformContribution.runtime) {
445+
if (platformContribution.runtime.indexOf('./') === 0) { // TODO
446+
result.runtime = path.join(extensionFolderPath, platformContribution.runtime);
447447
} else {
448-
result.runtime = contribution.runtime;
448+
result.runtime = platformContribution.runtime;
449449
}
450450
}
451-
if (contribution.runtimeArgs) {
452-
result.runtimeArgs = contribution.runtimeArgs;
451+
if (platformContribution.runtimeArgs) {
452+
result.runtimeArgs = platformContribution.runtimeArgs;
453453
}
454-
if (contribution.program) {
455-
if (!path.isAbsolute(contribution.program)) {
456-
result.program = path.join(extensionFolderPath, contribution.program);
454+
if (platformContribution.program) {
455+
if (!path.isAbsolute(platformContribution.program)) {
456+
result.program = path.join(extensionFolderPath, platformContribution.program);
457457
} else {
458-
result.program = contribution.program;
458+
result.program = platformContribution.program;
459459
}
460460
}
461-
if (contribution.args) {
462-
result.args = contribution.args;
461+
if (platformContribution.args) {
462+
result.args = platformContribution.args;
463463
}
464464

465+
const contribution = platformContribution as IDebuggerContribution;
466+
465467
if (contribution.win) {
466468
result.win = ExecutableDebugAdapter.extract(contribution.win, extensionFolderPath);
467469
}
@@ -490,7 +492,7 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter {
490492
const debuggers = <IDebuggerContribution[]>ed.contributes['debuggers'];
491493
if (debuggers && debuggers.length > 0) {
492494
debuggers.filter(dbg => typeof dbg.type === 'string' && strings.equalsIgnoreCase(dbg.type, debugType)).forEach(dbg => {
493-
// extract relevant attributes and make then absolute where needed
495+
// extract relevant attributes and make them absolute where needed
494496
const extractedDbg = ExecutableDebugAdapter.extract(dbg, ed.extensionLocation.fsPath);
495497

496498
// merge

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { isDebuggerMainContribution } from 'vs/workbench/contrib/debug/common/de
3131

3232
export class Debugger implements IDebugger {
3333

34-
private debuggerContribution: IDebuggerContribution = {};
34+
private debuggerContribution: IDebuggerContribution;
3535
private mergedExtensionDescriptions: IExtensionDescription[] = [];
3636
private mainExtensionDescription: IExtensionDescription | undefined;
3737

@@ -42,6 +42,7 @@ export class Debugger implements IDebugger {
4242
@IConfigurationResolverService private readonly configurationResolverService: IConfigurationResolverService,
4343
@ITelemetryService private readonly telemetryService: ITelemetryService,
4444
) {
45+
this.debuggerContribution = { type: dbgContribution.type };
4546
this.merge(dbgContribution, extensionDescription);
4647
}
4748

@@ -149,12 +150,15 @@ export class Debugger implements IDebugger {
149150
if (this.debuggerContribution.adapterExecutableCommand) {
150151
console.info('debugAdapterExecutable attribute in package.json is deprecated and support for it will be removed soon; please use DebugAdapterDescriptorFactory.createDebugAdapterDescriptor instead.');
151152
const rootFolder = session.root ? session.root.uri.toString() : undefined;
152-
return this.commandService.executeCommand<IDebugAdapterExecutable>(this.debuggerContribution.adapterExecutableCommand, rootFolder).then((ae: { command: string, args: string[] }) => {
153-
return <IAdapterDescriptor>{
154-
type: 'executable',
155-
command: ae.command,
156-
args: ae.args || []
157-
};
153+
return this.commandService.executeCommand<IDebugAdapterExecutable>(this.debuggerContribution.adapterExecutableCommand, rootFolder).then(ae => {
154+
if (ae) {
155+
return <IAdapterDescriptor>{
156+
type: 'executable',
157+
command: ae.command,
158+
args: ae.args || []
159+
};
160+
}
161+
throw new Error('command adapterExecutableCommand did not return proper command.');
158162
});
159163
}
160164

@@ -197,15 +201,15 @@ export class Debugger implements IDebugger {
197201
return this.debuggerContribution.type;
198202
}
199203

200-
get variables(): { [key: string]: string } {
204+
get variables(): { [key: string]: string } | undefined {
201205
return this.debuggerContribution.variables;
202206
}
203207

204-
get configurationSnippets(): IJSONSchemaSnippet[] {
208+
get configurationSnippets(): IJSONSchemaSnippet[] | undefined {
205209
return this.debuggerContribution.configurationSnippets;
206210
}
207211

208-
get languages(): string[] {
212+
get languages(): string[] | undefined {
209213
return this.debuggerContribution.languages;
210214
}
211215

@@ -254,8 +258,11 @@ export class Debugger implements IDebugger {
254258
}
255259

256260
@memoize
257-
getCustomTelemetryService(): Promise<TelemetryService> {
258-
if (!this.debuggerContribution.aiKey) {
261+
getCustomTelemetryService(): Promise<TelemetryService | undefined> {
262+
263+
const aiKey = this.debuggerContribution.aiKey;
264+
265+
if (!aiKey) {
259266
return Promise.resolve(undefined);
260267
}
261268

@@ -270,7 +277,7 @@ export class Debugger implements IDebugger {
270277
{
271278
serverName: 'Debug Telemetry',
272279
timeout: 1000 * 60 * 5,
273-
args: [`${this.getMainExtensionDescriptor().publisher}.${this.type}`, JSON.stringify(data), this.debuggerContribution.aiKey],
280+
args: [`${this.getMainExtensionDescriptor().publisher}.${this.type}`, JSON.stringify(data), aiKey],
274281
env: {
275282
ELECTRON_RUN_AS_NODE: 1,
276283
PIPE_LOGGING: 'true',
@@ -286,10 +293,12 @@ export class Debugger implements IDebugger {
286293
});
287294
}
288295

289-
getSchemaAttributes(): IJSONSchema[] {
296+
getSchemaAttributes(): IJSONSchema[] | null {
297+
290298
if (!this.debuggerContribution.configurationAttributes) {
291299
return null;
292300
}
301+
293302
// fill in the default configuration attributes shared by all adapters.
294303
const taskSchema = TaskDefinitionRegistry.getJsonSchema();
295304
return Object.keys(this.debuggerContribution.configurationAttributes).map(request => {
@@ -339,9 +348,9 @@ export class Debugger implements IDebugger {
339348
};
340349
properties['internalConsoleOptions'] = INTERNAL_CONSOLE_OPTIONS_SCHEMA;
341350
// Clear out windows, linux and osx fields to not have cycles inside the properties object
342-
properties['windows'] = undefined;
343-
properties['osx'] = undefined;
344-
properties['linux'] = undefined;
351+
delete properties['windows'];
352+
delete properties['osx'];
353+
delete properties['linux'];
345354

346355
const osProperties = objects.deepClone(properties);
347356
properties['windows'] = {
@@ -359,11 +368,10 @@ export class Debugger implements IDebugger {
359368
description: nls.localize('debugLinuxConfiguration', "Linux specific launch configuration attributes."),
360369
properties: osProperties
361370
};
362-
Object.keys(attributes.properties).forEach(name => {
371+
Object.keys(properties).forEach(name => {
363372
// Use schema allOf property to get independent error reporting #21113
364-
ConfigurationResolverUtils.applyDeprecatedVariableMessage(attributes.properties[name]);
373+
ConfigurationResolverUtils.applyDeprecatedVariableMessage(properties[name]);
365374
});
366-
367375
return attributes;
368376
});
369377
}

0 commit comments

Comments
 (0)