Skip to content

Commit 0422c8f

Browse files
authored
Merge pull request microsoft#187505 from microsoft/merogge/glob-fix
check if there are any glob tasks before getting them from the workspace
2 parents f07abd2 + ee5cc0d commit 0422c8f

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
29212921
title: strings.fetching
29222922
};
29232923
const promise = (async () => {
2924-
let taskGroupTasks: (Task | ConfiguringTask)[] = [];
2924+
let groupTasks: (Task | ConfiguringTask)[] = [];
29252925

29262926
async function runSingleTask(task: Task | undefined, problemMatcherOptions: IProblemMatcherRunOptions | undefined, that: AbstractTaskService) {
29272927
that.run(task, problemMatcherOptions, TaskRunSource.User).then(undefined, reason => {
@@ -2949,22 +2949,35 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
29492949
});
29502950
});
29512951
};
2952-
2952+
let globTasksDetected = false;
29532953
// First check for globs before checking for the default tasks of the task group
29542954
const absoluteURI = EditorResourceAccessor.getOriginalUri(this._editorService.activeEditor);
29552955
if (absoluteURI) {
29562956
const workspaceFolder = this._contextService.getWorkspaceFolder(absoluteURI);
2957-
// fallback to absolute path of the file if it is not in a workspace or relative path cannot be found
2958-
const relativePath = workspaceFolder?.uri ? (resources.relativePath(workspaceFolder.uri, absoluteURI) ?? absoluteURI.path) : absoluteURI.path;
2957+
if (workspaceFolder) {
2958+
const configuredTasks = this._getConfiguration(workspaceFolder)?.config?.tasks;
2959+
if (configuredTasks) {
2960+
globTasksDetected = configuredTasks.filter(task => task.group && typeof task.group !== 'string' && typeof task.group.isDefault === 'string').length > 0;
2961+
// This will activate extensions, so only do so if necessary #185960
2962+
if (globTasksDetected) {
2963+
// Fallback to absolute path of the file if it is not in a workspace or relative path cannot be found
2964+
const relativePath = workspaceFolder?.uri ? (resources.relativePath(workspaceFolder.uri, absoluteURI) ?? absoluteURI.path) : absoluteURI.path;
2965+
2966+
groupTasks = await this._findWorkspaceTasks((task) => {
2967+
const currentTaskGroup = task.configurationProperties.group;
2968+
if (currentTaskGroup && typeof currentTaskGroup !== 'string' && typeof currentTaskGroup.isDefault === 'string') {
2969+
return (currentTaskGroup._id === taskGroup._id && glob.match(currentTaskGroup.isDefault, relativePath));
2970+
}
29592971

2960-
taskGroupTasks = await this._findWorkspaceTasks((task) => {
2961-
const currentTaskGroup = task.configurationProperties.group;
2962-
if (currentTaskGroup && typeof currentTaskGroup !== 'string' && typeof currentTaskGroup.isDefault === 'string') {
2963-
return (currentTaskGroup._id === taskGroup._id && glob.match(currentTaskGroup.isDefault, relativePath));
2972+
return false;
2973+
});
2974+
}
29642975
}
2976+
}
2977+
}
29652978

2966-
return false;
2967-
});
2979+
if (!globTasksDetected && groupTasks.length === 0) {
2980+
groupTasks = await this._findWorkspaceTasksInGroup(TaskGroup.Build, true);
29682981
}
29692982

29702983
const handleMultipleTasks = (areGlobTasks: boolean) => {
@@ -2997,25 +3010,25 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
29973010
};
29983011

29993012
// A single default glob task was returned, just run it directly
3000-
if (taskGroupTasks.length === 1) {
3001-
return resolveTaskAndRun(taskGroupTasks[0]);
3013+
if (groupTasks.length === 1) {
3014+
return resolveTaskAndRun(groupTasks[0]);
30023015
}
30033016

30043017
// If there's multiple globs that match we want to show the quick picker for those tasks
30053018
// We will need to call splitPerGroupType putting globs in defaults and the remaining tasks in none.
30063019
// We don't need to carry on after here
3007-
if (taskGroupTasks.length > 1) {
3020+
if (globTasksDetected && groupTasks.length > 1) {
30083021
return handleMultipleTasks(true);
30093022
}
30103023

30113024
// If no globs are found or matched fallback to checking for default tasks of the task group
3012-
if (!taskGroupTasks.length) {
3013-
taskGroupTasks = await this._findWorkspaceTasksInGroup(taskGroup, false);
3025+
if (!groupTasks.length) {
3026+
groupTasks = await this._findWorkspaceTasksInGroup(taskGroup, false);
30143027
}
30153028

30163029
// A single default task was returned, just run it directly
3017-
if (taskGroupTasks.length === 1) {
3018-
return resolveTaskAndRun(taskGroupTasks[0]);
3030+
if (groupTasks.length === 1) {
3031+
return resolveTaskAndRun(groupTasks[0]);
30193032
}
30203033

30213034
// Multiple default tasks returned, show the quickPicker

0 commit comments

Comments
 (0)