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 11, 2022
1 parent e62fd33 commit ea7e981
Showing 1 changed file with 35 additions and 6 deletions.
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 ea7e981

Please sign in to comment.