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

check if there are any glob tasks before getting them from the workspace #187505

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 30 additions & 17 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
title: strings.fetching
};
const promise = (async () => {
let taskGroupTasks: (Task | ConfiguringTask)[] = [];
let groupTasks: (Task | ConfiguringTask)[] = [];

async function runSingleTask(task: Task | undefined, problemMatcherOptions: IProblemMatcherRunOptions | undefined, that: AbstractTaskService) {
that.run(task, problemMatcherOptions, TaskRunSource.User).then(undefined, reason => {
Expand Down Expand Up @@ -2949,22 +2949,35 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
});
});
};

let globTasksDetected = false;
// First check for globs before checking for the default tasks of the task group
const absoluteURI = EditorResourceAccessor.getOriginalUri(this._editorService.activeEditor);
if (absoluteURI) {
const workspaceFolder = this._contextService.getWorkspaceFolder(absoluteURI);
// fallback to absolute path of the file if it is not in a workspace or relative path cannot be found
const relativePath = workspaceFolder?.uri ? (resources.relativePath(workspaceFolder.uri, absoluteURI) ?? absoluteURI.path) : absoluteURI.path;
if (workspaceFolder) {
const configuredTasks = this._getConfiguration(workspaceFolder)?.config?.tasks;
if (configuredTasks) {
globTasksDetected = configuredTasks.filter(task => task.group && typeof task.group !== 'string' && typeof task.group.isDefault === 'string').length > 0;
// This will activate extensions, so only do so if necessary #185960
if (globTasksDetected) {
// Fallback to absolute path of the file if it is not in a workspace or relative path cannot be found
const relativePath = workspaceFolder?.uri ? (resources.relativePath(workspaceFolder.uri, absoluteURI) ?? absoluteURI.path) : absoluteURI.path;

groupTasks = await this._findWorkspaceTasks((task) => {
const currentTaskGroup = task.configurationProperties.group;
if (currentTaskGroup && typeof currentTaskGroup !== 'string' && typeof currentTaskGroup.isDefault === 'string') {
return (currentTaskGroup._id === taskGroup._id && glob.match(currentTaskGroup.isDefault, relativePath));
}

taskGroupTasks = await this._findWorkspaceTasks((task) => {
const currentTaskGroup = task.configurationProperties.group;
if (currentTaskGroup && typeof currentTaskGroup !== 'string' && typeof currentTaskGroup.isDefault === 'string') {
return (currentTaskGroup._id === taskGroup._id && glob.match(currentTaskGroup.isDefault, relativePath));
return false;
});
}
}
}
}

return false;
});
if (!globTasksDetected && groupTasks.length === 0) {
groupTasks = await this._findWorkspaceTasksInGroup(TaskGroup.Build, true);
}

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

// A single default glob task was returned, just run it directly
if (taskGroupTasks.length === 1) {
return resolveTaskAndRun(taskGroupTasks[0]);
if (groupTasks.length === 1) {
return resolveTaskAndRun(groupTasks[0]);
}

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

// 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);
if (!groupTasks.length) {
groupTasks = await this._findWorkspaceTasksInGroup(taskGroup, false);
}

// A single default task was returned, just run it directly
if (taskGroupTasks.length === 1) {
return resolveTaskAndRun(taskGroupTasks[0]);
if (groupTasks.length === 1) {
return resolveTaskAndRun(groupTasks[0]);
}

// Multiple default tasks returned, show the quickPicker
Expand Down