Skip to content

Commit

Permalink
debug: add multi-root support for add configs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Liang Huang <[email protected]>
  • Loading branch information
vince-fugnitto and elaihau committed Mar 17, 2022
1 parent e62fd33 commit 982cfe3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<a name="breaking_changes_1.24.0">[Breaking Changes:](#breaking_changes_1.24.0)</a>

- [markers] `ProblemDecorator` reimplemented to reduce redundancy and align more closely with VSCode. `collectMarkers` now returns `Map<string, TreeDecoration.Data>`, `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<string, TreeDecoration.Data>`, `getOverlayIconColor` renamed to `getColor`, `getOverlayIcon` removed, `appendContainerMarkers` returns `void` [#10820](https://github.com/eclipse-theia/theia/pull/10820)

## v1.23.0 - 2/24/2022

Expand Down
41 changes: 35 additions & 6 deletions packages/debug/src/browser/debug-configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
}
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -191,14 +195,23 @@ export class DebugConfigurationManager {
}

async openConfiguration(): Promise<void> {
const { model } = this;
const model = this.getModel();
if (model) {
await this.doOpen(model);
}
}

async addConfiguration(): Promise<void> {
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;
}
Expand Down Expand Up @@ -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<URI | undefined> {
const workspaceRoots = this.workspaceService.tryGetRoots();
const items: QuickPickValue<URI>[] = [];
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()) {
Expand Down

0 comments on commit 982cfe3

Please sign in to comment.