Skip to content

Commit f249b3e

Browse files
authored
Introduce DebugSession#workspaceFolder (#11090)
* add workspaceFolder to DebugSession model and adjust session creation * Adapt DebugSession Tree Model to show in UI for multi root workspaces Signed-off-by: Johannes Faltermeier <[email protected]> Co-authored-by: colin-grant-work <[email protected]> Contributed on behalf of STMicroelectronics
1 parent d6e571e commit f249b3e

File tree

14 files changed

+51
-19
lines changed

14 files changed

+51
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/)
66

7+
## v.1.26.0
8+
9+
- [plugin] Introduce `DebugSession#workspaceFolder` [#11090](https://github.com/eclipse-theia/theia/pull/11090) - Contributed on behalf of STMicroelectronics
10+
711
## v1.25.0 - 4/28/2022
812

913
[1.25.0 Milestone](https://github.com/eclipse-theia/theia/milestone/35)

packages/debug/src/browser/debug-session-contribution.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Channel, DebugAdapterPath } from '../common/debug-service';
3030
import { ContributionProvider } from '@theia/core/lib/common/contribution-provider';
3131
import { FileService } from '@theia/filesystem/lib/browser/file-service';
3232
import { DebugContribution } from './debug-contribution';
33+
import { WorkspaceService } from '@theia/workspace/lib/browser';
3334

3435
/**
3536
* DebugSessionContribution symbol for DI.
@@ -114,6 +115,8 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
114115
protected readonly fileService: FileService;
115116
@inject(ContributionProvider) @named(DebugContribution)
116117
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>;
118+
@inject(WorkspaceService)
119+
protected readonly workspaceService: WorkspaceService;
117120

118121
get(sessionId: string, options: DebugSessionOptions, parentSession?: DebugSession): DebugSession {
119122
const connection = new DebugSessionConnection(
@@ -135,7 +138,8 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
135138
this.labelProvider,
136139
this.messages,
137140
this.fileService,
138-
this.debugContributionProvider);
141+
this.debugContributionProvider,
142+
this.workspaceService);
139143
}
140144

141145
protected getTraceOutputChannel(): OutputChannel | undefined {

packages/debug/src/browser/debug-session-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class DebugSessionManager {
214214
}
215215
}
216216

217-
const sessionId = await this.debug.createDebugSession(resolved.configuration);
217+
const sessionId = await this.debug.createDebugSession(resolved.configuration, options.workspaceFolderUri);
218218
return this.doStart(sessionId, resolved);
219219
} catch (e) {
220220
if (DebugError.NotFound.is(e)) {

packages/debug/src/browser/debug-session.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
4141
import { FileService } from '@theia/filesystem/lib/browser/file-service';
4242
import { DebugContribution } from './debug-contribution';
4343
import { waitForEvent } from '@theia/core/lib/common/promise-util';
44+
import { WorkspaceService } from '@theia/workspace/lib/browser';
4445

4546
export enum DebugState {
4647
Inactive,
@@ -79,7 +80,8 @@ export class DebugSession implements CompositeTreeElement {
7980
protected readonly labelProvider: LabelProvider,
8081
protected readonly messages: MessageClient,
8182
protected readonly fileService: FileService,
82-
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>
83+
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>,
84+
protected readonly workspaceService: WorkspaceService,
8385
) {
8486
this.connection.onRequest('runInTerminal', (request: DebugProtocol.RunInTerminalRequest) => this.runInTerminal(request));
8587
this.connection.onDidClose(() => {
@@ -747,10 +749,14 @@ export class DebugSession implements CompositeTreeElement {
747749
}
748750

749751
get label(): string {
752+
const suffixes = [];
750753
if (InternalDebugSessionOptions.is(this.options) && this.options.id) {
751-
return this.configuration.name + ' (' + (this.options.id + 1) + ')';
754+
suffixes.push(String(this.options.id + 1));
752755
}
753-
return this.configuration.name;
756+
if (this.workspaceService.isMultiRootWorkspaceOpened && this.options.workspaceFolderUri) {
757+
suffixes.push(this.labelProvider.getName(new URI(this.options.workspaceFolderUri)));
758+
}
759+
return suffixes.length === 0 ? this.configuration.name : this.configuration.name + ` (${suffixes.join(' - ')})`;
754760
}
755761

756762
get visible(): boolean {

packages/debug/src/common/debug-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ export interface DebugService extends Disposable {
100100
/**
101101
* Creates a new [debug adapter session](#DebugAdapterSession).
102102
* @param config The resolved [debug configuration](#DebugConfiguration).
103+
* @param workspaceFolderUri The worspace folder for this sessions or undefined when folderless
103104
* @returns The identifier of the created [debug adapter session](#DebugAdapterSession).
104105
*/
105-
createDebugSession(config: DebugConfiguration): Promise<string>;
106+
createDebugSession(config: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<string>;
106107

107108
/**
108109
* Stop a running session for the given session id.

packages/debug/src/node/debug-service-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class DebugServiceImpl implements DebugService {
6565
}
6666

6767
protected readonly sessions = new Set<string>();
68-
async createDebugSession(config: DebugConfiguration): Promise<string> {
68+
async createDebugSession(config: DebugConfiguration, _workspaceFolderUri?: string): Promise<string> {
6969
const session = await this.sessionManager.create(config, this.registry);
7070
this.sessions.add(session.id);
7171
return session.id;

packages/plugin-ext/src/common/plugin-api-rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ export interface DebugExt {
17011701
debugConfiguration: theia.DebugConfiguration
17021702
): Promise<theia.DebugConfiguration | undefined | null>;
17031703

1704-
$createDebugSession(debugConfiguration: theia.DebugConfiguration): Promise<string>;
1704+
$createDebugSession(debugConfiguration: theia.DebugConfiguration, workspaceFolder: string | undefined): Promise<string>;
17051705
$terminateDebugSession(sessionId: string): Promise<void>;
17061706
$getTerminalCreationOptions(debugType: string): Promise<TerminalOptionsExt | undefined>;
17071707
}

packages/plugin-ext/src/main/browser/debug/debug-main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { DebugConsoleSession } from '@theia/debug/lib/browser/console/debug-cons
5454
import { ContributionProvider } from '@theia/core/lib/common';
5555
import { DebugContribution } from '@theia/debug/lib/browser/debug-contribution';
5656
import { ConnectionImpl } from '../../../common/connection';
57+
import { WorkspaceService } from '@theia/workspace/lib/browser';
5758

5859
export class DebugMainImpl implements DebugMain, Disposable {
5960
private readonly debugExt: DebugExt;
@@ -73,6 +74,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
7374
private readonly fileService: FileService;
7475
private readonly pluginService: HostedPluginSupport;
7576
private readonly debugContributionProvider: ContributionProvider<DebugContribution>;
77+
private readonly workspaceService: WorkspaceService;
7678

7779
private readonly debuggerContributions = new Map<string, DisposableCollection>();
7880
private readonly configurationProviders = new Map<number, DisposableCollection>();
@@ -95,6 +97,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
9597
this.debugContributionProvider = container.getNamed(ContributionProvider, DebugContribution);
9698
this.fileService = container.get(FileService);
9799
this.pluginService = container.get(HostedPluginSupport);
100+
this.workspaceService = container.get(WorkspaceService);
98101

99102
const fireDidChangeBreakpoints = ({ added, removed, changed }: BreakpointsChangeEvent<SourceBreakpoint | FunctionBreakpoint>) => {
100103
this.debugExt.$breakpointsDidChange(
@@ -155,7 +158,8 @@ export class DebugMainImpl implements DebugMain, Disposable {
155158
},
156159
this.fileService,
157160
terminalOptionsExt,
158-
this.debugContributionProvider
161+
this.debugContributionProvider,
162+
this.workspaceService,
159163
);
160164

161165
const toDispose = new DisposableCollection(

packages/plugin-ext/src/main/browser/debug/plugin-debug-adapter-contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export class PluginDebugAdapterContribution {
3737
return this.description.label;
3838
}
3939

40-
async createDebugSession(config: DebugConfiguration): Promise<string> {
40+
async createDebugSession(config: DebugConfiguration, workspaceFolder: string | undefined): Promise<string> {
4141
await this.pluginService.activateByDebug('onDebugAdapterProtocolTracker', config.type);
42-
return this.debugExt.$createDebugSession(config);
42+
return this.debugExt.$createDebugSession(config, workspaceFolder);
4343
}
4444

4545
async terminateDebugSession(sessionId: string): Promise<void> {

packages/plugin-ext/src/main/browser/debug/plugin-debug-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,14 @@ export class PluginDebugService implements DebugService {
264264
return snippets;
265265
}
266266

267-
async createDebugSession(config: DebugConfiguration): Promise<string> {
267+
async createDebugSession(config: DebugConfiguration, workspaceFolder: string | undefined): Promise<string> {
268268
const contributor = this.contributors.get(config.type);
269269
if (contributor) {
270-
const sessionId = await contributor.createDebugSession(config);
270+
const sessionId = await contributor.createDebugSession(config, workspaceFolder);
271271
this.sessionId2contrib.set(sessionId, contributor);
272272
return sessionId;
273273
} else {
274-
return this.delegated.createDebugSession(config);
274+
return this.delegated.createDebugSession(config, workspaceFolder);
275275
}
276276
}
277277

0 commit comments

Comments
 (0)