提交 8f7eecc2 编写于 作者: I isidor

Show quickpick when selecting dynamic debug configuration container

fixes #96778
fixes #96293
上级 124a368e
......@@ -20,7 +20,6 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ADD_CONFIGURATION_ID } from 'vs/workbench/contrib/debug/browser/debugCommands';
import { StartAction } from 'vs/workbench/contrib/debug/browser/debugActions';
const $ = dom.$;
......@@ -32,7 +31,7 @@ export class StartDebugActionViewItem implements IActionViewItem {
private container!: HTMLElement;
private start!: HTMLElement;
private selectBox: SelectBox;
private options: { label: string, handler?: (() => boolean) }[] = [];
private options: { label: string, handler: (() => Promise<boolean>) }[] = [];
private toDispose: IDisposable[];
private selected = 0;
private providers: { label: string, pick: () => Promise<{ launch: ILaunch, config: IConfig } | undefined> }[] = [];
......@@ -101,9 +100,9 @@ export class StartDebugActionViewItem implements IActionViewItem {
event.stopPropagation();
}
}));
this.toDispose.push(this.selectBox.onDidSelect(e => {
this.toDispose.push(this.selectBox.onDidSelect(async e => {
const target = this.options[e.index];
const shouldBeSelected = target.handler ? target.handler() : false;
const shouldBeSelected = target.handler ? await target.handler() : false;
if (shouldBeSelected) {
this.selected = e.index;
} else {
......@@ -173,7 +172,7 @@ export class StartDebugActionViewItem implements IActionViewItem {
if (lastGroup !== presentation?.group) {
lastGroup = presentation?.group;
if (this.options.length) {
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: undefined });
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: () => Promise.resolve(false) });
disabledIdxs.push(this.options.length - 1);
}
}
......@@ -183,8 +182,7 @@ export class StartDebugActionViewItem implements IActionViewItem {
const label = inWorkspace ? `${name} (${launch.name})` : name;
this.options.push({
label, handler: () => {
StartAction.GET_CONFIG_AND_LAUNCH = undefined;
label, handler: async () => {
manager.selectConfiguration(launch, name);
return true;
}
......@@ -192,31 +190,39 @@ export class StartDebugActionViewItem implements IActionViewItem {
});
if (this.options.length === 0) {
this.options.push({ label: nls.localize('noConfigurations', "No Configurations"), handler: () => false });
this.options.push({ label: nls.localize('noConfigurations', "No Configurations"), handler: async () => false });
} else {
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: undefined });
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: () => Promise.resolve(false) });
disabledIdxs.push(this.options.length - 1);
}
this.providers.forEach(p => {
if (p.label === manager.selectedConfiguration.name) {
this.selected = this.options.length;
}
this.options.push({
label: `${p.label}...`, handler: () => {
StartAction.GET_CONFIG_AND_LAUNCH = p.pick;
return true;
label: `${p.label}...`, handler: async () => {
const picked = await p.pick();
if (picked) {
manager.selectConfiguration(picked.launch, p.label, picked.config);
return true;
}
return false;
}
});
});
if (this.providers.length > 0) {
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: undefined });
this.options.push({ label: StartDebugActionViewItem.SEPARATOR, handler: () => Promise.resolve(false) });
disabledIdxs.push(this.options.length - 1);
}
manager.getLaunches().filter(l => !l.hidden).forEach(l => {
const label = inWorkspace ? nls.localize("addConfigTo", "Add Config ({0})...", l.name) : nls.localize('addConfiguration', "Add Configuration...");
this.options.push({
label, handler: () => {
this.commandService.executeCommand(ADD_CONFIGURATION_ID, l.uri.toString());
label, handler: async () => {
await this.commandService.executeCommand(ADD_CONFIGURATION_ID, l.uri.toString());
return false;
}
});
......
......@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import { Action } from 'vs/base/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IDebugService, State, IEnablement, IBreakpoint, IDebugSession, ILaunch, IConfig } from 'vs/workbench/contrib/debug/common/debug';
import { IDebugService, State, IEnablement, IBreakpoint, IDebugSession, ILaunch } from 'vs/workbench/contrib/debug/common/debug';
import { Variable, Breakpoint, FunctionBreakpoint } from 'vs/workbench/contrib/debug/common/debugModel';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { INotificationService } from 'vs/platform/notification/common/notification';
......@@ -113,7 +113,6 @@ export class ConfigureAction extends AbstractDebugAction {
export class StartAction extends AbstractDebugAction {
static ID = 'workbench.action.debug.start';
static LABEL = nls.localize('startDebug', "Start Debugging");
static GET_CONFIG_AND_LAUNCH: (() => Promise<{ config: IConfig, launch: ILaunch } | undefined>) | undefined;
constructor(id: string, label: string,
@IDebugService debugService: IDebugService,
......@@ -129,16 +128,8 @@ export class StartAction extends AbstractDebugAction {
}
async run(): Promise<boolean> {
if (StartAction.GET_CONFIG_AND_LAUNCH) {
const picked = await StartAction.GET_CONFIG_AND_LAUNCH();
if (picked) {
return this.debugService.startDebugging(picked.launch, picked.config, { noDebug: this.isNoDebug() });
}
return Promise.resolve(false);
} else {
let { launch, name } = this.debugService.getConfigurationManager().selectedConfiguration;
return this.debugService.startDebugging(launch, name, { noDebug: this.isNoDebug() });
}
let { launch, name, config } = this.debugService.getConfigurationManager().selectedConfiguration;
return this.debugService.startDebugging(launch, config || name, { noDebug: this.isNoDebug() });
}
protected isNoDebug(): boolean {
......
......@@ -46,6 +46,7 @@ jsonRegistry.registerSchema(launchSchemaId, launchSchema);
const DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname';
const DEBUG_SELECTED_ROOT = 'debug.selectedroot';
const DEBUG_SELECTED_CONFIG = 'debug.selectedconfig';
export class ConfigurationManager implements IConfigurationManager {
private debuggers: Debugger[];
......@@ -53,6 +54,7 @@ export class ConfigurationManager implements IConfigurationManager {
private launches!: ILaunch[];
private selectedName: string | undefined;
private selectedLaunch: ILaunch | undefined;
private selectedConfig: IConfig | undefined;
private toDispose: IDisposable[];
private readonly _onDidSelectConfigurationName = new Emitter<void>();
private configProviders: IDebugConfigurationProvider[];
......@@ -82,10 +84,12 @@ export class ConfigurationManager implements IConfigurationManager {
const previousSelectedRoot = this.storageService.get(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
const previousSelectedLaunch = this.launches.find(l => l.uri.toString() === previousSelectedRoot);
this.debugConfigurationTypeContext = CONTEXT_DEBUG_CONFIGURATION_TYPE.bindTo(contextKeyService);
const storedConfig = this.storageService.get(DEBUG_SELECTED_CONFIG, StorageScope.WORKSPACE);
const selectedConfig = typeof storedConfig === 'string' ? JSON.parse(storedConfig) : undefined;
if (previousSelectedLaunch && previousSelectedLaunch.getConfigurationNames().length) {
this.selectConfiguration(previousSelectedLaunch, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE));
this.selectConfiguration(previousSelectedLaunch, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE), selectedConfig);
} else if (this.launches.length > 0) {
this.selectConfiguration(undefined);
this.selectConfiguration(undefined, selectedConfig ? selectedConfig.name : undefined, selectedConfig);
}
}
......@@ -434,10 +438,11 @@ export class ConfigurationManager implements IConfigurationManager {
return this.launches.find(l => l.workspace && l.workspace.uri.toString() === workspaceUri.toString());
}
get selectedConfiguration(): { launch: ILaunch | undefined, name: string | undefined } {
get selectedConfiguration(): { launch: ILaunch | undefined, name: string | undefined, config: IConfig | undefined } {
return {
launch: this.selectedLaunch,
name: this.selectedName
name: this.selectedName,
config: this.selectedConfig
};
}
......@@ -453,7 +458,7 @@ export class ConfigurationManager implements IConfigurationManager {
return undefined;
}
selectConfiguration(launch: ILaunch | undefined, name?: string): void {
selectConfiguration(launch: ILaunch | undefined, name?: string, config?: IConfig): void {
if (typeof launch === 'undefined') {
const rootUri = this.historyService.getLastActiveWorkspaceRoot();
launch = this.getLaunch(rootUri);
......@@ -472,18 +477,19 @@ export class ConfigurationManager implements IConfigurationManager {
this.storageService.remove(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
}
const names = launch ? launch.getConfigurationNames() : [];
if (name && names.indexOf(name) >= 0) {
if ((name && names.indexOf(name) >= 0) || config) {
this.setSelectedLaunchName(name);
}
if (!this.selectedName || names.indexOf(this.selectedName) === -1) {
} else if (!this.selectedName || names.indexOf(this.selectedName) === -1) {
this.setSelectedLaunchName(names.length ? names[0] : undefined);
}
const configuration = this.selectedLaunch && this.selectedName ? this.selectedLaunch.getConfiguration(this.selectedName) : undefined;
if (configuration) {
this.debugConfigurationTypeContext.set(configuration.type);
this.selectedConfig = config || (this.selectedLaunch && this.selectedName ? this.selectedLaunch.getConfiguration(this.selectedName) : undefined);
if (this.selectedConfig) {
this.debugConfigurationTypeContext.set(this.selectedConfig.type);
this.storageService.store(DEBUG_SELECTED_CONFIG, JSON.stringify(this.selectedConfig), StorageScope.WORKSPACE);
} else {
this.debugConfigurationTypeContext.reset();
this.storageService.remove(DEBUG_SELECTED_CONFIG, StorageScope.WORKSPACE);
}
if (this.selectedLaunch !== previousLaunch || this.selectedName !== previousName) {
......
......@@ -633,10 +633,11 @@ export interface IConfigurationManager {
*/
readonly selectedConfiguration: {
launch: ILaunch | undefined;
config: IConfig | undefined;
name: string | undefined;
};
selectConfiguration(launch: ILaunch | undefined, name?: string, debugStarted?: boolean): void;
selectConfiguration(launch: ILaunch | undefined, name?: string, config?: IConfig): void;
getLaunches(): ReadonlyArray<ILaunch>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册