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

delay task provider activation until the task is found/run or fallback to activating all #223136

Merged
merged 1 commit into from
Jul 22, 2024
Merged
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
23 changes: 18 additions & 5 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,24 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this._registerCommands().then(() => TaskCommandsRegistered.bindTo(this._contextKeyService).set(true));
ServerlessWebContext.bindTo(this._contextKeyService).set(Platform.isWeb && !remoteAgentService.getConnection()?.remoteAuthority);
this._configurationResolverService.contributeVariable('defaultBuildTask', async (): Promise<string | undefined> => {
let tasks = await this._getTasksForGroup(TaskGroup.Build);
// delay provider activation, we might find a default task in the tasks.json file
let tasks = await this._getTasksForGroup(TaskGroup.Build, true);
if (tasks.length > 0) {
const defaults = this._getDefaultTasks(tasks);
if (defaults.length === 1) {
return defaults[0]._label;
} else if (defaults.length) {
tasks = defaults;
}
} else {
// activate all providers, we haven't found the default build task in the tasks.json file
tasks = await this._getTasksForGroup(TaskGroup.Build);
const defaults = this._getDefaultTasks(tasks);
if (defaults.length === 1) {
return defaults[0]._label;
} else if (defaults.length) {
tasks = defaults;
}
}

let entry: ITaskQuickPickEntry | null | undefined;
Expand Down Expand Up @@ -608,6 +618,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
// We need to first wait for extensions to be registered because we might read
// the `TaskDefinitionRegistry` in case `type` is `undefined`
await this._extensionService.whenInstalledExtensionsRegistered();
this._log('Activating task providers ' + type ?? 'all');
await raceTimeout(
Promise.all(this._getActivationEvents(type).map(activationEvent => this._extensionService.activateByEvent(activationEvent))),
5000,
Expand Down Expand Up @@ -1418,8 +1429,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
return task;
}

private async _getTasksForGroup(group: TaskGroup): Promise<Task[]> {
const groups = await this._getGroupedTasks();
private async _getTasksForGroup(group: TaskGroup, waitToActivate?: boolean): Promise<Task[]> {
const groups = await this._getGroupedTasks(undefined, waitToActivate);
const result: Task[] = [];
groups.forEach(tasks => {
for (const task of tasks) {
Expand Down Expand Up @@ -2001,11 +2012,13 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
return !definition || !definition.when || this._contextKeyService.contextMatchesRules(definition.when);
}

private async _getGroupedTasks(filter?: ITaskFilter): Promise<TaskMap> {
private async _getGroupedTasks(filter?: ITaskFilter, waitToActivate?: boolean): Promise<TaskMap> {
await this._waitForAllSupportedExecutions;
const type = filter?.type;
const needsRecentTasksMigration = this._needsRecentTasksMigration();
await this._activateTaskProviders(filter?.type);
if (!waitToActivate) {
await this._activateTaskProviders(filter?.type);
}
const validTypes: IStringDictionary<boolean> = Object.create(null);
TaskDefinitionRegistry.all().forEach(definition => validTypes[definition.taskType] = true);
validTypes['shell'] = true;
Expand Down
Loading