提交 9a72cf08 编写于 作者: A Andre Weinand

null checking in debugger.ts

上级 b91adad1
......@@ -243,6 +243,7 @@
"./vs/workbench/contrib/debug/common/debugViewModel.ts",
"./vs/workbench/contrib/debug/electron-browser/rawDebugSession.ts",
"./vs/workbench/contrib/debug/node/debugAdapter.ts",
"./vs/workbench/contrib/debug/node/debugger.ts",
"./vs/workbench/contrib/debug/node/telemetryApp.ts",
"./vs/workbench/contrib/debug/test/common/debugSource.test.ts",
"./vs/workbench/contrib/debug/test/common/debugUtils.test.ts",
......
......@@ -112,7 +112,7 @@ export interface IExpression extends IReplElement, IExpressionContainer {
export interface IDebugger {
createDebugAdapter(session: IDebugSession, outputService: IOutputService): Promise<IDebugAdapter>;
runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments): Promise<number | undefined>;
getCustomTelemetryService(): Promise<TelemetryService>;
getCustomTelemetryService(): Promise<TelemetryService | undefined>;
}
export const enum State {
......@@ -516,7 +516,7 @@ export interface IPlatformSpecificAdapterContribution {
}
export interface IDebuggerContribution extends IPlatformSpecificAdapterContribution {
type?: string;
type: string;
label?: string;
// debug adapter executable
adapterExecutableCommand?: string;
......
......@@ -435,33 +435,35 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter {
}
}
private static extract(contribution: IDebuggerContribution, extensionFolderPath: string): IDebuggerContribution | undefined {
if (!contribution) {
private static extract(platformContribution: IPlatformSpecificAdapterContribution, extensionFolderPath: string): IDebuggerContribution | undefined {
if (!platformContribution) {
return undefined;
}
const result: IDebuggerContribution = Object.create(null);
if (contribution.runtime) {
if (contribution.runtime.indexOf('./') === 0) { // TODO
result.runtime = path.join(extensionFolderPath, contribution.runtime);
if (platformContribution.runtime) {
if (platformContribution.runtime.indexOf('./') === 0) { // TODO
result.runtime = path.join(extensionFolderPath, platformContribution.runtime);
} else {
result.runtime = contribution.runtime;
result.runtime = platformContribution.runtime;
}
}
if (contribution.runtimeArgs) {
result.runtimeArgs = contribution.runtimeArgs;
if (platformContribution.runtimeArgs) {
result.runtimeArgs = platformContribution.runtimeArgs;
}
if (contribution.program) {
if (!path.isAbsolute(contribution.program)) {
result.program = path.join(extensionFolderPath, contribution.program);
if (platformContribution.program) {
if (!path.isAbsolute(platformContribution.program)) {
result.program = path.join(extensionFolderPath, platformContribution.program);
} else {
result.program = contribution.program;
result.program = platformContribution.program;
}
}
if (contribution.args) {
result.args = contribution.args;
if (platformContribution.args) {
result.args = platformContribution.args;
}
const contribution = platformContribution as IDebuggerContribution;
if (contribution.win) {
result.win = ExecutableDebugAdapter.extract(contribution.win, extensionFolderPath);
}
......@@ -490,7 +492,7 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter {
const debuggers = <IDebuggerContribution[]>ed.contributes['debuggers'];
if (debuggers && debuggers.length > 0) {
debuggers.filter(dbg => typeof dbg.type === 'string' && strings.equalsIgnoreCase(dbg.type, debugType)).forEach(dbg => {
// extract relevant attributes and make then absolute where needed
// extract relevant attributes and make them absolute where needed
const extractedDbg = ExecutableDebugAdapter.extract(dbg, ed.extensionLocation.fsPath);
// merge
......
......@@ -31,7 +31,7 @@ import { isDebuggerMainContribution } from 'vs/workbench/contrib/debug/common/de
export class Debugger implements IDebugger {
private debuggerContribution: IDebuggerContribution = {};
private debuggerContribution: IDebuggerContribution;
private mergedExtensionDescriptions: IExtensionDescription[] = [];
private mainExtensionDescription: IExtensionDescription | undefined;
......@@ -42,6 +42,7 @@ export class Debugger implements IDebugger {
@IConfigurationResolverService private readonly configurationResolverService: IConfigurationResolverService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
) {
this.debuggerContribution = { type: dbgContribution.type };
this.merge(dbgContribution, extensionDescription);
}
......@@ -149,12 +150,15 @@ export class Debugger implements IDebugger {
if (this.debuggerContribution.adapterExecutableCommand) {
console.info('debugAdapterExecutable attribute in package.json is deprecated and support for it will be removed soon; please use DebugAdapterDescriptorFactory.createDebugAdapterDescriptor instead.');
const rootFolder = session.root ? session.root.uri.toString() : undefined;
return this.commandService.executeCommand<IDebugAdapterExecutable>(this.debuggerContribution.adapterExecutableCommand, rootFolder).then((ae: { command: string, args: string[] }) => {
return <IAdapterDescriptor>{
type: 'executable',
command: ae.command,
args: ae.args || []
};
return this.commandService.executeCommand<IDebugAdapterExecutable>(this.debuggerContribution.adapterExecutableCommand, rootFolder).then(ae => {
if (ae) {
return <IAdapterDescriptor>{
type: 'executable',
command: ae.command,
args: ae.args || []
};
}
throw new Error('command adapterExecutableCommand did not return proper command.');
});
}
......@@ -197,15 +201,15 @@ export class Debugger implements IDebugger {
return this.debuggerContribution.type;
}
get variables(): { [key: string]: string } {
get variables(): { [key: string]: string } | undefined {
return this.debuggerContribution.variables;
}
get configurationSnippets(): IJSONSchemaSnippet[] {
get configurationSnippets(): IJSONSchemaSnippet[] | undefined {
return this.debuggerContribution.configurationSnippets;
}
get languages(): string[] {
get languages(): string[] | undefined {
return this.debuggerContribution.languages;
}
......@@ -254,8 +258,11 @@ export class Debugger implements IDebugger {
}
@memoize
getCustomTelemetryService(): Promise<TelemetryService> {
if (!this.debuggerContribution.aiKey) {
getCustomTelemetryService(): Promise<TelemetryService | undefined> {
const aiKey = this.debuggerContribution.aiKey;
if (!aiKey) {
return Promise.resolve(undefined);
}
......@@ -270,7 +277,7 @@ export class Debugger implements IDebugger {
{
serverName: 'Debug Telemetry',
timeout: 1000 * 60 * 5,
args: [`${this.getMainExtensionDescriptor().publisher}.${this.type}`, JSON.stringify(data), this.debuggerContribution.aiKey],
args: [`${this.getMainExtensionDescriptor().publisher}.${this.type}`, JSON.stringify(data), aiKey],
env: {
ELECTRON_RUN_AS_NODE: 1,
PIPE_LOGGING: 'true',
......@@ -286,10 +293,12 @@ export class Debugger implements IDebugger {
});
}
getSchemaAttributes(): IJSONSchema[] {
getSchemaAttributes(): IJSONSchema[] | null {
if (!this.debuggerContribution.configurationAttributes) {
return null;
}
// fill in the default configuration attributes shared by all adapters.
const taskSchema = TaskDefinitionRegistry.getJsonSchema();
return Object.keys(this.debuggerContribution.configurationAttributes).map(request => {
......@@ -339,9 +348,9 @@ export class Debugger implements IDebugger {
};
properties['internalConsoleOptions'] = INTERNAL_CONSOLE_OPTIONS_SCHEMA;
// Clear out windows, linux and osx fields to not have cycles inside the properties object
properties['windows'] = undefined;
properties['osx'] = undefined;
properties['linux'] = undefined;
delete properties['windows'];
delete properties['osx'];
delete properties['linux'];
const osProperties = objects.deepClone(properties);
properties['windows'] = {
......@@ -359,11 +368,10 @@ export class Debugger implements IDebugger {
description: nls.localize('debugLinuxConfiguration', "Linux specific launch configuration attributes."),
properties: osProperties
};
Object.keys(attributes.properties).forEach(name => {
Object.keys(properties).forEach(name => {
// Use schema allOf property to get independent error reporting #21113
ConfigurationResolverUtils.applyDeprecatedVariableMessage(attributes.properties[name]);
ConfigurationResolverUtils.applyDeprecatedVariableMessage(properties[name]);
});
return attributes;
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册