Skip to content

Commit

Permalink
Add suppport vor DebugSession.parentSession. Fixes eclipse-theia#11512
Browse files Browse the repository at this point in the history
Adds support for the parentSession property in theia.d.ts. Includes
some minor changes to make sure we're not sending theia.DebugSession
object over the wire, but only session ids.

Contributed on behalf of ST Microelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Nov 24, 2022
1 parent b58de21 commit b3b5d89
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/debug/src/browser/debug-session-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export class DebugSessionManager {
}

protected async doStart(sessionId: string, options: DebugConfigurationSessionOptions): Promise<DebugSession> {
const parentSession = options.configuration.parentSession && this._sessions.get(options.configuration.parentSession.id);
const parentSession = options.configuration.parentSessionId ? this._sessions.get(options.configuration.parentSessionId) : undefined;
const contrib = this.sessionContributionRegistry.get(options.configuration.type);
const sessionFactory = contrib ? contrib.debugSessionFactory() : this.debugSessionFactory;
const session = sessionFactory.get(sessionId, options, parentSession);
Expand Down
4 changes: 2 additions & 2 deletions packages/debug/src/common/debug-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface DebugConfiguration {
*/
[key: string]: any;

parentSession?: { id: string };
parentSessionId?: string;

lifecycleManagedByParent?: boolean;

Expand Down Expand Up @@ -80,7 +80,7 @@ export namespace DebugConfiguration {

export interface DebugSessionOptions {
lifecycleManagedByParent?: boolean;
parentSession?: { id: string };
parentSessionId?: string;
consoleMode?: DebugConsoleMode;
noDebug?: boolean;
compact?: boolean;
Expand Down
7 changes: 4 additions & 3 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import { ThemeType } from '@theia/core/lib/common/theme';
import { Disposable } from '@theia/core/lib/common/disposable';
import { PickOptions, QuickInputButtonHandle } from '@theia/core/lib/common';
import { Severity } from '@theia/core/lib/common/severity';
import { DebugConfiguration, DebugSessionOptions } from '@theia/debug/lib/common/debug-configuration';

export interface PreferenceData {
[scope: number]: any;
Expand Down Expand Up @@ -1800,10 +1801,10 @@ export interface DebugExt {
$resolveDebugConfigurationWithSubstitutedVariablesByHandle(
handle: number,
workspaceFolder: string | undefined,
debugConfiguration: theia.DebugConfiguration
debugConfiguration: DebugConfiguration
): Promise<theia.DebugConfiguration | undefined | null>;

$createDebugSession(debugConfiguration: theia.DebugConfiguration, workspaceFolder: string | undefined): Promise<string>;
$createDebugSession(debugConfiguration: DebugConfiguration, workspaceFolder: string | undefined): Promise<string>;
$terminateDebugSession(sessionId: string): Promise<void>;
$getTerminalCreationOptions(debugType: string): Promise<TerminalOptionsExt | undefined>;
}
Expand All @@ -1817,7 +1818,7 @@ export interface DebugMain {
$unregisterDebugConfigurationProvider(handle: number): Promise<void>;
$addBreakpoints(breakpoints: Breakpoint[]): Promise<void>;
$removeBreakpoints(breakpoints: string[]): Promise<void>;
$startDebugging(folder: theia.WorkspaceFolder | undefined, nameOrConfiguration: string | theia.DebugConfiguration, options: theia.DebugSessionOptions): Promise<boolean>;
$startDebugging(folder: theia.WorkspaceFolder | undefined, nameOrConfiguration: string | theia.DebugConfiguration, options: DebugSessionOptions): Promise<boolean>;
$stopDebugging(sessionId?: string): Promise<void>;
$customRequest(sessionId: string, command: string, args?: any): Promise<DebugProtocol.Response>;
$getDebugProtocolBreakpoint(sessionId: string, breakpointId: string): Promise<theia.DebugProtocolBreakpoint | undefined>;
Expand Down
13 changes: 11 additions & 2 deletions packages/plugin-ext/src/plugin/debug/debug-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { DebugAdapter } from '@theia/debug/lib/common/debug-model';
import { PluginDebugAdapterCreator } from './plugin-debug-adapter-creator';
import { NodeDebugAdapterCreator } from '../node/debug/plugin-node-debug-adapter-creator';
import { DebugProtocol } from '@vscode/debugprotocol';
import { DebugConfiguration } from '@theia/debug/lib/common/debug-configuration';

interface ConfigurationProviderRecord {
handle: number;
Expand Down Expand Up @@ -171,7 +172,13 @@ export class DebugExtImpl implements DebugExt {
}

startDebugging(folder: theia.WorkspaceFolder | undefined, nameOrConfiguration: string | theia.DebugConfiguration, options: theia.DebugSessionOptions): PromiseLike<boolean> {
return this.proxy.$startDebugging(folder, nameOrConfiguration, options);
return this.proxy.$startDebugging(folder, nameOrConfiguration, {
parentSessionId: options.parentSession?.id,
compact: options.compact,
consoleMode: options.consoleMode,
lifecycleManagedByParent: options.lifecycleManagedByParent,
noDebug: options.noDebug
});
}

stopDebugging(session?: theia.DebugSession): PromiseLike<void> {
Expand Down Expand Up @@ -313,13 +320,15 @@ export class DebugExtImpl implements DebugExt {
return undefined;
}

async $createDebugSession(debugConfiguration: theia.DebugConfiguration, workspaceFolderUri: string | undefined): Promise<string> {
async $createDebugSession(debugConfiguration: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<string> {
const sessionId = uuid.v4();

const parentSession = debugConfiguration.parentSessionId ? this.sessions.get(debugConfiguration.parentSessionId) : undefined;
const theiaSession: theia.DebugSession = {
id: sessionId,
type: debugConfiguration.type,
name: debugConfiguration.name,
parentSession: parentSession,
workspaceFolder: this.toWorkspaceFolder(workspaceFolderUri),
configuration: debugConfiguration,
customRequest: async (command: string, args?: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,32 @@ import { DebugChannel } from '@theia/debug/lib/common/debug-service';
/**
* Server debug adapter session.
*/
export class PluginDebugAdapterSession extends DebugAdapterSessionImpl {
readonly type: string;
readonly name: string;
readonly workspaceFolder: theia.WorkspaceFolder | undefined;
readonly configuration: theia.DebugConfiguration;
export class PluginDebugAdapterSession extends DebugAdapterSessionImpl implements theia.DebugSession {

constructor(
override readonly debugAdapter: DebugAdapter,
protected readonly tracker: theia.DebugAdapterTracker,
protected readonly theiaSession: theia.DebugSession) {

super(theiaSession.id, debugAdapter);
}

get parentSession(): theia.DebugSession | undefined {
return this.theiaSession.parentSession;
}

this.type = theiaSession.type;
this.name = theiaSession.name;
this.workspaceFolder = theiaSession.workspaceFolder;
this.configuration = theiaSession.configuration;
get type(): string {
return this.theiaSession.type;
}
get name(): string {
return this.theiaSession.name;
};
get workspaceFolder(): theia.WorkspaceFolder | undefined {
return this.theiaSession.workspaceFolder;
};
get configuration(): theia.DebugConfiguration {
return this.theiaSession.configuration;
};

override async start(channel: DebugChannel): Promise<void> {
if (this.tracker.onWillStartSession) {
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10664,6 +10664,12 @@ export module '@theia/plugin' {
*/
readonly name: string;

/**
* The parent session of this debug session, if it was created as a child.
* @see DebugSessionOptions.parentSession
*/
readonly parentSession?: DebugSession;

/**
* The workspace folder of this session or `undefined` for a folderless setup.
*/
Expand Down

0 comments on commit b3b5d89

Please sign in to comment.