Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "lifecycleManagedByParent" #51

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 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,13 @@ 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 +466,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