Skip to content

Commit

Permalink
Add support for lifecycleManagedByParent. Fixes eclipse-theia#11511
Browse files Browse the repository at this point in the history
Forwards lifecycle events to parent session where applicable and changes
the behavior of compound sessions to behave same way.

Contributed on behalf of ST Microelectronics

Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
  • Loading branch information
tsmaeder committed Oct 6, 2022
1 parent d3f6359 commit a16bcb8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
33 changes: 27 additions & 6 deletions packages/debug/src/browser/debug-session-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ export class DebugSessionManager {

protected async startCompound(options: DebugCompoundSessionOptions): Promise<boolean | undefined> {
let configurations: DebugConfigurationSessionOptions[] = [];
const compoundRoot = options.compound.stopAll ? new DebugCompoundRoot() : undefined;
try {
configurations = this.getCompoundConfigurations(options);
configurations = this.getCompoundConfigurations(options, compoundRoot);
} catch (error) {
this.messageService.error(error.message);
return;
Expand All @@ -265,19 +266,25 @@ export class DebugSessionManager {
}

// Compound launch is a success only if each configuration launched successfully
const values = await Promise.all(configurations.map(configuration => this.startConfiguration(configuration)));
const values = await Promise.all(configurations.map(async configuration => {
const newSession = await this.startConfiguration(configuration);
if (newSession) {
compoundRoot?.onDidSessionStop(() => newSession.stop(false, () => this.debug.terminateDebugSession(newSession.id)));
}
return newSession;
}));
const result = values.every(success => !!success);
return result;
}

protected getCompoundConfigurations(options: DebugCompoundSessionOptions): DebugConfigurationSessionOptions[] {
protected getCompoundConfigurations(options: DebugCompoundSessionOptions, compoundRoot: DebugCompoundRoot | undefined): DebugConfigurationSessionOptions[] {
const compound = options.compound;
if (!compound.configurations) {
throw new Error(nls.localizeByDefault('Compound must have "configurations" attribute set in order to start multiple configurations.'));
}

const compoundRoot = compound.stopAll ? new DebugCompoundRoot() : undefined;
const configurations: DebugConfigurationSessionOptions[] = [];

for (const configData of compound.configurations) {
const name = typeof configData === 'string' ? configData : configData.name;
if (name === compound.name) {
Expand Down Expand Up @@ -431,6 +438,7 @@ export class DebugSessionManager {
await session.restart();
return session;
}

const { options, configuration } = session;
session.stop(isRestart, () => this.debug.terminateDebugSession(session.id));
configuration.__restart = isRestart;
Expand All @@ -443,7 +451,15 @@ export class DebugSessionManager {
session = this._currentSession;
}
if (session) {
session.stop(false, () => this.debug.terminateDebugSession(session!.id));
if (session.options.compoundRoot) {
session.options.compoundRoot.stopSession();
} else {
if (session.parentSession && session.configuration.lifecycleManagedByParent) {
this.terminateSession(session.parentSession);
} else {
session.stop(false, () => this.debug.terminateDebugSession(session!.id));
}
}
}
}

Expand All @@ -452,8 +468,13 @@ export class DebugSessionManager {
this.updateCurrentSession(this._currentSession);
session = this._currentSession;
}

if (session) {
return this.doRestart(session, true);
if (session.parentSession && session.configuration.lifecycleManagedByParent) {
return this.restartSession(session.parentSession);
} else {
return this.doRestart(session, true);
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ export class DebugSession implements CompositeTreeElement {
this.connection.on('capabilities', event => this.updateCapabilities(event.body.capabilities)),
this.breakpoints.onDidChangeMarkers(uri => this.updateBreakpoints({ uri, sourceModified: true }))
]);
if (this.options.compoundRoot) {
this.toDispose.push(this.options.compoundRoot.onDidSessionStop(() => this.stop(false, () => { })));
}
}

get onDispose(): Event<void> {
Expand Down Expand Up @@ -355,9 +352,6 @@ export class DebugSession implements CompositeTreeElement {
console.error('Error on disconnect', e);
}
}
if (!isRestart) {
this.options.compoundRoot?.stopSession();
}
callback();
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/debug/src/common/debug-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface DebugConfiguration {

parentSession?: { id: string };

lifecycleManagedByParent?: boolean;

consoleMode?: DebugConsoleMode;

compact?: boolean;
Expand Down Expand Up @@ -77,6 +79,7 @@ export namespace DebugConfiguration {
}

export interface DebugSessionOptions {
lifecycleManagedByParent?: boolean;
parentSession?: { id: string };
consoleMode?: DebugConsoleMode;
noDebug?: boolean;
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10269,6 +10269,13 @@ export module '@theia/plugin' {
*/
parentSession?: DebugSession;

/**
* Controls whether lifecycle requests like 'restart' are sent to the newly created session or its parent session.
* By default (if the property is false or missing), lifecycle requests are sent to the new session.
* This property is ignored if the session has no parent session.
*/
lifecycleManagedByParent?: boolean;

/**
* Controls whether this session should have a separate debug console or share it
* with the parent session. Has no effect for sessions which do not have a parent session.
Expand Down

0 comments on commit a16bcb8

Please sign in to comment.