Skip to content

Commit

Permalink
debug: allow vscode.startDebug to pass full json config
Browse files Browse the repository at this point in the history
fixes #4615
  • Loading branch information
isidorn committed May 10, 2016
1 parent fabda7b commit 1ef6a70
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/vs/workbench/api/node/extHostApiCommands.ts
Expand Up @@ -189,12 +189,12 @@ class ExtHostApiCommands {
]
});

this._register('vscode.startDebug', (configurationName?: string) => {
return this._commands.executeCommand('_workbench.startDebug', configurationName);
this._register('vscode.startDebug', (configuration?: any) => {
return this._commands.executeCommand('_workbench.startDebug', configuration);
}, {
description: 'Start a debugging session.',
args: [
{ name: 'configurationName', description: '(optional) Name of the debug configuration from \'launch.json\' to use.' }
{ name: 'configuration', description: '(optional) Name of the debug configuration from \'launch.json\' to use. Or a configuration json object to use.' }
]
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/common/debug.ts
Expand Up @@ -372,7 +372,7 @@ export interface IDebugService {
/**
* Creates a new debug session. Depending on the configuration will either 'launch' or 'attach'.
*/
createSession(noDebug: boolean): TPromise<any>;
createSession(noDebug: boolean, configuration?: IConfig): TPromise<any>;

/**
* Restarts an active debug session or creates a new one if there is no active session.
Expand Down
Expand Up @@ -6,9 +6,7 @@
import 'vs/css!../browser/media/debug.contribution';
import 'vs/css!../browser/media/debugHover';
import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import errors = require('vs/base/common/errors');
import editorcommon = require('vs/editor/common/editorCommon');
import { CommonEditorRegistry, ContextKey, EditorActionDescriptor } from 'vs/editor/common/editorCommonExtensions';
import { EditorBrowserRegistry } from 'vs/editor/browser/editorBrowserExtensions';
Expand Down Expand Up @@ -119,10 +117,14 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(dbgactions.RunAction,
KeybindingsRegistry.registerCommandDesc({
id: '_workbench.startDebug',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(0),
handler(accessor: ServicesAccessor, configurationName: string) {
handler(accessor: ServicesAccessor, configuration: any) {
const debugService = accessor.get(debug.IDebugService);
(configurationName ? debugService.getConfigurationManager().setConfiguration(configurationName) : TPromise.as(null))
.done(() => debugService.createSession(false), errors.onUnexpectedError);
if (typeof configuration === 'string') {
return debugService.getConfigurationManager().setConfiguration(configuration)
.then(() => debugService.createSession(false));
}

return debugService.createSession(false, configuration);
},
when: KbExpr.not(debug.CONTEXT_IN_DEBUG_MODE),
primary: undefined
Expand Down
103 changes: 52 additions & 51 deletions src/vs/workbench/parts/debug/electron-browser/debugService.ts
Expand Up @@ -486,58 +486,59 @@ export class DebugService implements debug.IDebugService {
this.model.removeWatchExpressions(id);
}

public createSession(noDebug: boolean, changeViewState = !this.partService.isSideBarHidden()): TPromise<any> {
public createSession(noDebug: boolean, configuration?: debug.IConfig, changeViewState = !this.partService.isSideBarHidden()): TPromise<any> {
this.removeReplExpressions();

return this.textFileService.saveAll() // make sure all dirty files are saved
return this.textFileService.saveAll() // make sure all dirty files are saved
.then(() => this.configurationService.loadConfiguration() // make sure configuration is up to date
.then(() => this.extensionService.onReady()
.then(() => this.configurationManager.setConfiguration((this.configurationManager.configurationName))
.then(() => {
const configuration = this.configurationManager.configuration;
if (!configuration) {
return this.configurationManager.openConfigFile(false).then(openend => {
if (openend) {
this.messageService.show(severity.Info, nls.localize('NewLaunchConfig', "Please set up the launch configuration file for your application."));
}
});
}

configuration.noDebug = noDebug;
if (!this.configurationManager.adapter) {
return configuration.type ? TPromise.wrapError(new Error(nls.localize('debugTypeNotSupported', "Configured debug type '{0}' is not supported.", configuration.type)))
: TPromise.wrapError(errors.create(nls.localize('debugTypeMissing', "Missing property 'type' for the selected configuration in launch.json."),
{ actions: [CloseAction, this.instantiationService.createInstance(debugactions.ConfigureAction, debugactions.ConfigureAction.ID, debugactions.ConfigureAction.LABEL)] }));
}

return this.runPreLaunchTask(configuration.preLaunchTask).then((taskSummary: ITaskSummary) => {
const errorCount = configuration.preLaunchTask ? this.markerService.getStatistics().errors : 0;
const successExitCode = taskSummary && taskSummary.exitCode === 0;
const failureExitCode = taskSummary && taskSummary.exitCode !== undefined && taskSummary.exitCode !== 0;
if (successExitCode || (errorCount === 0 && !failureExitCode)) {
return this.doCreateSession(configuration, changeViewState);
}

this.messageService.show(severity.Error, {
message: errorCount > 1 ? nls.localize('preLaunchTaskErrors', "Build errors have been detected during preLaunchTask '{0}'.", configuration.preLaunchTask) :
errorCount === 1 ? nls.localize('preLaunchTaskError', "Build error has been detected during preLaunchTask '{0}'.", configuration.preLaunchTask) :
nls.localize('preLaunchTaskExitCode', "The preLaunchTask '{0}' terminated with exit code {1}.", configuration.preLaunchTask, taskSummary.exitCode),
actions: [CloseAction, new Action('debug.continue', nls.localize('debugAnyway', "Debug Anyway"), null, true, () => {
this.messageService.hideAll();
return this.doCreateSession(configuration, changeViewState);
})]
});
}, (err: TaskError) => {
if (err.code !== TaskErrors.NotConfigured) {
throw err;
}

this.messageService.show(err.severity, {
message: err.message,
actions: [CloseAction, this.taskService.configureAction()]
});
});
}))));
.then(() => this.extensionService.onReady()
.then(() => this.configurationManager.setConfiguration((this.configurationManager.configurationName))
.then(() => {
this.configurationManager.resloveConfiguration(configuration);
configuration = configuration || this.configurationManager.configuration;
if (!configuration) {
return this.configurationManager.openConfigFile(false).then(openend => {
if (openend) {
this.messageService.show(severity.Info, nls.localize('NewLaunchConfig', "Please set up the launch configuration file for your application."));
}
});
}

configuration.noDebug = noDebug;
if (!this.configurationManager.adapter) {
return configuration.type ? TPromise.wrapError(new Error(nls.localize('debugTypeNotSupported', "Configured debug type '{0}' is not supported.", configuration.type)))
: TPromise.wrapError(errors.create(nls.localize('debugTypeMissing', "Missing property 'type' for the selected configuration in launch.json."),
{ actions: [CloseAction, this.instantiationService.createInstance(debugactions.ConfigureAction, debugactions.ConfigureAction.ID, debugactions.ConfigureAction.LABEL)] }));
}

return this.runPreLaunchTask(configuration.preLaunchTask).then((taskSummary: ITaskSummary) => {
const errorCount = configuration.preLaunchTask ? this.markerService.getStatistics().errors : 0;
const successExitCode = taskSummary && taskSummary.exitCode === 0;
const failureExitCode = taskSummary && taskSummary.exitCode !== undefined && taskSummary.exitCode !== 0;
if (successExitCode || (errorCount === 0 && !failureExitCode)) {
return this.doCreateSession(configuration, changeViewState);
}

this.messageService.show(severity.Error, {
message: errorCount > 1 ? nls.localize('preLaunchTaskErrors', "Build errors have been detected during preLaunchTask '{0}'.", configuration.preLaunchTask) :
errorCount === 1 ? nls.localize('preLaunchTaskError', "Build error has been detected during preLaunchTask '{0}'.", configuration.preLaunchTask) :
nls.localize('preLaunchTaskExitCode', "The preLaunchTask '{0}' terminated with exit code {1}.", configuration.preLaunchTask, taskSummary.exitCode),
actions: [CloseAction, new Action('debug.continue', nls.localize('debugAnyway', "Debug Anyway"), null, true, () => {
this.messageService.hideAll();
return this.doCreateSession(configuration, changeViewState);
})]
});
}, (err: TaskError) => {
if (err.code !== TaskErrors.NotConfigured) {
throw err;
}

this.messageService.show(err.severity, {
message: err.message,
actions: [CloseAction, this.taskService.configureAction()]
});
});
}))));
}

private doCreateSession(configuration: debug.IConfig, changeViewState: boolean): TPromise<any> {
Expand Down Expand Up @@ -679,10 +680,10 @@ export class DebugService implements debug.IDebugService {
return this.session ? this.session.disconnect(true).then(() =>
new TPromise<void>((c, e) => {
setTimeout(() => {
this.createSession(false, false).then(() => c(null), err => e(err));
this.createSession(false, null, false).then(() => c(null), err => e(err));
}, 300);
})
) : this.createSession(false, false);
) : this.createSession(false, null, false);
}

public getActiveSession(): debug.IRawDebugSession {
Expand Down
14 changes: 9 additions & 5 deletions src/vs/workbench/parts/debug/node/debugConfigurationManager.ts
Expand Up @@ -241,16 +241,20 @@ export class ConfigurationManager implements debug.IConfigurationManager {
// massage configuration attributes - append workspace path to relatvie paths, substitute variables in paths.
this.configuration = filtered.length === 1 ? objects.deepClone(filtered[0]) : null;
if (this.configuration) {
if (this.systemVariables) {
Object.keys(this.configuration).forEach(key => {
this.configuration[key] = this.systemVariables.resolveAny(this.configuration[key]);
});
}
this.resloveConfiguration(this.configuration);
this.configuration.debugServer = config.debugServer;
}
}).then(() => this._onDidConfigurationChange.fire(this.configurationName));
}

public resloveConfiguration(configuration: debug.IConfig) {
if (this.systemVariables && configuration) {
Object.keys(configuration).forEach(key => {
configuration[key] = this.systemVariables.resolveAny(configuration[key]);
});
}
}

public openConfigFile(sideBySide: boolean): TPromise<boolean> {
const resource = uri.file(paths.join(this.contextService.getWorkspace().resource.fsPath, '/.vscode/launch.json'));

Expand Down

0 comments on commit 1ef6a70

Please sign in to comment.