From 943835bf776b68580d23555a2d1f7943197b1571 Mon Sep 17 00:00:00 2001 From: isidor Date: Wed, 31 Aug 2016 12:36:19 +0200 Subject: [PATCH] debug: remove isAttach field from debugService, get it from configuration fixes #11163 --- .../parts/debug/browser/debugActionItems.ts | 5 +++-- .../workbench/parts/debug/browser/debugActions.ts | 15 +++++++-------- .../parts/debug/browser/debugActionsWidget.ts | 5 +++-- src/vs/workbench/parts/debug/common/debug.ts | 6 +++--- .../debug/electron-browser/debug.contribution.ts | 2 +- .../parts/debug/electron-browser/debugService.ts | 6 +----- .../debug/electron-browser/rawDebugSession.ts | 8 ++------ .../parts/debug/node/debugConfigurationManager.ts | 8 ++++---- .../parts/debug/test/common/mockDebugService.ts | 3 +-- 9 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/vs/workbench/parts/debug/browser/debugActionItems.ts b/src/vs/workbench/parts/debug/browser/debugActionItems.ts index e8e0008aff5..4bb92482f06 100644 --- a/src/vs/workbench/parts/debug/browser/debugActionItems.ts +++ b/src/vs/workbench/parts/debug/browser/debugActionItems.ts @@ -38,14 +38,15 @@ export class DebugSelectActionItem extends SelectActionItem { } private updateOptions(changeDebugConfiguration: boolean): TPromise { - return this.debugService.getConfigurationManager().loadLaunchConfig().then(config => { + const configurationManager = this.debugService.getConfigurationManager(); + return configurationManager.loadLaunchConfig().then(config => { if (!config || !config.configurations || config.configurations.length === 0) { this.setOptions([nls.localize('noConfigurations', "No Configurations")], 0); return changeDebugConfiguration ? this.actionRunner.run(this._action, null) : null; } const configurationNames = config.configurations.filter(cfg => !!cfg.name).map(cfg => cfg.name); - const configurationName = this.debugService.getConfigurationManager().configurationName; + const configurationName = configurationManager.configuration ? configurationManager.configuration.name : null; let selected = configurationNames.indexOf(configurationName); this.setOptions(configurationNames, selected); diff --git a/src/vs/workbench/parts/debug/browser/debugActions.ts b/src/vs/workbench/parts/debug/browser/debugActions.ts index a61ca97a545..6e7204854db 100644 --- a/src/vs/workbench/parts/debug/browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/browser/debugActions.ts @@ -142,12 +142,12 @@ export class RestartAction extends AbstractDebugAction { constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { super(id, label, 'debug-action restart', debugService, keybindingService); - this.toDispose.push(this.debugService.onDidChangeState(() => { - const session = this.debugService.getActiveSession(); - if (session) { - this.updateLabel(session.configuration.isAttach ? RestartAction.RECONNECT_LABEL : RestartAction.LABEL); - } - })); + this.setLabel(this.debugService.getConfigurationManager().configuration); + this.toDispose.push(this.debugService.getConfigurationManager().onDidConfigurationChange(config => this.setLabel(config))); + } + + private setLabel(config: debug.IConfig): void { + this.updateLabel(config.request === 'attach' ? RestartAction.RECONNECT_LABEL : RestartAction.LABEL); } public run(): TPromise { @@ -273,8 +273,7 @@ export class DisconnectAction extends AbstractDebugAction { } protected isEnabled(state: debug.State): boolean { - const session = this.debugService.getActiveSession(); - return super.isEnabled(state) && state !== debug.State.Inactive && session && session.configuration.isAttach; + return super.isEnabled(state) && state !== debug.State.Inactive; } } diff --git a/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts b/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts index a5377113885..8b4161d4d37 100644 --- a/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts +++ b/src/vs/workbench/parts/debug/browser/debugActionsWidget.ts @@ -180,10 +180,11 @@ export class DebugActionsWidget implements wbext.IWorkbenchContribution { this.toDispose.push(this.pauseAction); this.toDispose.push(this.disconnectAction); } - + this.actions[0] = state === debug.State.Running ? this.pauseAction : this.continueAction; const session = this.debugService.getActiveSession(); - this.actions[5] = session && session.configuration.isAttach ? this.disconnectAction : this.stopAction; + const configuration = this.debugService.getConfigurationManager().configuration; + this.actions[5] = configuration && configuration.request === 'attach' ? this.disconnectAction : this.stopAction; if (session && session.configuration.capabilities.supportsStepBack) { if (!this.stepBackAction) { diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index 197d7c236b8..cf06f2e9aa4 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -250,7 +250,7 @@ export interface IRawBreakpointContribution { } export interface IRawDebugSession { - configuration: { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites }; + configuration: { type: string, capabilities: DebugProtocol.Capabilites }; disconnect(restart?: boolean, force?: boolean): TPromise; @@ -265,7 +265,7 @@ export interface IRawDebugSession { } export interface IConfigurationManager { - configurationName: string; + configuration: IConfig; setConfiguration(name: string): TPromise; openConfigFile(sideBySide: boolean): TPromise; loadLaunchConfig(): TPromise; @@ -274,7 +274,7 @@ export interface IConfigurationManager { /** * Allows to register on change of debug configuration. */ - onDidConfigurationChange: Event; + onDidConfigurationChange: Event; } export const IDebugService = createDecorator(DEBUG_SERVICE_ID); 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 b05e936bf5b..f6fd54cc210 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debug.contribution.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debug.contribution.ts @@ -118,7 +118,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ const configurationManager = debugService.getConfigurationManager(); return configurationManager.setConfiguration(configuration) .then(() => { - return configurationManager.configurationName ? debugService.createSession(false) + return configurationManager.configuration ? debugService.createSession(false) : TPromise.wrapError(new Error(nls.localize('launchConfigDoesNotExist', "Launch configuration '{0}' does not exist.", configuration))); }); } diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 1e4141c527b..dd70b1c762e 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -739,11 +739,7 @@ export class DebugService implements debug.IDebugService { private rawAttach(port: number): TPromise { if (this.session) { - if (!this.session.configuration.isAttach) { - return this.session.attach({ port }); - } - - this.session.disconnect().done(null, errors.onUnexpectedError); + return this.session.attach({ port }); } this.setStateAndEmit(debug.State.Initializing); diff --git a/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts b/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts index 091aec2cb6e..9ba7dd8ebb6 100644 --- a/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts +++ b/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts @@ -52,7 +52,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes private startTime: number; private stopServerPending: boolean; private sentPromises: TPromise[]; - private isAttach: boolean; private capabilities: DebugProtocol.Capabilites; private _onDidInitialize: Emitter; @@ -212,10 +211,9 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes this._onDidEvent.fire(event); } - public get configuration(): { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites } { + public get configuration(): { type: string, capabilities: DebugProtocol.Capabilites } { return { type: this.adapter.type, - isAttach: this.isAttach, capabilities: this.capabilities || {} }; } @@ -233,12 +231,10 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes } public launch(args: DebugProtocol.LaunchRequestArguments): TPromise { - this.isAttach = false; return this.send('launch', args).then(response => this.readCapabilities(response)); } public attach(args: DebugProtocol.AttachRequestArguments): TPromise { - this.isAttach = true; return this.send('attach', args).then(response => this.readCapabilities(response)); } @@ -358,7 +354,7 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes let command = ''; if (platform.isWindows) { - + const quote = (s: string) => { s = s.replace(/\"/g, '""'); return (s.indexOf(' ') >= 0 || s.indexOf('"') >= 0) ? `"${s}"` : s; diff --git a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts index 9c3859677d8..f21726a3157 100644 --- a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts @@ -175,7 +175,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { private systemVariables: ISystemVariables; private adapters: Adapter[]; private allModeIdsForBreakpoints: { [key: string]: boolean }; - private _onDidConfigurationChange: Emitter; + private _onDidConfigurationChange: Emitter; constructor( configName: string, @@ -189,7 +189,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { @ICommandService private commandService: ICommandService ) { this.systemVariables = this.contextService.getWorkspace() ? new ConfigVariables(this.configurationService, this.editorService, this.contextService, this.environmentService) : null; - this._onDidConfigurationChange = new Emitter(); + this._onDidConfigurationChange = new Emitter(); this.setConfiguration(configName); this.adapters = []; this.registerListeners(); @@ -252,7 +252,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { }); } - public get onDidConfigurationChange(): Event { + public get onDidConfigurationChange(): Event { return this._onDidConfigurationChange.event; } @@ -364,7 +364,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { }); } } - }).then(() => this._onDidConfigurationChange.fire(this.configurationName)); + }).then(() => this._onDidConfigurationChange.fire(this.configuration)); } public openConfigFile(sideBySide: boolean): TPromise { diff --git a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts index 5f02269972b..a21de59216a 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts @@ -145,10 +145,9 @@ export class MockDebugService implements debug.IDebugService { class MockRawSession implements debug.IRawDebugSession { - public get configuration(): { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites } { + public get configuration(): { type: string, capabilities: DebugProtocol.Capabilites } { return { type: 'mock', - isAttach: false, capabilities: {} }; } -- GitLab