Skip to content

Commit

Permalink
debug: reduce usages of selectedLaunch and some refactoring
Browse files Browse the repository at this point in the history
fixes #42630
  • Loading branch information
isidorn committed Feb 6, 2018
1 parent 9f4cd0a commit bc7b804
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/browser/debugActionItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class StartDebugActionItem implements IActionItem {
const inWorkspace = this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE;
manager.getLaunches().forEach(launch =>
launch.getConfigurationNames().forEach(name => {
if (name === manager.selectedName && launch === manager.selectedLaunch) {
if (name === manager.selectedConfiguration.name && launch === manager.selectedConfiguration.launch) {
this.selected = this.options.length;
}
const label = inWorkspace ? `${name} (${launch.name})` : name;
Expand Down
17 changes: 9 additions & 8 deletions src/vs/workbench/parts/debug/browser/debugActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,34 @@ export class ConfigureAction extends AbstractDebugAction {
constructor(id: string, label: string,
@IDebugService debugService: IDebugService,
@IKeybindingService keybindingService: IKeybindingService,
@IMessageService private messageService: IMessageService
@IMessageService private messageService: IMessageService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
super(id, label, 'debug-action configure', debugService, keybindingService);
this.toDispose.push(debugService.getConfigurationManager().onDidSelectConfiguration(() => this.updateClass()));
this.updateClass();
}

public get tooltip(): string {
if (this.debugService.getConfigurationManager().selectedName) {
if (this.debugService.getConfigurationManager().selectedConfiguration.name) {
return ConfigureAction.LABEL;
}

return nls.localize('launchJsonNeedsConfigurtion', "Configure or Fix 'launch.json'");
}

private updateClass(): void {
this.class = this.debugService.getConfigurationManager().selectedName ? 'debug-action configure' : 'debug-action configure notification';
this.class = this.debugService.getConfigurationManager().selectedConfiguration.name ? 'debug-action configure' : 'debug-action configure notification';
}

public run(event?: any): TPromise<any> {
if (!this.debugService.getConfigurationManager().selectedLaunch) {
if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY) {
this.messageService.show(severity.Info, nls.localize('noFolderDebugConfig', "Please first open a folder in order to do advanced debug configuration."));
return TPromise.as(null);
}

const sideBySide = !!(event && (event.ctrlKey || event.metaKey));
return this.debugService.getConfigurationManager().selectedLaunch.openConfigFile(sideBySide);
return this.debugService.getConfigurationManager().selectedConfiguration.launch.openConfigFile(sideBySide);
}
}

Expand All @@ -124,7 +125,7 @@ export class StartAction extends AbstractDebugAction {
}

public run(): TPromise<any> {
const launch = this.debugService.getConfigurationManager().selectedLaunch;
const launch = this.debugService.getConfigurationManager().selectedConfiguration.launch;
return this.debugService.startDebugging(launch ? launch.workspace : undefined, undefined, this.isNoDebug());
}

Expand All @@ -134,7 +135,7 @@ export class StartAction extends AbstractDebugAction {

public static isEnabled(debugService: IDebugService, contextService: IWorkspaceContextService, configName: string) {
const processes = debugService.getModel().getProcesses();
const launch = debugService.getConfigurationManager().selectedLaunch;
const launch = debugService.getConfigurationManager().selectedConfiguration.launch;

if (debugService.state === State.Initializing) {
return false;
Expand All @@ -155,7 +156,7 @@ export class StartAction extends AbstractDebugAction {

// Disabled if the launch drop down shows the launch config that is already running.
protected isEnabled(state: State): boolean {
return StartAction.isEnabled(this.debugService, this.contextService, this.debugService.getConfigurationManager().selectedName);
return StartAction.isEnabled(this.debugService, this.contextService, this.debugService.getConfigurationManager().selectedConfiguration.name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/browser/debugQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class DebugQuickOpenHandler extends Quickopen.QuickOpenHandler {
launch.getConfigurationNames().map(config => ({ config: config, highlights: Filters.matchesContiguousSubString(input, config) }))
.filter(({ highlights }) => !!highlights)
.forEach(({ config, highlights }) => {
if (launch === configManager.selectedLaunch && config === configManager.selectedName) {
if (launch === configManager.selectedConfiguration.launch && config === configManager.selectedConfiguration.name) {
this.autoFocusIndex = configurations.length;
}
configurations.push(new StartDebugEntry(this.debugService, this.contextService, this.messageService, launch, config, highlights));
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/parts/debug/browser/debugStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export class DebugStatus extends Themable implements IStatusbarItem {
private setLabel(): void {
if (this.label && this.statusBarItem) {
const manager = this.debugService.getConfigurationManager();
if (manager.selectedName) {
const name = manager.selectedName;
const name = manager.selectedConfiguration.name;
if (name) {
this.statusBarItem.style.display = 'block';
this.label.textContent = manager.getLaunches().length > 1 ? `${name} (${manager.selectedLaunch.name})` : name;
this.label.textContent = manager.getLaunches().length > 1 ? `${name} (${manager.selectedConfiguration.launch.name})` : name;
} else {
this.statusBarItem.style.display = 'none';
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/browser/debugViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class DebugViewlet extends PersistentViewsViewlet {
}

public getActionItem(action: IAction): IActionItem {
if (action.id === StartAction.ID && !!this.debugService.getConfigurationManager().selectedLaunch) {
if (action.id === StartAction.ID) {
this.startDebugActionItem = this.instantiationService.createInstance(StartDebugActionItem, null, action);
return this.startDebugActionItem;
}
Expand Down
9 changes: 5 additions & 4 deletions src/vs/workbench/parts/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,12 @@ export interface IConfigurationManager {
canSetBreakpointsIn(model: EditorIModel): boolean;

/**
* Returns null for no folder workspace. Otherwise returns a launch object corresponding to the selected debug configuration.
* Returns an object containing the selected launch configuration and the selected configuration name. Both these fields can be null (no folder workspace).
*/
selectedLaunch: ILaunch;

selectedName: string;
selectedConfiguration: {
launch: ILaunch;
name: string;
};

selectConfiguration(launch: ILaunch, name?: string, debugStarted?: boolean): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function registerCommands(): void {
accessor.get(IMessageService).show(severity.Info, nls.localize('noFolderDebugConfig', "Please first open a folder in order to do advanced debug configuration."));
return TPromise.as(null);
}
const launch = manager.getLaunches().filter(l => l.uri.toString() === launchUri).pop() || manager.selectedLaunch;
const launch = manager.getLaunches().filter(l => l.uri.toString() === launchUri).pop() || manager.selectedConfiguration.launch;

return launch.openConfigFile(false).done(editor => {
if (editor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export class ConfigurationManager implements IConfigurationManager {
private adapters: Adapter[];
private breakpointModeIdsSet = new Set<string>();
private launches: ILaunch[];
private _selectedName: string;
private _selectedLaunch: ILaunch;
private selectedName: string;
private selectedLaunch: ILaunch;
private toDispose: IDisposable[];
private _onDidSelectConfigurationName = new Emitter<void>();
private providers: IDebugConfigurationProvider[];
Expand Down Expand Up @@ -368,8 +368,8 @@ export class ConfigurationManager implements IConfigurationManager {
this.launches.push(this.instantiationService.createInstance(WorkspaceLaunch, this));
}

if (this.launches.indexOf(this._selectedLaunch) === -1) {
this._selectedLaunch = undefined;
if (this.launches.indexOf(this.selectedLaunch) === -1) {
this.selectedLaunch = undefined;
}
}

Expand All @@ -390,12 +390,11 @@ export class ConfigurationManager implements IConfigurationManager {
return this.launches;
}

public get selectedLaunch(): ILaunch {
return this._selectedLaunch;
}

public get selectedName(): string {
return this._selectedName;
public get selectedConfiguration(): { launch: ILaunch, name: string } {
return {
launch: this.selectedLaunch,
name: this.selectedName
};
}

public get onDidSelectConfiguration(): Event<void> {
Expand All @@ -411,20 +410,20 @@ export class ConfigurationManager implements IConfigurationManager {
}

public selectConfiguration(launch?: ILaunch, name?: string, debugStarted?: boolean): void {
const previousLaunch = this._selectedLaunch;
const previousName = this._selectedName;
const previousLaunch = this.selectedLaunch;
const previousName = this.selectedName;

if (!launch) {
launch = this.selectedLaunch && this.selectedLaunch.getConfigurationNames().length ? this.selectedLaunch : first(this.launches, l => !!l.getConfigurationNames().length, this.launches.length ? this.launches[0] : undefined);
}

this._selectedLaunch = launch;
this.selectedLaunch = launch;
const names = launch ? launch.getConfigurationNames() : [];
if (name && names.indexOf(name) >= 0) {
this._selectedName = name;
this.selectedName = name;
}
if (names.indexOf(this.selectedName) === -1) {
this._selectedName = names.length ? names[0] : undefined;
this.selectedName = names.length ? names[0] : undefined;
}

if (this.selectedLaunch !== previousLaunch || this.selectedName !== previousName) {
Expand Down Expand Up @@ -491,8 +490,8 @@ export class ConfigurationManager implements IConfigurationManager {

private store(): void {
this.storageService.store(DEBUG_SELECTED_CONFIG_NAME_KEY, this.selectedName, StorageScope.WORKSPACE);
if (this._selectedLaunch) {
this.storageService.store(DEBUG_SELECTED_ROOT, this._selectedLaunch.uri.toString(), StorageScope.WORKSPACE);
if (this.selectedLaunch) {
this.storageService.store(DEBUG_SELECTED_ROOT, this.selectedLaunch.uri.toString(), StorageScope.WORKSPACE);
}
}

Expand Down Expand Up @@ -621,7 +620,7 @@ class Launch implements ILaunch {
if (!content) {
return undefined;
}
const index = content.indexOf(`"${this.configurationManager.selectedName}"`);
const index = content.indexOf(`"${this.configurationManager.selectedConfiguration.name}"`);
let startLineNumber = 1;
for (let i = 0; i < index; i++) {
if (content.charAt(i) === '\n') {
Expand Down
10 changes: 6 additions & 4 deletions src/vs/workbench/parts/debug/electron-browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ export class DebugService implements debug.IDebugService {

let config: debug.IConfig, compound: debug.ICompound;
if (!configOrName) {
configOrName = this.configurationManager.selectedName;
configOrName = this.configurationManager.selectedConfiguration.name;
}
if (typeof configOrName === 'string' && launch) {
config = launch.getConfiguration(configOrName);
Expand Down Expand Up @@ -768,7 +768,7 @@ export class DebugService implements debug.IDebugService {
}

private createProcess(root: IWorkspaceFolder, config: debug.IConfig, sessionId: string): TPromise<void> {
const launch = root ? this.configurationManager.getLaunches().filter(l => l.workspace && l.workspace.uri.toString() === root.uri.toString()).pop() : this.configurationManager.selectedLaunch;
const launch = root ? this.configurationManager.getLaunches().filter(l => l.workspace && l.workspace.uri.toString() === root.uri.toString()).pop() : undefined;
return this.textFileService.saveAll().then(() =>
(launch ? launch.resolveConfiguration(config) : TPromise.as(config)).then(resolvedConfig => {
if (!resolvedConfig) {
Expand Down Expand Up @@ -1063,9 +1063,11 @@ export class DebugService implements debug.IDebugService {
setTimeout(() => {
// Read the configuration again if a launch.json has been changed, if not just use the inmemory configuration
let config = process.configuration;
if (this.launchJsonChanged && this.configurationManager.selectedLaunch) {

const launch = this.configurationManager.getLaunches().filter(l => l.workspace && process.session.root && l.workspace.uri.toString() === process.session.root.uri.toString()).pop();
if (this.launchJsonChanged && launch) {
this.launchJsonChanged = false;
config = this.configurationManager.selectedLaunch.getConfiguration(process.configuration.name) || config;
config = launch.getConfiguration(process.configuration.name) || config;
// Take the type from the process since the debug extension might overwrite it #21316
config.type = process.configuration.type;
config.noDebug = process.configuration.noDebug;
Expand Down

0 comments on commit bc7b804

Please sign in to comment.