From ae2a4a7f950bcdc4ecdabb0ccfec2f6126a8ca77 Mon Sep 17 00:00:00 2001 From: isidor Date: Tue, 30 Jan 2018 17:56:46 +0100 Subject: [PATCH] debug: introduce UserLaunch fixes #42467 --- .../parts/debug/browser/debugActionItems.ts | 9 ++-- .../parts/debug/browser/debugQuickOpen.ts | 5 ++- src/vs/workbench/parts/debug/common/debug.ts | 5 +++ .../debugConfigurationManager.ts | 44 ++++++++++++++++++- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/parts/debug/browser/debugActionItems.ts b/src/vs/workbench/parts/debug/browser/debugActionItems.ts index 2f8e4a05dfa..526d46c3640 100644 --- a/src/vs/workbench/parts/debug/browser/debugActionItems.ts +++ b/src/vs/workbench/parts/debug/browser/debugActionItems.ts @@ -20,6 +20,7 @@ import { attachSelectBoxStyler, attachStylerCallback } from 'vs/platform/theme/c import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme'; import { selectBorder } from 'vs/platform/theme/common/colorRegistry'; import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; +import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; const $ = dom.$; @@ -42,6 +43,7 @@ export class StartDebugActionItem implements IActionItem { @IThemeService private themeService: IThemeService, @IConfigurationService private configurationService: IConfigurationService, @ICommandService private commandService: ICommandService, + @IWorkspaceContextService private contextService: IWorkspaceContextService, @IContextViewService contextViewService: IContextViewService, ) { this.toDispose = []; @@ -153,12 +155,13 @@ export class StartDebugActionItem implements IActionItem { this.options = []; const manager = this.debugService.getConfigurationManager(); const launches = manager.getLaunches(); + const inWorkspace = this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE; manager.getLaunches().forEach(launch => launch.getConfigurationNames().forEach(name => { if (name === manager.selectedName && launch === manager.selectedLaunch) { this.selected = this.options.length; } - const label = launches.length > 1 ? `${name} (${launch.name})` : name; + const label = inWorkspace ? `${name} (${launch.name})` : name; this.options.push({ label, handler: () => { manager.selectConfiguration(launch, name); return true; } }); })); @@ -168,8 +171,8 @@ export class StartDebugActionItem implements IActionItem { this.options.push({ label: StartDebugActionItem.SEPARATOR, handler: undefined }); const disabledIdx = this.options.length - 1; - launches.forEach(l => { - const label = launches.length > 1 ? nls.localize("addConfigTo", "Add Config ({0})...", l.name) : nls.localize('addConfiguration', "Add Configuration..."); + launches.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('debug.addConfiguration', l.uri.toString()).done(undefined, errors.onUnexpectedError); diff --git a/src/vs/workbench/parts/debug/browser/debugQuickOpen.ts b/src/vs/workbench/parts/debug/browser/debugQuickOpen.ts index 4b93cc51109..909b65532b8 100644 --- a/src/vs/workbench/parts/debug/browser/debugQuickOpen.ts +++ b/src/vs/workbench/parts/debug/browser/debugQuickOpen.ts @@ -109,8 +109,9 @@ export class DebugQuickOpenHandler extends Quickopen.QuickOpenHandler { configurations.push(new StartDebugEntry(this.debugService, this.contextService, this.messageService, launch, config, highlights)); }); } - launches.forEach((l, index) => { - const label = launches.length > 1 ? nls.localize("addConfigTo", "Add Config ({0})...", l.name) : nls.localize('addConfiguration', "Add Configuration..."); + launches.filter(l => !l.hidden).forEach((l, index) => { + + const label = this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ? nls.localize("addConfigTo", "Add Config ({0})...", l.name) : nls.localize('addConfiguration', "Add Configuration..."); const entry = new AddConfigEntry(label, l, this.commandService, this.contextService, Filters.matchesContiguousSubString(input, label)); if (index === 0) { configurations.push(new QuickOpenEntryGroup(entry, undefined, true)); diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index dcb0cb17698..ba7ca13c2ff 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -448,6 +448,11 @@ export interface ILaunch { workspace: IWorkspaceFolder; + /** + * Should this launch be shown in the debug dropdown. + */ + hidden: boolean; + /** * Returns a configuration with the specified name. * Returns null if there is no configuration with the specified name. diff --git a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts index 6e6aa939f9d..f06096a0ece 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts @@ -34,6 +34,7 @@ import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { isCodeEditor } from 'vs/editor/browser/editorBrowser'; import { launchSchemaId } from 'vs/workbench/services/configuration/common/configuration'; +import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences'; // debuggers extension point export const debuggersExtPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint('debuggers', [], { @@ -362,6 +363,7 @@ export class ConfigurationManager implements IConfigurationManager { private initLaunches(): void { this.launches = this.contextService.getWorkspace().folders.map(folder => this.instantiationService.createInstance(Launch, this, folder)); + this.launches.push(this.instantiationService.createInstance(UserLaunch, this)); if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE) { this.launches.push(this.instantiationService.createInstance(WorkspaceLaunch, this)); } @@ -520,8 +522,12 @@ class Launch implements ILaunch { return this.workspace.name; } + public get hidden(): boolean { + return false; + } + protected getConfig(): IGlobalConfig { - return this.configurationService.getValue('launch', { resource: this.workspace.uri }); + return this.configurationService.inspect('launch', { resource: this.workspace.uri }).workspaceFolder; } public getCompound(name: string): ICompound { @@ -539,7 +545,7 @@ class Launch implements ILaunch { return []; } else { const names = config.configurations.filter(cfg => cfg && typeof cfg.name === 'string').map(cfg => cfg.name); - if (includeCompounds && names.length > 0 && config.compounds) { + if (includeCompounds && config.compounds) { if (config.compounds) { names.push(...config.compounds.filter(compound => typeof compound.name === 'string' && compound.configurations && compound.configurations.length) .map(compound => compound.name)); @@ -668,3 +674,37 @@ class WorkspaceLaunch extends Launch implements ILaunch { return this.editorService.openEditor({ resource: this.workspaceContextService.getWorkspace().configuration }); } } + +class UserLaunch extends Launch implements ILaunch { + + constructor( + configurationManager: ConfigurationManager, + @IFileService fileService: IFileService, + @IWorkbenchEditorService editorService: IWorkbenchEditorService, + @IConfigurationService configurationService: IConfigurationService, + @IConfigurationResolverService configurationResolverService: IConfigurationResolverService, + @IPreferencesService private preferencesService: IPreferencesService + ) { + super(configurationManager, undefined, fileService, editorService, configurationService, configurationResolverService); + } + + get uri(): uri { + return this.preferencesService.userSettingsResource; + } + + get name(): string { + return nls.localize('user settings', "user settings"); + } + + public get hidden(): boolean { + return true; + } + + protected getConfig(): IGlobalConfig { + return this.configurationService.inspect('launch').user; + } + + openConfigFile(sideBySide: boolean, type?: string): TPromise { + return this.preferencesService.openGlobalSettings(); + } +} -- GitLab