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

ensure tasks have been resolved before run task commands are executed, only show default build tasks in quick-pick #186025

Merged
merged 9 commits into from
Jun 23, 2023
30 changes: 14 additions & 16 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this._configurationResolverService.contributeVariable('defaultBuildTask', async (): Promise<string | undefined> => {
let tasks = await this._getTasksForGroup(TaskGroup.Build);
if (tasks.length > 0) {
const { none, defaults } = this._splitPerGroupType(tasks);
const defaults = this._getDefaultTasks(tasks);
if (defaults.length === 1) {
return defaults[0]._label;
} else if (defaults.length + none.length > 0) {
tasks = defaults.concat(none);
} else if (defaults.length) {
tasks = defaults;
}
}

Expand Down Expand Up @@ -335,6 +335,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this._waitForSupportedExecutions = new Promise(resolve => {
once(this._onDidRegisterSupportedExecutions.event)(() => resolve());
});

meganrogge marked this conversation as resolved.
Show resolved Hide resolved
if (this._terminalService.getReconnectedTerminals('Task')?.length) {
this._attemptTaskReconnection();
} else {
Expand All @@ -344,7 +345,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
}
}));
}

this._registerCommands().then(() => TaskCommandsRegistered.bindTo(this._contextKeyService).set(true));
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
this._upgrade();
}

Expand Down Expand Up @@ -2875,24 +2876,21 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer

/**
*
* @param tasks - The tasks which need filtering from defaults and non-defaults
* @param taskGlobsInList - This tells splitPerGroupType to filter out globbed tasks (into default), otherwise fall back to boolean
* @param tasks - The tasks which need to be filtered
* @param taskGlobsInList - This tells splitPerGroupType to filter out globbed tasks (into defaults)
* @returns
*/
private _splitPerGroupType(tasks: Task[], taskGlobsInList: boolean = false): { none: Task[]; defaults: Task[] } {
const none: Task[] = [];
private _getDefaultTasks(tasks: Task[], taskGlobsInList: boolean = false): Task[] {
const defaults: Task[] = [];
for (const task of tasks) {
// At this point (assuming taskGlobsInList is true) there are tasks with matching globs, so only put those in defaults
if (taskGlobsInList && typeof (task.configurationProperties.group as TaskGroup).isDefault === 'string') {
defaults.push(task);
} else if (!taskGlobsInList && (task.configurationProperties.group as TaskGroup).isDefault === true) {
defaults.push(task);
} else {
none.push(task);
}
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
}
return { none, defaults };
return defaults;
}

private _runTaskGroupCommand(taskGroup: TaskGroup, strings: {
Expand All @@ -2909,7 +2907,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
title: strings.fetching
};
const promise = (async () => {

await this.getWorkspaceTasks();
let taskGroupTasks: (Task | ConfiguringTask)[] = [];

async function runSingleTask(task: Task | undefined, problemMatcherOptions: IProblemMatcherRunOptions | undefined, that: AbstractTaskService) {
Expand Down Expand Up @@ -2961,12 +2959,12 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
if (tasks.length > 0) {
// If we're dealing with tasks that were chosen because of a glob match,
// then put globs in the defaults and everything else in none
const { none, defaults } = this._splitPerGroupType(tasks, areGlobTasks);
const defaults = this._getDefaultTasks(tasks, areGlobTasks);
if (defaults.length === 1) {
runSingleTask(defaults[0], undefined, this);
return;
} else if (defaults.length + none.length > 0) {
tasks = defaults.concat(none);
} else if (defaults.length > 0) {
tasks = defaults;
}
}

Expand Down Expand Up @@ -2999,7 +2997,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer

// If no globs are found or matched fallback to checking for default tasks of the task group
if (!taskGroupTasks.length) {
taskGroupTasks = await this._findWorkspaceTasksInGroup(taskGroup, false);
taskGroupTasks = await this._findWorkspaceTasksInGroup(taskGroup, true);
}

// A single default task was returned, just run it directly
Expand Down