diff --git a/src/vs/workbench/api/node/extHostApiCommands.ts b/src/vs/workbench/api/node/extHostApiCommands.ts index c56ddbb3733..d4bf26e343e 100644 --- a/src/vs/workbench/api/node/extHostApiCommands.ts +++ b/src/vs/workbench/api/node/extHostApiCommands.ts @@ -188,6 +188,15 @@ class ExtHostApiCommands { { name: 'newWindow', description: '(optional) Wether to open the folder in a new window or the same. Defaults to opening in the same window.', constraint: value => value === void 0 || typeof value === 'boolean' } ] }); + + this._register('vscode.startDebug', (configurationName?: string) => { + return this._commands.executeCommand('_workbench.startDebug', configurationName); + }, { + description: 'Start a debugging session.', + args: [ + { name: 'configurationName', description: '(optional) Name of the debug configuration from \'launch.json\' to use.' } + ] + }); } // --- command impl diff --git a/src/vs/workbench/parts/debug/browser/debugActionItems.ts b/src/vs/workbench/parts/debug/browser/debugActionItems.ts index 5ff87faed7e..ae050357f6f 100644 --- a/src/vs/workbench/parts/debug/browser/debugActionItems.ts +++ b/src/vs/workbench/parts/debug/browser/debugActionItems.ts @@ -40,14 +40,17 @@ export class SelectConfigActionItem extends BaseActionItem { this.select.disabled = state !== State.Inactive; })); this.toDispose.push(configurationService.onDidUpdateConfiguration(e => { - this.setOptions().done(null, errors.onUnexpectedError); + this.setOptions(true).done(null, errors.onUnexpectedError); + })); + this.toDispose.push(this.debugService.getConfigurationManager().onDidConfigurationChange(name => { + this.setOptions(false).done(null, errors.onUnexpectedError); })); } public render(container: HTMLElement): void { dom.addClass(container, 'select-container'); container.appendChild(this.select); - this.setOptions().done(null, errors.onUnexpectedError); + this.setOptions(true).done(null, errors.onUnexpectedError); } public focus(): void { @@ -62,7 +65,7 @@ export class SelectConfigActionItem extends BaseActionItem { } } - private setOptions(): TPromise { + private setOptions(changeDebugConfiguration: boolean): TPromise { let previousSelectedIndex = this.select.selectedIndex; this.select.options.length = 0; @@ -91,7 +94,9 @@ export class SelectConfigActionItem extends BaseActionItem { previousSelectedIndex = 0; } this.select.selectedIndex = previousSelectedIndex; - return this.actionRunner.run(this._action, configurations[previousSelectedIndex].name); + if (changeDebugConfiguration) { + return this.actionRunner.run(this._action, configurations[previousSelectedIndex].name); + } } }); } diff --git a/src/vs/workbench/parts/debug/electron-browser/debug.contribution.ts b/src/vs/workbench/parts/debug/electron-browser/debug.contribution.ts index 83889ef0cd7..7fc5dd4edb1 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debug.contribution.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debug.contribution.ts @@ -6,15 +6,18 @@ 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'; import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import platform = require('vs/platform/platform'); import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KbExpr, IKeybindings } from 'vs/platform/keybinding/common/keybindingService'; -import { EditorBrowserRegistry } from 'vs/editor/browser/editorBrowserExtensions'; +import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import wbaregistry = require('vs/workbench/common/actionRegistry'); import viewlet = require('vs/workbench/browser/viewlet'); import panel = require('vs/workbench/browser/panel'); @@ -113,5 +116,17 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(dbgactions.AddFunction registry.registerWorkbenchAction(new SyncActionDescriptor(dbgactions.ReapplyBreakpointsAction, dbgactions.ReapplyBreakpointsAction.ID, dbgactions.ReapplyBreakpointsAction.LABEL), 'Debug: Reapply All Breakpoints', debugCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(dbgactions.RunAction, dbgactions.RunAction.ID, dbgactions.RunAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.F5 }, KbExpr.not(debug.CONTEXT_IN_DEBUG_MODE)), 'Debug: Start Without Debugging', debugCategory); +KeybindingsRegistry.registerCommandDesc({ + id: '_workbench.startDebug', + weight: KeybindingsRegistry.WEIGHT.workbenchContrib(0), + handler(accessor: ServicesAccessor, configurationName: string) { + const debugService = accessor.get(debug.IDebugService); + (configurationName ? debugService.getConfigurationManager().setConfiguration(configurationName) : TPromise.as(null)) + .done(() => debugService.createSession(false), errors.onUnexpectedError); + }, + when: KbExpr.not(debug.CONTEXT_IN_DEBUG_MODE), + primary: undefined +}); + // register service registerSingleton(IDebugService, service.DebugService); diff --git a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts index a7d4dcc4351..f3acc177c32 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts @@ -27,15 +27,16 @@ import IDebugService = debug.IDebugService; export class AbstractDebugAction extends actions.Action { - protected debugService: IDebugService; - private keybindingService: IKeybindingService; protected toDispose: lifecycle.IDisposable[]; private keybinding: string; - constructor(id: string, label: string, cssClass: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { + constructor( + id: string, label: string, cssClass: string, + @IDebugService protected debugService: IDebugService, + @IKeybindingService protected keybindingService: IKeybindingService + ) { super(id, label, cssClass, false); this.debugService = debugService; - this.keybindingService = keybindingService; this.toDispose = []; this.toDispose.push(this.debugService.onDidChangeState((state) => this.updateEnablement(state))); @@ -119,7 +120,7 @@ export class StartDebugAction extends AbstractDebugAction { } public run(): TPromise { - return this.debugService.createSession(false); + return this.keybindingService.executeCommand('_workbench.startDebug'); } protected isEnabled(state: debug.State): boolean {