From 982cfe3f814c7fd8e36e1a3ad57094d4a2eeab46 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Fri, 11 Mar 2022 11:04:28 -0500 Subject: [PATCH] debug: add multi-root support for add configs The commit adds support when executing `add configuration...` in a multi-root workspace where the user will first be prompted to choose the location for their config (choose the root) before adding. Previously, the first root was always chosen. Signed-off-by: vince-fugnitto Co-authored-by: Liang Huang --- CHANGELOG.md | 7 +--- .../browser/debug-configuration-manager.ts | 41 ++++++++++++++++--- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87498ca659f03..eea454b218148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,10 @@ - [plugin] added support for `DocumentSymbolProviderMetadata` [#10811](https://github.com/eclipse-theia/theia/pull/10811) - Contributed on behalf of STMicroelectronics -## v1.24.0 - unreleased - -[1.24.0 Milestone](https://github.com/eclipse-theia/theia/milestone/32) - [Breaking Changes:](#breaking_changes_1.24.0) - - [markers] `ProblemDecorator` reimplemented to reduce redundancy and align more closely with VSCode. `collectMarkers` now returns `Map`, `getOverlayIconColor` renamed to `getColor`, `getOverlayIcon` removed, `appendContainerMarkers` returns `void`. +- [debug] the getter `model` was renamed to `getModel` and accepts an optional `URI` parameter [#10875](https://github.com/eclipse-theia/theia/pull/10875) + - [markers] `ProblemDecorator` reimplemented to reduce redundancy and align more closely with VSCode. `collectMarkers` now returns `Map`, `getOverlayIconColor` renamed to `getColor`, `getOverlayIcon` removed, `appendContainerMarkers` returns `void` [#10820](https://github.com/eclipse-theia/theia/pull/10820) ## v1.23.0 - 2/24/2022 diff --git a/packages/debug/src/browser/debug-configuration-manager.ts b/packages/debug/src/browser/debug-configuration-manager.ts index b40eab253089f..68397e695595f 100644 --- a/packages/debug/src/browser/debug-configuration-manager.ts +++ b/packages/debug/src/browser/debug-configuration-manager.ts @@ -26,7 +26,7 @@ import URI from '@theia/core/lib/common/uri'; import { Emitter, Event, WaitUntilEvent } from '@theia/core/lib/common/event'; import { EditorManager, EditorWidget } from '@theia/editor/lib/browser'; import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; -import { PreferenceScope, PreferenceService, QuickPickValue, StorageService } from '@theia/core/lib/browser'; +import { LabelProvider, PreferenceScope, PreferenceService, QuickPickValue, StorageService } from '@theia/core/lib/browser'; import { QuickPickService } from '@theia/core/lib/common/quick-pick-service'; import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; import { DebugConfigurationModel } from './debug-configuration-model'; @@ -37,6 +37,7 @@ import { DebugConfiguration } from '../common/debug-common'; import { WorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution'; import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations'; import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; +import { nls } from '@theia/core'; export interface WillProvideDebugConfiguration extends WaitUntilEvent { } @@ -56,6 +57,9 @@ export class DebugConfigurationManager { @inject(ContextKeyService) protected readonly contextKeyService: ContextKeyService; + @inject(LabelProvider) + protected readonly labelProvider: LabelProvider; + @inject(MonacoTextModelService) protected readonly textModelService: MonacoTextModelService; @@ -160,7 +164,7 @@ export class DebugConfigurationManager { this._currentOptions = options && !options.configuration.dynamic ? this.find(options.configuration.name, options.workspaceFolderUri) : options; if (!this._currentOptions) { - const { model } = this; + const model = this.getModel(); if (model) { const configuration = model.configurations[0]; if (configuration) { @@ -191,14 +195,23 @@ export class DebugConfigurationManager { } async openConfiguration(): Promise { - const { model } = this; + const model = this.getModel(); if (model) { await this.doOpen(model); } } async addConfiguration(): Promise { - const { model } = this; + let rootUri: URI | undefined = undefined; + if (this.workspaceService.saved && this.workspaceService.tryGetRoots().length > 1) { + rootUri = await this.selectRootUri(); + // Do not continue if the user explicitly does not choose a location. + if (!rootUri) { + return; + } + } + + const model = this.getModel(rootUri); if (!model) { return; } @@ -243,8 +256,24 @@ export class DebugConfigurationManager { await commandService.executeCommand('editor.action.triggerSuggest'); } - protected get model(): DebugConfigurationModel | undefined { - const workspaceFolderUri = this.workspaceVariables.getWorkspaceRootUri(); + protected async selectRootUri(): Promise { + const workspaceRoots = this.workspaceService.tryGetRoots(); + const items: QuickPickValue[] = []; + for (const workspaceRoot of workspaceRoots) { + items.push({ + label: this.labelProvider.getName(workspaceRoot.resource), + description: this.labelProvider.getLongName(workspaceRoot.resource), + value: workspaceRoot.resource + }); + } + const root = await this.quickPickService.show(items, { + placeholder: nls.localize('theia/debug/addConfigurationPlaceholder', 'Select workspace root to add configuration to') + }); + return root?.value; + } + + protected getModel(uri?: URI): DebugConfigurationModel | undefined { + const workspaceFolderUri = this.workspaceVariables.getWorkspaceRootUri(uri); if (workspaceFolderUri) { const key = workspaceFolderUri.toString(); for (const model of this.models.values()) {