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

Allow "Command" type in status bar items #8253

Merged
merged 2 commits into from
Jul 30, 2020
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
9 changes: 7 additions & 2 deletions packages/debug/src/browser/debug-session-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ export class DebugSessionManager {
return options;
}
const { workspaceFolderUri } = options;
const resolvedConfiguration = await this.resolveDebugConfiguration(options.configuration, workspaceFolderUri);
const configuration = await this.variableResolver.resolve(resolvedConfiguration, {
let configuration = await this.resolveDebugConfiguration(options.configuration, workspaceFolderUri);
configuration = await this.variableResolver.resolve(configuration, {
context: options.workspaceFolderUri ? new URI(options.workspaceFolderUri) : undefined,
configurationSection: 'launch'
});
configuration = await this.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
const key = configuration.name + workspaceFolderUri;
const id = this.configurationIds.has(key) ? this.configurationIds.get(key)! + 1 : 0;
this.configurationIds.set(key, id);
Expand All @@ -229,6 +230,10 @@ export class DebugSessionManager {
await WaitUntilEvent.fire(this.onWillResolveDebugConfigurationEmitter, { debugType });
}

protected async resolveDebugConfigurationWithSubstitutedVariables(configuration: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<DebugConfiguration> {
return this.debug.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
}

protected async doStart(sessionId: string, options: DebugSessionOptions): Promise<DebugSession> {
const contrib = this.sessionContributionRegistry.get(options.configuration.type);
const sessionFactory = contrib ? contrib.debugSessionFactory() : this.debugSessionFactory;
Expand Down
10 changes: 9 additions & 1 deletion packages/debug/src/common/debug-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,17 @@ export interface DebugAdapterContribution {

/**
* Resolves a [debug configuration](#DebugConfiguration) by filling in missing values
* or by adding/changing/removing attributes.
* or by adding/changing/removing attributes before variable substitution.
* @param config The [debug configuration](#DebugConfiguration) to resolve.
* @returns The resolved debug configuration.
*/
resolveDebugConfiguration?(config: DebugConfiguration, workspaceFolderUri?: string): MaybePromise<DebugConfiguration | undefined>;

/**
* Resolves a [debug configuration](#DebugConfiguration) by filling in missing values
* or by adding/changing/removing attributes with substituted variables.
* @param config The [debug configuration](#DebugConfiguration) to resolve.
* @returns The resolved debug configuration.
*/
resolveDebugConfigurationWithSubstitutedVariables?(config: DebugConfiguration, workspaceFolderUri?: string): MaybePromise<DebugConfiguration | undefined>;
}
10 changes: 9 additions & 1 deletion packages/debug/src/common/debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ export interface DebugService extends Disposable {

/**
* Resolves a [debug configuration](#DebugConfiguration) by filling in missing values
* or by adding/changing/removing attributes.
* or by adding/changing/removing attributes before variable substitution.
* @param debugConfiguration The [debug configuration](#DebugConfiguration) to resolve.
* @returns The resolved debug configuration.
*/
resolveDebugConfiguration(config: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<DebugConfiguration>;

/**
* Resolves a [debug configuration](#DebugConfiguration) by filling in missing values
* or by adding/changing/removing attributes with substituted variables.
* @param debugConfiguration The [debug configuration](#DebugConfiguration) to resolve.
* @returns The resolved debug configuration.
*/
resolveDebugConfigurationWithSubstitutedVariables(config: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<DebugConfiguration>;

/**
* Creates a new [debug adapter session](#DebugAdapterSession).
* @param config The resolved [debug configuration](#DebugConfiguration).
Expand Down
27 changes: 26 additions & 1 deletion packages/debug/src/node/debug-adapter-contribution-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class DebugAdapterContributionRegistry {

/**
* Resolves a [debug configuration](#DebugConfiguration) by filling in missing values
* or by adding/changing/removing attributes.
* or by adding/changing/removing attributes before variable substitution.
* @param debugConfiguration The [debug configuration](#DebugConfiguration) to resolve.
* @returns The resolved debug configuration.
*/
Expand All @@ -115,6 +115,31 @@ export class DebugAdapterContributionRegistry {
return current;
}

/**
* Resolves a [debug configuration](#DebugConfiguration) by filling in missing values
* or by adding/changing/removing attributes with substituted variables.
* @param debugConfiguration The [debug configuration](#DebugConfiguration) to resolve.
* @returns The resolved debug configuration.
*/
async resolveDebugConfigurationWithSubstitutedVariables(config: DebugConfiguration, workspaceFolderUri?: string): Promise<DebugConfiguration> {
let current = config;
for (const contribution of this.getContributions(config.type)) {
if (contribution.resolveDebugConfigurationWithSubstitutedVariables) {
try {
const next = await contribution.resolveDebugConfigurationWithSubstitutedVariables(config, workspaceFolderUri);
if (next) {
current = next;
} else {
return current;
}
} catch (e) {
console.error(e);
}
}
}
return current;
}

/**
* Provides schema attributes.
* @param debugType The registered debug type
Expand Down
3 changes: 3 additions & 0 deletions packages/debug/src/node/debug-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class DebugServiceImpl implements DebugService {
async resolveDebugConfiguration(config: DebugConfiguration, workspaceFolderUri?: string): Promise<DebugConfiguration> {
return this.registry.resolveDebugConfiguration(config, workspaceFolderUri);
}
async resolveDebugConfigurationWithSubstitutedVariables(config: DebugConfiguration, workspaceFolderUri?: string): Promise<DebugConfiguration> {
return this.registry.resolveDebugConfigurationWithSubstitutedVariables(config, workspaceFolderUri);
}

protected readonly sessions = new Set<string>();
async createDebugSession(config: DebugConfiguration): Promise<string> {
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ export interface StatusBarMessageRegistryMain {
alignment: theia.StatusBarAlignment,
color: string | undefined,
tooltip: string | undefined,
command: string | undefined): PromiseLike<void>;
$update(id: string, message: string): void;
command: string | undefined,
args: any[] | undefined): PromiseLike<void>;
$dispose(id: string): void;
}

Expand Down Expand Up @@ -1366,6 +1366,8 @@ export interface DebugExt {
$sessionDidChange(sessionId: string | undefined): void;
$provideDebugConfigurations(debugType: string, workspaceFolder: string | undefined): Promise<theia.DebugConfiguration[]>;
$resolveDebugConfigurations(debugConfiguration: theia.DebugConfiguration, workspaceFolder: string | undefined): Promise<theia.DebugConfiguration | undefined>;
$resolveDebugConfigurationWithSubstitutedVariables(debugConfiguration: theia.DebugConfiguration, workspaceFolder: string | undefined):
Promise<theia.DebugConfiguration | undefined>;
$createDebugSession(debugConfiguration: theia.DebugConfiguration): Promise<string>;
$terminateDebugSession(sessionId: string): Promise<void>;
$getTerminalCreationOptions(debugType: string): Promise<TerminalOptionsExt | undefined>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export class PluginDebugAdapterContribution {
return this.debugExt.$resolveDebugConfigurations(config, workspaceFolderUri);
}

async resolveDebugConfigurationWithSubstitutedVariables(config: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<DebugConfiguration | undefined> {
return this.debugExt.$resolveDebugConfigurationWithSubstitutedVariables(config, workspaceFolderUri);
}

async createDebugSession(config: DebugConfiguration): Promise<string> {
await this.pluginService.activateByDebug('onDebugAdapterProtocolTracker', config.type);
return this.debugExt.$createDebugSession(config);
Expand Down
22 changes: 22 additions & 0 deletions packages/plugin-ext/src/main/browser/debug/plugin-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ export class PluginDebugService implements DebugService, PluginDebugAdapterContr
return this.delegated.resolveDebugConfiguration(resolved, workspaceFolderUri);
}

async resolveDebugConfigurationWithSubstitutedVariables(config: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<DebugConfiguration> {
let resolved = config;

// we should iterate over all to handle configuration providers for `*`
for (const contributor of this.contributors.values()) {
if (contributor) {
try {
const next = await contributor.resolveDebugConfigurationWithSubstitutedVariables(resolved, workspaceFolderUri);
if (next) {
resolved = next;
} else {
return resolved;
}
} catch (e) {
console.error(e);
}
}
}

return this.delegated.resolveDebugConfigurationWithSubstitutedVariables(resolved, workspaceFolderUri);
}

registerDebugger(contribution: DebuggerContribution): Disposable {
this.debuggers.push(contribution);
return Disposable.create(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ export class StatusBarMessageRegistryMainImpl implements StatusBarMessageRegistr
alignment: number,
color: string | undefined,
tooltip: string | undefined,
command: string | undefined): Promise<void> {
command: string | undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args: any[] | undefined): Promise<void> {
const entry = {
text: text || '',
priority,
alignment: alignment === types.StatusBarAlignment.Left ? StatusBarAlignment.LEFT : StatusBarAlignment.RIGHT,
color: color && (this.colorRegistry.getCurrentColor(color) || color),
tooltip,
command
command,
args
};

this.entries.set(id, entry);
Expand All @@ -63,14 +66,6 @@ export class StatusBarMessageRegistryMainImpl implements StatusBarMessageRegistr
}
}

$update(id: string, message: string): void {
const entry = this.entries.get(id);
if (entry) {
entry.text = message;
this.delegate.setElement(id, entry);
}
}

$dispose(id: string): void {
const entry = this.entries.get(id);
if (entry) {
Expand Down
26 changes: 26 additions & 0 deletions packages/plugin-ext/src/plugin/node/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,32 @@ export class DebugExtImpl implements DebugExt {
return current;
}

async $resolveDebugConfigurationWithSubstitutedVariables(debugConfiguration: theia.DebugConfiguration, workspaceFolderUri: string | undefined):
Promise<theia.DebugConfiguration | undefined> {
let current = debugConfiguration;

for (const providers of [this.configurationProviders.get(debugConfiguration.type), this.configurationProviders.get('*')]) {
if (providers) {
for (const provider of providers) {
if (provider.resolveDebugConfigurationWithSubstitutedVariables) {
try {
const next = await provider.resolveDebugConfigurationWithSubstitutedVariables(this.toWorkspaceFolder(workspaceFolderUri), current);
if (next) {
current = next;
} else {
return current;
}
} catch (e) {
console.error(e);
}
}
}
}
}

return current;
}

protected async createDebugAdapterTracker(session: theia.DebugSession): Promise<theia.DebugAdapterTracker> {
return PluginDebugAdapterTracker.create(session, this.trackerFactories);
}
Expand Down
11 changes: 7 additions & 4 deletions packages/plugin-ext/src/plugin/status-bar/status-bar-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
private _text: string;
private _tooltip: string;
private _color: string | ThemeColor;
private _command: string;
private _command: string | theia.Command;

private _isVisible: boolean;
private _timeoutHandle: NodeJS.Timer | undefined;
Expand Down Expand Up @@ -63,7 +63,7 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
return this._color;
}

public get command(): string {
public get command(): string | theia.Command {
return this._command;
}

Expand All @@ -82,7 +82,7 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
this.update();
}

public set command(command: string) {
public set command(command: string | theia.Command) {
this._command = command;
this.update();
}
Expand Down Expand Up @@ -111,13 +111,16 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
this._timeoutHandle = setTimeout(() => {
this._timeoutHandle = undefined;

const commandId = typeof this.command === 'object' ? this.command.command : this.command;
const args = typeof this.command === 'object' ? this.command.arguments : undefined;
// Set to status bar
this._proxy.$setMessage(this.id, this.text,
this.priority,
this.alignment,
typeof this.color === 'string' ? this.color : this.color && this.color.id,
this.tooltip,
this.command);
commandId,
args);
}, 0);
}

Expand Down
17 changes: 16 additions & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ declare module '@theia/plugin' {
/**
* The identifier of a command to run on click.
*/
command: string | undefined;
command: string | Command | undefined;

/**
* Shows the entry in the status bar.
Expand Down Expand Up @@ -8183,6 +8183,21 @@ declare module '@theia/plugin' {
* @return The resolved debug configuration or undefined or null.
*/
resolveDebugConfiguration?(folder: WorkspaceFolder | undefined, debugConfiguration: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration>;

/**
* This hook is directly called after 'resolveDebugConfiguration' but with all variables substituted.
* It can be used to resolve or verify a [debug configuration](#DebugConfiguration) by filling in missing values or by adding/changing/removing attributes.
* If more than one debug configuration provider is registered for the same type, the 'resolveDebugConfigurationWithSubstitutedVariables' calls are chained
* in arbitrary order and the initial debug configuration is piped through the chain.
* Returning the value 'undefined' prevents the debug session from starting.
* Returning the value 'null' prevents the debug session from starting and opens the underlying debug configuration instead.
*
* @param folder The workspace folder from which the configuration originates from or `undefined` for a folderless setup.
* @param debugConfiguration The [debug configuration](#DebugConfiguration) to resolve.
* @param token A cancellation token.
* @return The resolved debug configuration or undefined or null.
*/
resolveDebugConfigurationWithSubstitutedVariables?(folder: WorkspaceFolder | undefined, debugConfiguration: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration>;
}

/**
Expand Down