Skip to content

Commit 8f7eecc

Browse files
committed
Show quickpick when selecting dynamic debug configuration container
fixes microsoft#96778 fixes microsoft#96293
1 parent 124a368 commit 8f7eecc

4 files changed

Lines changed: 43 additions & 39 deletions

File tree

src/vs/workbench/contrib/debug/browser/debugActionViewItems.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
2020
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
2121
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
2222
import { ADD_CONFIGURATION_ID } from 'vs/workbench/contrib/debug/browser/debugCommands';
23-
import { StartAction } from 'vs/workbench/contrib/debug/browser/debugActions';
2423

2524
const $ = dom.$;
2625

@@ -32,7 +31,7 @@ export class StartDebugActionViewItem implements IActionViewItem {
3231
private container!: HTMLElement;
3332
private start!: HTMLElement;
3433
private selectBox: SelectBox;
35-
private options: { label: string, handler?: (() => boolean) }[] = [];
34+
private options: { label: string, handler: (() => Promise<boolean>) }[] = [];
3635
private toDispose: IDisposable[];
3736
private selected = 0;
3837
private providers: { label: string, pick: () => Promise<{ launch: ILaunch, config: IConfig } | undefined> }[] = [];
@@ -101,9 +100,9 @@ export class StartDebugActionViewItem implements IActionViewItem {
101100
event.stopPropagation();
102101
}
103102
}));
104-
this.toDispose.push(this.selectBox.onDidSelect(e => {
103+
this.toDispose.push(this.selectBox.onDidSelect(async e => {
105104
const target = this.options[e.index];
106-
const shouldBeSelected = target.handler ? target.handler() : false;
105+
const shouldBeSelected = target.handler ? await target.handler() : false;
107106
if (shouldBeSelected) {
108107
this.selected = e.index;
109108
} else {
@@ -173,7 +172,7 @@ export class StartDebugActionViewItem implements IActionViewItem {
173172
if (lastGroup !== presentation?.group) {
174173
lastGroup = presentation?.group;
175174
if (this.options.length) {
176-
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: undefined });
175+
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: () => Promise.resolve(false) });
177176
disabledIdxs.push(this.options.length - 1);
178177
}
179178
}
@@ -183,40 +182,47 @@ export class StartDebugActionViewItem implements IActionViewItem {
183182

184183
const label = inWorkspace ? `${name} (${launch.name})` : name;
185184
this.options.push({
186-
label, handler: () => {
187-
StartAction.GET_CONFIG_AND_LAUNCH = undefined;
185+
label, handler: async () => {
188186
manager.selectConfiguration(launch, name);
189187
return true;
190188
}
191189
});
192190
});
193191

194192
if (this.options.length === 0) {
195-
this.options.push({ label: nls.localize('noConfigurations', "No Configurations"), handler: () => false });
193+
this.options.push({ label: nls.localize('noConfigurations', "No Configurations"), handler: async () => false });
196194
} else {
197-
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: undefined });
195+
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: () => Promise.resolve(false) });
198196
disabledIdxs.push(this.options.length - 1);
199197
}
200198

201199
this.providers.forEach(p => {
200+
if (p.label === manager.selectedConfiguration.name) {
201+
this.selected = this.options.length;
202+
}
203+
202204
this.options.push({
203-
label: `${p.label}...`, handler: () => {
204-
StartAction.GET_CONFIG_AND_LAUNCH = p.pick;
205-
return true;
205+
label: `${p.label}...`, handler: async () => {
206+
const picked = await p.pick();
207+
if (picked) {
208+
manager.selectConfiguration(picked.launch, p.label, picked.config);
209+
return true;
210+
}
211+
return false;
206212
}
207213
});
208214
});
209215

210216
if (this.providers.length > 0) {
211-
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: undefined });
217+
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: () => Promise.resolve(false) });
212218
disabledIdxs.push(this.options.length - 1);
213219
}
214220

215221
manager.getLaunches().filter(l => !l.hidden).forEach(l => {
216222
const label = inWorkspace ? nls.localize("addConfigTo", "Add Config ({0})...", l.name) : nls.localize('addConfiguration', "Add Configuration...");
217223
this.options.push({
218-
label, handler: () => {
219-
this.commandService.executeCommand(ADD_CONFIGURATION_ID, l.uri.toString());
224+
label, handler: async () => {
225+
await this.commandService.executeCommand(ADD_CONFIGURATION_ID, l.uri.toString());
220226
return false;
221227
}
222228
});

src/vs/workbench/contrib/debug/browser/debugActions.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
77
import { Action } from 'vs/base/common/actions';
88
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
99
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
10-
import { IDebugService, State, IEnablement, IBreakpoint, IDebugSession, ILaunch, IConfig } from 'vs/workbench/contrib/debug/common/debug';
10+
import { IDebugService, State, IEnablement, IBreakpoint, IDebugSession, ILaunch } from 'vs/workbench/contrib/debug/common/debug';
1111
import { Variable, Breakpoint, FunctionBreakpoint } from 'vs/workbench/contrib/debug/common/debugModel';
1212
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1313
import { INotificationService } from 'vs/platform/notification/common/notification';
@@ -113,7 +113,6 @@ export class ConfigureAction extends AbstractDebugAction {
113113
export class StartAction extends AbstractDebugAction {
114114
static ID = 'workbench.action.debug.start';
115115
static LABEL = nls.localize('startDebug', "Start Debugging");
116-
static GET_CONFIG_AND_LAUNCH: (() => Promise<{ config: IConfig, launch: ILaunch } | undefined>) | undefined;
117116

118117
constructor(id: string, label: string,
119118
@IDebugService debugService: IDebugService,
@@ -129,16 +128,8 @@ export class StartAction extends AbstractDebugAction {
129128
}
130129

131130
async run(): Promise<boolean> {
132-
if (StartAction.GET_CONFIG_AND_LAUNCH) {
133-
const picked = await StartAction.GET_CONFIG_AND_LAUNCH();
134-
if (picked) {
135-
return this.debugService.startDebugging(picked.launch, picked.config, { noDebug: this.isNoDebug() });
136-
}
137-
return Promise.resolve(false);
138-
} else {
139-
let { launch, name } = this.debugService.getConfigurationManager().selectedConfiguration;
140-
return this.debugService.startDebugging(launch, name, { noDebug: this.isNoDebug() });
141-
}
131+
let { launch, name, config } = this.debugService.getConfigurationManager().selectedConfiguration;
132+
return this.debugService.startDebugging(launch, config || name, { noDebug: this.isNoDebug() });
142133
}
143134

144135
protected isNoDebug(): boolean {

src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ jsonRegistry.registerSchema(launchSchemaId, launchSchema);
4646

4747
const DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname';
4848
const DEBUG_SELECTED_ROOT = 'debug.selectedroot';
49+
const DEBUG_SELECTED_CONFIG = 'debug.selectedconfig';
4950

5051
export class ConfigurationManager implements IConfigurationManager {
5152
private debuggers: Debugger[];
5253
private breakpointModeIdsSet = new Set<string>();
5354
private launches!: ILaunch[];
5455
private selectedName: string | undefined;
5556
private selectedLaunch: ILaunch | undefined;
57+
private selectedConfig: IConfig | undefined;
5658
private toDispose: IDisposable[];
5759
private readonly _onDidSelectConfigurationName = new Emitter<void>();
5860
private configProviders: IDebugConfigurationProvider[];
@@ -82,10 +84,12 @@ export class ConfigurationManager implements IConfigurationManager {
8284
const previousSelectedRoot = this.storageService.get(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
8385
const previousSelectedLaunch = this.launches.find(l => l.uri.toString() === previousSelectedRoot);
8486
this.debugConfigurationTypeContext = CONTEXT_DEBUG_CONFIGURATION_TYPE.bindTo(contextKeyService);
87+
const storedConfig = this.storageService.get(DEBUG_SELECTED_CONFIG, StorageScope.WORKSPACE);
88+
const selectedConfig = typeof storedConfig === 'string' ? JSON.parse(storedConfig) : undefined;
8589
if (previousSelectedLaunch && previousSelectedLaunch.getConfigurationNames().length) {
86-
this.selectConfiguration(previousSelectedLaunch, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE));
90+
this.selectConfiguration(previousSelectedLaunch, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE), selectedConfig);
8791
} else if (this.launches.length > 0) {
88-
this.selectConfiguration(undefined);
92+
this.selectConfiguration(undefined, selectedConfig ? selectedConfig.name : undefined, selectedConfig);
8993
}
9094
}
9195

@@ -434,10 +438,11 @@ export class ConfigurationManager implements IConfigurationManager {
434438
return this.launches.find(l => l.workspace && l.workspace.uri.toString() === workspaceUri.toString());
435439
}
436440

437-
get selectedConfiguration(): { launch: ILaunch | undefined, name: string | undefined } {
441+
get selectedConfiguration(): { launch: ILaunch | undefined, name: string | undefined, config: IConfig | undefined } {
438442
return {
439443
launch: this.selectedLaunch,
440-
name: this.selectedName
444+
name: this.selectedName,
445+
config: this.selectedConfig
441446
};
442447
}
443448

@@ -453,7 +458,7 @@ export class ConfigurationManager implements IConfigurationManager {
453458
return undefined;
454459
}
455460

456-
selectConfiguration(launch: ILaunch | undefined, name?: string): void {
461+
selectConfiguration(launch: ILaunch | undefined, name?: string, config?: IConfig): void {
457462
if (typeof launch === 'undefined') {
458463
const rootUri = this.historyService.getLastActiveWorkspaceRoot();
459464
launch = this.getLaunch(rootUri);
@@ -472,18 +477,19 @@ export class ConfigurationManager implements IConfigurationManager {
472477
this.storageService.remove(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
473478
}
474479
const names = launch ? launch.getConfigurationNames() : [];
475-
if (name && names.indexOf(name) >= 0) {
480+
if ((name && names.indexOf(name) >= 0) || config) {
476481
this.setSelectedLaunchName(name);
477-
}
478-
if (!this.selectedName || names.indexOf(this.selectedName) === -1) {
482+
} else if (!this.selectedName || names.indexOf(this.selectedName) === -1) {
479483
this.setSelectedLaunchName(names.length ? names[0] : undefined);
480484
}
481485

482-
const configuration = this.selectedLaunch && this.selectedName ? this.selectedLaunch.getConfiguration(this.selectedName) : undefined;
483-
if (configuration) {
484-
this.debugConfigurationTypeContext.set(configuration.type);
486+
this.selectedConfig = config || (this.selectedLaunch && this.selectedName ? this.selectedLaunch.getConfiguration(this.selectedName) : undefined);
487+
if (this.selectedConfig) {
488+
this.debugConfigurationTypeContext.set(this.selectedConfig.type);
489+
this.storageService.store(DEBUG_SELECTED_CONFIG, JSON.stringify(this.selectedConfig), StorageScope.WORKSPACE);
485490
} else {
486491
this.debugConfigurationTypeContext.reset();
492+
this.storageService.remove(DEBUG_SELECTED_CONFIG, StorageScope.WORKSPACE);
487493
}
488494

489495
if (this.selectedLaunch !== previousLaunch || this.selectedName !== previousName) {

src/vs/workbench/contrib/debug/common/debug.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,11 @@ export interface IConfigurationManager {
633633
*/
634634
readonly selectedConfiguration: {
635635
launch: ILaunch | undefined;
636+
config: IConfig | undefined;
636637
name: string | undefined;
637638
};
638639

639-
selectConfiguration(launch: ILaunch | undefined, name?: string, debugStarted?: boolean): void;
640+
selectConfiguration(launch: ILaunch | undefined, name?: string, config?: IConfig): void;
640641

641642
getLaunches(): ReadonlyArray<ILaunch>;
642643

0 commit comments

Comments
 (0)