Skip to content

Commit 73d4b04

Browse files
authored
Add DebugSessionOptions.testRun (#13939)
Fixes #13872 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <[email protected]>
1 parent 3fba2f6 commit 73d4b04

15 files changed

+126
-38
lines changed

.theia/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"editor.formatOnSave": false,
2+
"editor.formatOnSave": true,
33
"editor.insertSpaces": true,
44
"[typescript]": {
55
"editor.tabSize": 4

CHANGELOG.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

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

7-
<!-- ## not yet released
7+
## not yet released
8+
- [test] Added `DebugSessionOptions.testRun` [#13939](https://github.com/eclipse-theia/theia/pull/13939) - Contributed on behalf of STMicroelectronics
89

910
- [core] introduce `FRONTEND_CONNECTION_TIMEOUT` environment variable to override application connexion settings. [#13936](https://github.com/eclipse-theia/theia/pull/13936) - Contributed on behalf of STMicroelectronics
1011
- [core] tab selected should be adjacent when closing last one [#13912](https://github.com/eclipse-theia/theia/pull/13912) - contributed on behalf of STMicroelectronics
@@ -13,8 +14,6 @@
1314

1415
<a name="breaking_changes_not_yet_released">[Breaking Changes:](#breaking_changes_not_yet_released)</a>
1516

16-
-->
17-
1817
## 1.50.0 - 06/27/2024
1918

2019
- [application-manager] updated logic to load correct messaging module in browser-only mode [#13827](https://github.com/eclipse-theia/theia/pull/13827)

packages/debug/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@theia/output": "1.51.0",
1414
"@theia/process": "1.51.0",
1515
"@theia/task": "1.51.0",
16+
"@theia/test": "1.51.0",
1617
"@theia/terminal": "1.51.0",
1718
"@theia/variable-resolver": "1.51.0",
1819
"@theia/workspace": "1.51.0",

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service';
3131
import { DebugContribution } from './debug-contribution';
3232
import { WorkspaceService } from '@theia/workspace/lib/browser';
3333
import { RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser/messaging/service-connection-provider';
34+
import { TestService } from '@theia/test/lib/browser/test-service';
35+
import { DebugSessionManager } from './debug-session-manager';
3436

3537
/**
3638
* DebugSessionContribution symbol for DI.
@@ -90,7 +92,7 @@ export const DebugSessionFactory = Symbol('DebugSessionFactory');
9092
* The [debug session](#DebugSession) factory.
9193
*/
9294
export interface DebugSessionFactory {
93-
get(sessionId: string, options: DebugSessionOptions, parentSession?: DebugSession): DebugSession;
95+
get(manager: DebugSessionManager, sessionId: string, options: DebugSessionOptions, parentSession?: DebugSession): DebugSession;
9496
}
9597

9698
@injectable()
@@ -115,10 +117,12 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
115117
protected readonly fileService: FileService;
116118
@inject(ContributionProvider) @named(DebugContribution)
117119
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>;
120+
@inject(TestService)
121+
protected readonly testService: TestService;
118122
@inject(WorkspaceService)
119123
protected readonly workspaceService: WorkspaceService;
120124

121-
get(sessionId: string, options: DebugConfigurationSessionOptions, parentSession?: DebugSession): DebugSession {
125+
get(manager: DebugSessionManager, sessionId: string, options: DebugConfigurationSessionOptions, parentSession?: DebugSession): DebugSession {
122126
const connection = new DebugSessionConnection(
123127
sessionId,
124128
() => new Promise<DebugChannel>(resolve =>
@@ -131,6 +135,9 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
131135
sessionId,
132136
options,
133137
parentSession,
138+
this.testService,
139+
options.testRun,
140+
manager,
134141
connection,
135142
this.terminalService,
136143
this.editorManager,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export class DebugSessionManager {
386386
const parentSession = options.configuration.parentSessionId ? this._sessions.get(options.configuration.parentSessionId) : undefined;
387387
const contrib = this.sessionContributionRegistry.get(options.configuration.type);
388388
const sessionFactory = contrib ? contrib.debugSessionFactory() : this.debugSessionFactory;
389-
const session = sessionFactory.get(sessionId, options, parentSession);
389+
const session = sessionFactory.get(this, sessionId, options, parentSession);
390390
this._sessions.set(sessionId, session);
391391

392392
this.debugTypeKey.set(session.configuration.type);

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

+6
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ export class DebugCompoundRoot {
3131
}
3232
}
3333

34+
export interface TestRunReference {
35+
controllerId: string,
36+
runId: string
37+
}
38+
3439
export interface DebugSessionOptionsBase {
3540
workspaceFolderUri?: string,
41+
testRun?: TestRunReference
3642
}
3743

3844
export interface DebugConfigurationSessionOptions extends DebugSessionOptionsBase {

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

+19-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { DebugSourceBreakpoint } from './model/debug-source-breakpoint';
3333
import debounce = require('p-debounce');
3434
import URI from '@theia/core/lib/common/uri';
3535
import { BreakpointManager } from './breakpoint/breakpoint-manager';
36-
import { DebugConfigurationSessionOptions, InternalDebugSessionOptions } from './debug-session-options';
36+
import { DebugConfigurationSessionOptions, InternalDebugSessionOptions, TestRunReference } from './debug-session-options';
3737
import { DebugConfiguration, DebugConsoleMode } from '../common/debug-common';
3838
import { SourceBreakpoint, ExceptionBreakpoint } from './breakpoint/breakpoint-marker';
3939
import { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
@@ -44,6 +44,8 @@ import { Deferred, waitForEvent } from '@theia/core/lib/common/promise-util';
4444
import { WorkspaceService } from '@theia/workspace/lib/browser';
4545
import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
4646
import { nls } from '@theia/core';
47+
import { TestService, TestServices } from '@theia/test/lib/browser/test-service';
48+
import { DebugSessionManager } from './debug-session-manager';
4749

4850
export enum DebugState {
4951
Inactive,
@@ -98,6 +100,9 @@ export class DebugSession implements CompositeTreeElement {
98100
readonly id: string,
99101
readonly options: DebugConfigurationSessionOptions,
100102
readonly parentSession: DebugSession | undefined,
103+
testService: TestService,
104+
testRun: TestRunReference | undefined,
105+
sessionManager: DebugSessionManager,
101106
protected readonly connection: DebugSessionConnection,
102107
protected readonly terminalServer: TerminalService,
103108
protected readonly editorManager: EditorManager,
@@ -124,6 +129,19 @@ export class DebugSession implements CompositeTreeElement {
124129
this.parentSession?.childSessions?.delete(id);
125130
}));
126131
}
132+
if (testRun) {
133+
try {
134+
const run = TestServices.withTestRun(testService, testRun.controllerId, testRun.runId);
135+
run.onDidChangeProperty(evt => {
136+
if (evt.isRunning === false) {
137+
sessionManager.terminateSession(this);
138+
}
139+
});
140+
} catch (err) {
141+
console.error(err);
142+
}
143+
}
144+
127145
this.connection.onDidClose(() => this.toDispose.dispose());
128146
this.toDispose.pushAll([
129147
this.onDidChangeEmitter,

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

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export interface DebugSessionOptions {
100100
suppressSaveBeforeStart?: boolean;
101101
suppressDebugStatusbar?: boolean;
102102
suppressDebugView?: boolean;
103+
testRun?: {
104+
controllerId: string,
105+
runId: string
106+
}
103107
}
104108

105109
export enum DebugConsoleMode {

packages/debug/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
{
4040
"path": "../terminal"
4141
},
42+
{
43+
"path": "../test"
44+
},
4245
{
4346
"path": "../variable-resolver"
4447
},

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser';
5858
import { DebugSessionOptions as TheiaDebugSessionOptions } from '@theia/debug/lib/browser/debug-session-options';
5959
import { DebugStackFrame } from '@theia/debug/lib/browser/model/debug-stack-frame';
6060
import { DebugThread } from '@theia/debug/lib/browser/model/debug-thread';
61+
import { TestService } from '@theia/test/lib/browser/test-service';
6162

6263
export class DebugMainImpl implements DebugMain, Disposable {
6364
private readonly debugExt: DebugExt;
@@ -77,6 +78,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
7778
private readonly fileService: FileService;
7879
private readonly pluginService: HostedPluginSupport;
7980
private readonly debugContributionProvider: ContributionProvider<DebugContribution>;
81+
private readonly testService: TestService;
8082
private readonly workspaceService: WorkspaceService;
8183

8284
private readonly debuggerContributions = new Map<string, DisposableCollection>();
@@ -100,6 +102,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
100102
this.debugContributionProvider = container.getNamed(ContributionProvider, DebugContribution);
101103
this.fileService = container.get(FileService);
102104
this.pluginService = container.get(HostedPluginSupport);
105+
this.testService = container.get(TestService);
103106
this.workspaceService = container.get(WorkspaceService);
104107

105108
const fireDidChangeBreakpoints = ({ added, removed, changed }: BreakpointsChangeEvent<SourceBreakpoint | FunctionBreakpoint>) => {
@@ -165,6 +168,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
165168
this.fileService,
166169
terminalOptionsExt,
167170
this.debugContributionProvider,
171+
this.testService,
168172
this.workspaceService,
169173
);
170174

@@ -327,6 +331,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
327331
} else {
328332
sessionOptions = { ...sessionOptions, ...options, workspaceFolderUri };
329333
}
334+
sessionOptions.testRun = options.testRun;
330335

331336
// start options
332337
const session = await this.sessionManager.start(sessionOptions);
@@ -345,7 +350,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
345350
}
346351

347352
private toDebugStackFrameDTO(stackFrame: DebugStackFrame | undefined): DebugStackFrameDTO | undefined {
348-
return stackFrame ? {
353+
return stackFrame ? {
349354
sessionId: stackFrame.session.id,
350355
frameId: stackFrame.frameId,
351356
threadId: stackFrame.thread.threadId

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { LabelProvider } from '@theia/core/lib/browser/label-provider';
2222
import { MessageClient } from '@theia/core/lib/common/message-service-protocol';
2323
import { OutputChannelManager } from '@theia/output/lib/browser/output-channel';
2424
import { DebugPreferences } from '@theia/debug/lib/browser/debug-preferences';
25-
import { DebugConfigurationSessionOptions } from '@theia/debug/lib/browser/debug-session-options';
25+
import { DebugConfigurationSessionOptions, TestRunReference } from '@theia/debug/lib/browser/debug-session-options';
2626
import { DebugSession } from '@theia/debug/lib/browser/debug-session';
2727
import { DebugSessionConnection } from '@theia/debug/lib/browser/debug-session-connection';
2828
import { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
@@ -32,12 +32,17 @@ import { DebugContribution } from '@theia/debug/lib/browser/debug-contribution';
3232
import { ContributionProvider } from '@theia/core/lib/common/contribution-provider';
3333
import { WorkspaceService } from '@theia/workspace/lib/browser';
3434
import { PluginChannel } from '../../../common/connection';
35+
import { TestService } from '@theia/test/lib/browser/test-service';
36+
import { DebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
3537

3638
export class PluginDebugSession extends DebugSession {
3739
constructor(
3840
override readonly id: string,
3941
override readonly options: DebugConfigurationSessionOptions,
4042
override readonly parentSession: DebugSession | undefined,
43+
testService: TestService,
44+
testRun: TestRunReference | undefined,
45+
sessionManager: DebugSessionManager,
4146
protected override readonly connection: DebugSessionConnection,
4247
protected override readonly terminalServer: TerminalService,
4348
protected override readonly editorManager: EditorManager,
@@ -48,7 +53,8 @@ export class PluginDebugSession extends DebugSession {
4853
protected readonly terminalOptionsExt: TerminalOptionsExt | undefined,
4954
protected override readonly debugContributionProvider: ContributionProvider<DebugContribution>,
5055
protected override readonly workspaceService: WorkspaceService) {
51-
super(id, options, parentSession, connection, terminalServer, editorManager, breakpoints, labelProvider, messages, fileService, debugContributionProvider,
56+
super(id, options, parentSession, testService, testRun, sessionManager, connection, terminalServer, editorManager, breakpoints,
57+
labelProvider, messages, fileService, debugContributionProvider,
5258
workspaceService);
5359
}
5460

@@ -75,12 +81,13 @@ export class PluginDebugSessionFactory extends DefaultDebugSessionFactory {
7581
protected override readonly fileService: FileService,
7682
protected readonly terminalOptionsExt: TerminalOptionsExt | undefined,
7783
protected override readonly debugContributionProvider: ContributionProvider<DebugContribution>,
84+
protected override readonly testService: TestService,
7885
protected override readonly workspaceService: WorkspaceService,
7986
) {
8087
super();
8188
}
8289

83-
override get(sessionId: string, options: DebugConfigurationSessionOptions, parentSession?: DebugSession): DebugSession {
90+
override get(manager: DebugSessionManager, sessionId: string, options: DebugConfigurationSessionOptions, parentSession?: DebugSession): DebugSession {
8491
const connection = new DebugSessionConnection(
8592
sessionId,
8693
this.connectionFactory,
@@ -90,6 +97,9 @@ export class PluginDebugSessionFactory extends DefaultDebugSessionFactory {
9097
sessionId,
9198
options,
9299
parentSession,
100+
this.testService,
101+
options.testRun,
102+
manager,
93103
connection,
94104
this.terminalService,
95105
this.editorManager,

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import { DebugAdapter } from '@theia/debug/lib/common/debug-model';
3333
import { PluginDebugAdapterCreator } from './plugin-debug-adapter-creator';
3434
import { NodeDebugAdapterCreator } from '../node/debug/plugin-node-debug-adapter-creator';
3535
import { DebugProtocol } from '@vscode/debugprotocol';
36-
import { DebugConfiguration } from '@theia/debug/lib/common/debug-configuration';
36+
import { DebugConfiguration, DebugSessionOptions } from '@theia/debug/lib/common/debug-configuration';
37+
import { checkTestRunInstance } from '../tests';
3738

3839
interface ConfigurationProviderRecord {
3940
handle: number;
@@ -193,16 +194,24 @@ export class DebugExtImpl implements DebugExt {
193194
}
194195

195196
startDebugging(folder: theia.WorkspaceFolder | undefined, nameOrConfiguration: string | theia.DebugConfiguration, options: theia.DebugSessionOptions): PromiseLike<boolean> {
196-
return this.proxy.$startDebugging(folder, nameOrConfiguration, {
197+
const optionsDto: DebugSessionOptions = {
197198
parentSessionId: options.parentSession?.id,
198199
compact: options.compact,
199200
consoleMode: options.consoleMode,
200201
suppressSaveBeforeStart: options.suppressSaveBeforeStart,
201202
suppressDebugStatusbar: options.suppressDebugStatusbar,
202203
suppressDebugView: options.suppressDebugView,
203204
lifecycleManagedByParent: options.lifecycleManagedByParent,
204-
noDebug: options.noDebug
205-
});
205+
noDebug: options.noDebug,
206+
};
207+
if (options.testRun) {
208+
const run = checkTestRunInstance(options.testRun);
209+
optionsDto.testRun = {
210+
controllerId: run.controller.id,
211+
runId: run.id
212+
};
213+
}
214+
return this.proxy.$startDebugging(folder, nameOrConfiguration, optionsDto);
206215
}
207216

208217
stopDebugging(session?: theia.DebugSession): PromiseLike<void> {

0 commit comments

Comments
 (0)