Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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

## v.1.26.0

- [plugin] Introduce `DebugSession#workspaceFolder` [#11090](https://github.com/eclipse-theia/theia/pull/11090) - Contributed on behalf of STMicroelectronics

## v1.25.0 - 4/28/2022

[1.25.0 Milestone](https://github.com/eclipse-theia/theia/milestone/35)
Expand Down
6 changes: 5 additions & 1 deletion packages/debug/src/browser/debug-session-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { Channel, DebugAdapterPath } from '../common/debug-service';
import { ContributionProvider } from '@theia/core/lib/common/contribution-provider';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { DebugContribution } from './debug-contribution';
import { WorkspaceService } from '@theia/workspace/lib/browser';

/**
* DebugSessionContribution symbol for DI.
Expand Down Expand Up @@ -114,6 +115,8 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
protected readonly fileService: FileService;
@inject(ContributionProvider) @named(DebugContribution)
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>;
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

get(sessionId: string, options: DebugSessionOptions, parentSession?: DebugSession): DebugSession {
const connection = new DebugSessionConnection(
Expand All @@ -135,7 +138,8 @@ export class DefaultDebugSessionFactory implements DebugSessionFactory {
this.labelProvider,
this.messages,
this.fileService,
this.debugContributionProvider);
this.debugContributionProvider,
this.workspaceService);
}

protected getTraceOutputChannel(): OutputChannel | undefined {
Expand Down
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 @@ -214,7 +214,7 @@ export class DebugSessionManager {
}
}

const sessionId = await this.debug.createDebugSession(resolved.configuration);
const sessionId = await this.debug.createDebugSession(resolved.configuration, options.workspaceFolderUri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not appear that the implementation of the createDebugSession method on the DebugServiceImpl has been updated to handle the workspaceFolderUri. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. No, this was an oversight, since this value is not needed there.
In the plain Theia API the ws folder is taken from the DebugSessionOptions and we only need it for vs code compatibility.
I've added the parameter as _workspaceFolderUri?

return this.doStart(sessionId, resolved);
} catch (e) {
if (DebugError.NotFound.is(e)) {
Expand Down
12 changes: 9 additions & 3 deletions packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { DebugContribution } from './debug-contribution';
import { waitForEvent } from '@theia/core/lib/common/promise-util';
import { WorkspaceService } from '@theia/workspace/lib/browser';

export enum DebugState {
Inactive,
Expand Down Expand Up @@ -79,7 +80,8 @@ export class DebugSession implements CompositeTreeElement {
protected readonly labelProvider: LabelProvider,
protected readonly messages: MessageClient,
protected readonly fileService: FileService,
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>
protected readonly debugContributionProvider: ContributionProvider<DebugContribution>,
protected readonly workspaceService: WorkspaceService,
) {
this.connection.onRequest('runInTerminal', (request: DebugProtocol.RunInTerminalRequest) => this.runInTerminal(request));
this.connection.onDidClose(() => {
Expand Down Expand Up @@ -747,10 +749,14 @@ export class DebugSession implements CompositeTreeElement {
}

get label(): string {
const suffixes = [];
if (InternalDebugSessionOptions.is(this.options) && this.options.id) {
return this.configuration.name + ' (' + (this.options.id + 1) + ')';
suffixes.push(String(this.options.id + 1));
}
return this.configuration.name;
if (this.workspaceService.isMultiRootWorkspaceOpened && this.options.workspaceFolderUri) {
suffixes.push(this.labelProvider.getName(new URI(this.options.workspaceFolderUri)));
}
return suffixes.length === 0 ? this.configuration.name : this.configuration.name + ` (${suffixes.join(' - ')})`;
}

get visible(): boolean {
Expand Down
3 changes: 2 additions & 1 deletion packages/debug/src/common/debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ export interface DebugService extends Disposable {
/**
* Creates a new [debug adapter session](#DebugAdapterSession).
* @param config The resolved [debug configuration](#DebugConfiguration).
* @param workspaceFolderUri The worspace folder for this sessions or undefined when folderless
* @returns The identifier of the created [debug adapter session](#DebugAdapterSession).
*/
createDebugSession(config: DebugConfiguration): Promise<string>;
createDebugSession(config: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<string>;

/**
* Stop a running session for the given session id.
Expand Down
2 changes: 1 addition & 1 deletion packages/debug/src/node/debug-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class DebugServiceImpl implements DebugService {
}

protected readonly sessions = new Set<string>();
async createDebugSession(config: DebugConfiguration): Promise<string> {
async createDebugSession(config: DebugConfiguration, _workspaceFolderUri?: string): Promise<string> {
const session = await this.sessionManager.create(config, this.registry);
this.sessions.add(session.id);
return session.id;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ export interface DebugExt {
debugConfiguration: theia.DebugConfiguration
): Promise<theia.DebugConfiguration | undefined | null>;

$createDebugSession(debugConfiguration: theia.DebugConfiguration): Promise<string>;
$createDebugSession(debugConfiguration: theia.DebugConfiguration, workspaceFolder: string | undefined): Promise<string>;
$terminateDebugSession(sessionId: string): Promise<void>;
$getTerminalCreationOptions(debugType: string): Promise<TerminalOptionsExt | undefined>;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-ext/src/main/browser/debug/debug-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { DebugConsoleSession } from '@theia/debug/lib/browser/console/debug-cons
import { ContributionProvider } from '@theia/core/lib/common';
import { DebugContribution } from '@theia/debug/lib/browser/debug-contribution';
import { ConnectionImpl } from '../../../common/connection';
import { WorkspaceService } from '@theia/workspace/lib/browser';

export class DebugMainImpl implements DebugMain, Disposable {
private readonly debugExt: DebugExt;
Expand All @@ -73,6 +74,7 @@ export class DebugMainImpl implements DebugMain, Disposable {
private readonly fileService: FileService;
private readonly pluginService: HostedPluginSupport;
private readonly debugContributionProvider: ContributionProvider<DebugContribution>;
private readonly workspaceService: WorkspaceService;

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

const fireDidChangeBreakpoints = ({ added, removed, changed }: BreakpointsChangeEvent<SourceBreakpoint | FunctionBreakpoint>) => {
this.debugExt.$breakpointsDidChange(
Expand Down Expand Up @@ -155,7 +158,8 @@ export class DebugMainImpl implements DebugMain, Disposable {
},
this.fileService,
terminalOptionsExt,
this.debugContributionProvider
this.debugContributionProvider,
this.workspaceService,
);

const toDispose = new DisposableCollection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export class PluginDebugAdapterContribution {
return this.description.label;
}

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

async terminateDebugSession(sessionId: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ export class PluginDebugService implements DebugService {
return snippets;
}

async createDebugSession(config: DebugConfiguration): Promise<string> {
async createDebugSession(config: DebugConfiguration, workspaceFolder: string | undefined): Promise<string> {
const contributor = this.contributors.get(config.type);
if (contributor) {
const sessionId = await contributor.createDebugSession(config);
const sessionId = await contributor.createDebugSession(config, workspaceFolder);
this.sessionId2contrib.set(sessionId, contributor);
return sessionId;
} else {
return this.delegated.createDebugSession(config);
return this.delegated.createDebugSession(config, workspaceFolder);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { DebugContribution } from '@theia/debug/lib/browser/debug-contribution';
import { ContributionProvider } from '@theia/core/lib/common/contribution-provider';
import { Channel } from '@theia/debug/lib/common/debug-service';
import { WorkspaceService } from '@theia/workspace/lib/browser';

export class PluginDebugSession extends DebugSession {
constructor(
Expand All @@ -45,8 +46,10 @@ export class PluginDebugSession extends DebugSession {
protected override readonly messages: MessageClient,
protected override readonly fileService: FileService,
protected readonly terminalOptionsExt: TerminalOptionsExt | undefined,
protected override readonly debugContributionProvider: ContributionProvider<DebugContribution>) {
super(id, options, parentSession, connection, terminalServer, editorManager, breakpoints, labelProvider, messages, fileService, debugContributionProvider);
protected override readonly debugContributionProvider: ContributionProvider<DebugContribution>,
protected override readonly workspaceService: WorkspaceService) {
super(id, options, parentSession, connection, terminalServer, editorManager, breakpoints, labelProvider, messages, fileService, debugContributionProvider,
workspaceService);
}

protected override async doCreateTerminal(terminalWidgetOptions: TerminalWidgetOptions): Promise<TerminalWidget> {
Expand All @@ -71,7 +74,8 @@ export class PluginDebugSessionFactory extends DefaultDebugSessionFactory {
protected readonly connectionFactory: (sessionId: string) => Promise<Channel>,
protected override readonly fileService: FileService,
protected readonly terminalOptionsExt: TerminalOptionsExt | undefined,
protected override readonly debugContributionProvider: ContributionProvider<DebugContribution>
protected override readonly debugContributionProvider: ContributionProvider<DebugContribution>,
protected override readonly workspaceService: WorkspaceService,
) {
super();
}
Expand All @@ -94,7 +98,8 @@ export class PluginDebugSessionFactory extends DefaultDebugSessionFactory {
this.messages,
this.fileService,
this.terminalOptionsExt,
this.debugContributionProvider
this.debugContributionProvider,
this.workspaceService,
);
}
}
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/node/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,14 @@ export class DebugExtImpl implements DebugExt {
return undefined;
}

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

const theiaSession: theia.DebugSession = {
id: sessionId,
type: debugConfiguration.type,
name: debugConfiguration.name,
workspaceFolder: this.toWorkspaceFolder(workspaceFolderUri),
configuration: debugConfiguration,
customRequest: async (command: string, args?: any) => {
const response = await this.proxy.$customRequest(sessionId, command, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Channel } from '@theia/debug/lib/common/debug-service';
export class PluginDebugAdapterSession extends DebugAdapterSessionImpl {
readonly type: string;
readonly name: string;
readonly workspaceFolder: theia.WorkspaceFolder | undefined;
readonly configuration: theia.DebugConfiguration;

constructor(
Expand All @@ -38,6 +39,7 @@ export class PluginDebugAdapterSession extends DebugAdapterSessionImpl {

this.type = theiaSession.type;
this.name = theiaSession.name;
this.workspaceFolder = theiaSession.workspaceFolder;
this.configuration = theiaSession.configuration;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9648,6 +9648,11 @@ export module '@theia/plugin' {
*/
readonly name: string;

/**
* The workspace folder of this session or `undefined` for a folderless setup.
*/
readonly workspaceFolder: WorkspaceFolder | undefined;

/**
* The "resolved" [debug configuration](#DebugConfiguration) of this session.
*/
Expand Down