Skip to content

Commit

Permalink
fix #5861: ensure that plugin tasks are registered before accessing them
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Aug 6, 2019
1 parent 44a2ec7 commit 93e61fa
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Breaking changes:

- [task] `TaskService.getConfiguredTasks()` returns `Promise<TaskConfiguration[]>` instead of `TaskConfiguration[]` [#5777](https://github.com/theia-ide/theia/pull/5777)
- [plugin] files from 'plugin-ext/src/api' moved to 'plugin-ext/src/common', renamed 'model.ts' to 'plugin-api-rpc-model.ts', 'plugin-api.ts' to 'plugin-api-rpc.ts'
- [task] ensure that plugin tasks are registered before accessing them [5869](https://github.com/theia-ide/theia/pull/5869)
- `TaskProviderRegistry` and `TaskResolverRegistry` are promisified

Breaking changes:
- [shell][plugin] integrated view containers and views [#5665](https://github.com/theia-ide/theia/pull/5665)
Expand Down
2 changes: 1 addition & 1 deletion packages/cpp/src/browser/cpp-task-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class CppTaskProvider implements TaskContribution, TaskProvider, TaskReso
}

async resolveTask(task: CppBuildTaskConfiguration): Promise<TaskConfiguration> {
const resolver = this.taskResolverRegistry.getResolver('shell');
const resolver = await this.taskResolverRegistry.getResolver('shell');
if (!resolver) {
throw new Error('No shell resolver found, cannot build.');
}
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { FileSearchService } from '@theia/file-search/lib/common/file-search-ser
import { isCancelled } from '@theia/core';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
import { PluginViewRegistry } from '../../main/browser/view/plugin-view-registry';
import { TaskProviderRegistry, TaskResolverRegistry } from '@theia/task/lib/browser/task-contribution';

export type PluginHost = 'frontend' | string;
export type DebugActivationEvent = 'onDebugResolve' | 'onDebugInitialConfigurations' | 'onDebugAdapterProtocolTracker';
Expand Down Expand Up @@ -112,6 +113,12 @@ export class HostedPluginSupport {
@inject(PluginViewRegistry)
protected readonly viewRegistry: PluginViewRegistry;

@inject(TaskProviderRegistry)
protected readonly taskProviderRegistry: TaskProviderRegistry;

@inject(TaskResolverRegistry)
protected readonly taskResolverRegistry: TaskResolverRegistry;

private theiaReadyPromise: Promise<any>;

protected readonly managers: PluginManagerExt[] = [];
Expand All @@ -135,6 +142,8 @@ export class HostedPluginSupport {
this.debugSessionManager.onWillResolveDebugConfiguration(event => this.ensureDebugActivation(event, 'onDebugResolve', event.debugType));
this.debugConfigurationManager.onWillProvideDebugConfiguration(event => this.ensureDebugActivation(event, 'onDebugInitialConfigurations'));
this.viewRegistry.onDidExpandView(id => this.activateByView(id));
this.taskProviderRegistry.onWillProvideTaskProvider(event => this.ensureTaskActivation(event));
this.taskResolverRegistry.onWillProvideTaskResolver(event => this.ensureTaskActivation(event));
}

checkAndLoadPlugin(container: interfaces.Container): void {
Expand Down Expand Up @@ -290,6 +299,10 @@ export class HostedPluginSupport {
event.waitUntil(p);
}

protected ensureTaskActivation(event: WaitUntilEvent): void {
event.waitUntil(this.activateByCommand('workbench.action.tasks.runTask'));
}

protected ensureDebugActivation(event: WaitUntilEvent, activationEvent?: DebugActivationEvent, debugType?: string): void {
event.waitUntil(this.activateByDebug(activationEvent, debugType));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/task/src/browser/provided-task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ProvidedTaskConfigurations {

/** returns a list of provided tasks */
async getTasks(): Promise<TaskConfiguration[]> {
const providers = this.taskProviderRegistry.getProviders();
const providers = await this.taskProviderRegistry.getProviders();
const providedTasks: TaskConfiguration[] = (await Promise.all(providers.map(p => p.provideTasks())))
.reduce((acc, taskArray) => acc.concat(taskArray), []);
this.cacheTasks(providedTasks);
Expand Down
16 changes: 13 additions & 3 deletions packages/task/src/browser/task-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { injectable, postConstruct } from 'inversify';
import { Disposable } from '@theia/core/lib/common/disposable';
import { TaskConfiguration } from '../common/task-protocol';
import { WaitUntilEvent, Emitter } from '@theia/core/lib/common/event';

export const TaskContribution = Symbol('TaskContribution');

Expand All @@ -39,6 +40,9 @@ export interface TaskProvider {
@injectable()
export class TaskResolverRegistry {

protected readonly onWillProvideTaskResolverEmitter = new Emitter<WaitUntilEvent>();
readonly onWillProvideTaskResolver = this.onWillProvideTaskResolverEmitter.event;

protected resolvers: Map<string, TaskResolver>;

@postConstruct()
Expand All @@ -54,14 +58,18 @@ export class TaskResolverRegistry {
};
}

getResolver(type: string): TaskResolver | undefined {
async getResolver(type: string): Promise<TaskResolver | undefined> {
await WaitUntilEvent.fire(this.onWillProvideTaskResolverEmitter, {});
return this.resolvers.get(type);
}
}

@injectable()
export class TaskProviderRegistry {

protected readonly onWillProvideTaskProviderEmitter = new Emitter<WaitUntilEvent>();
readonly onWillProvideTaskProvider = this.onWillProvideTaskProviderEmitter.event;

protected providers: Map<string, TaskProvider>;

@postConstruct()
Expand All @@ -78,12 +86,14 @@ export class TaskProviderRegistry {
};
}

getProvider(type: string): TaskProvider | undefined {
async getProvider(type: string): Promise<TaskProvider | undefined> {
await WaitUntilEvent.fire(this.onWillProvideTaskProviderEmitter, {});
return this.providers.get(type);
}

/** Returns all registered Task Providers. */
getProviders(): TaskProvider[] {
async getProviders(): Promise<TaskProvider[]> {
await WaitUntilEvent.fire(this.onWillProvideTaskProviderEmitter, {});
return [...this.providers.values()];
}
}
2 changes: 1 addition & 1 deletion packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export class TaskService implements TaskConfigurationClient {
}
}

const resolver = this.taskResolverRegistry.getResolver(task.type);
const resolver = await this.taskResolverRegistry.getResolver(task.type);
let resolvedTask: TaskConfiguration;
try {
resolvedTask = resolver ? await resolver.resolveTask(task) : task;
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
],
"@theia/userstorage/lib/*": [
"packages/userstorage/src/*"
],
"@theia/task/lib/*": [
"packages/task/src/*"
]
},
"plugins": [
Expand Down

0 comments on commit 93e61fa

Please sign in to comment.