From 0dce81403bcd224afaff7dcb289168358c81ea6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Thu, 11 Jun 2020 09:39:25 +0200 Subject: [PATCH] =?UTF-8?q?Introduce=20a=20token=20to=20scope=20contribute?= =?UTF-8?q?d=20tasksSigned-off-by:=20Thomas=20M=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/browser/debug-session-manager.ts | 2 +- .../plugin-ext/src/main/browser/tasks-main.ts | 5 +- .../provided-task-configurations.spec.ts | 2 +- .../browser/provided-task-configurations.ts | 71 ++++++++++++------- packages/task/src/browser/quick-open-task.ts | 56 ++++++++++----- .../task/src/browser/task-configurations.ts | 16 ++--- .../src/browser/task-frontend-contribution.ts | 6 +- packages/task/src/browser/task-service.ts | 64 +++++++++-------- 8 files changed, 131 insertions(+), 91 deletions(-) diff --git a/packages/debug/src/browser/debug-session-manager.ts b/packages/debug/src/browser/debug-session-manager.ts index e481df8aa5fb3..e101d6fc828ee 100644 --- a/packages/debug/src/browser/debug-session-manager.ts +++ b/packages/debug/src/browser/debug-session-manager.ts @@ -439,7 +439,7 @@ export class DebugSessionManager { return true; } - const taskInfo = await this.taskService.runWorkspaceTask(workspaceFolderUri, taskName); + const taskInfo = await this.taskService.runWorkspaceTask(this.taskService.startUserAction(), workspaceFolderUri, taskName); if (!checkErrors) { return true; } diff --git a/packages/plugin-ext/src/main/browser/tasks-main.ts b/packages/plugin-ext/src/main/browser/tasks-main.ts index 84c0c41d9a7ca..aa34b7adb6e10 100644 --- a/packages/plugin-ext/src/main/browser/tasks-main.ts +++ b/packages/plugin-ext/src/main/browser/tasks-main.ts @@ -105,9 +105,10 @@ export class TasksMainImpl implements TasksMain, Disposable { return []; } + const token: number = this.taskService.startUserAction(); const [configured, provided] = await Promise.all([ - this.taskService.getConfiguredTasks(), - this.taskService.getProvidedTasks() + this.taskService.getConfiguredTasks(token), + this.taskService.getProvidedTasks(token) ]); const result: TaskDto[] = []; for (const tasks of [configured, provided]) { diff --git a/packages/task/src/browser/provided-task-configurations.spec.ts b/packages/task/src/browser/provided-task-configurations.spec.ts index c42eac3fbe435..bb71c2b654da5 100644 --- a/packages/task/src/browser/provided-task-configurations.spec.ts +++ b/packages/task/src/browser/provided-task-configurations.spec.ts @@ -38,7 +38,7 @@ describe('provided-task-configurations', () => { } }); - const task = await container.get(ProvidedTaskConfigurations).getTask('test', 'task from test', 'test'); + const task = await container.get(ProvidedTaskConfigurations).getTask(1, 'test', 'task from test', 'test'); assert.isOk(task); assert.equal(task!.type, 'test'); assert.equal(task!.label, 'task from test'); diff --git a/packages/task/src/browser/provided-task-configurations.ts b/packages/task/src/browser/provided-task-configurations.ts index 9f44546a0a898..ad625a4287140 100644 --- a/packages/task/src/browser/provided-task-configurations.ts +++ b/packages/task/src/browser/provided-task-configurations.ts @@ -21,7 +21,6 @@ import { TaskConfiguration, TaskCustomization, TaskOutputPresentation, TaskConfi @injectable() export class ProvidedTaskConfigurations { - /** * Map of source (name of extension, or path of root folder that the task config comes from) and `task config map`. * For the second level of inner map, the key is task label. @@ -35,36 +34,53 @@ export class ProvidedTaskConfigurations { @inject(TaskDefinitionRegistry) protected readonly taskDefinitionRegistry: TaskDefinitionRegistry; + private currentToken: number = 0; + private nextToken = 1; + + startUserAction(): number { + return this.nextToken++; + } + /** returns a list of provided tasks */ - async getTasks(): Promise { - const providers = await this.taskProviderRegistry.getProviders(); - const providedTasks: TaskConfiguration[] = (await Promise.all(providers.map(p => p.provideTasks()))) - .reduce((acc, taskArray) => acc.concat(taskArray), []) - .map(providedTask => { - const originalPresentation = providedTask.presentation || {}; - return { - ...providedTask, - presentation: { - ...TaskOutputPresentation.getDefault(), - ...originalPresentation - } - }; - }); - this.cacheTasks(providedTasks); - return providedTasks; + async getTasks(token: number): Promise { + await this.refreshTasks(token); + const tasks: TaskConfiguration[] = []; + for (const taskLabelMap of this.tasksMap!.values()) { + for (const taskScopeMap of taskLabelMap.values()) { + for (const task of taskScopeMap.values()) { + tasks.push(task); + } + } + } + return tasks; } - /** returns the task configuration for a given source and label or undefined if none */ - async getTask(source: string, taskLabel: string, scope: TaskConfigurationScope): Promise { - const task = this.getCachedTask(source, taskLabel, scope); - if (task) { - return task; - } else { - await this.getTasks(); - return this.getCachedTask(source, taskLabel, scope); + protected async refreshTasks(token: number): Promise { + if (token !== this.currentToken) { + this.currentToken = token; + const providers = await this.taskProviderRegistry.getProviders(); + const providedTasks: TaskConfiguration[] = (await Promise.all(providers.map(p => p.provideTasks()))) + .reduce((acc, taskArray) => acc.concat(taskArray), []) + .map(providedTask => { + const originalPresentation = providedTask.presentation || {}; + return { + ...providedTask, + presentation: { + ...TaskOutputPresentation.getDefault(), + ...originalPresentation + } + }; + }); + this.cacheTasks(providedTasks); } } + /** returns the task configuration for a given source and label or undefined if none */ + async getTask(token: number, source: string, taskLabel: string, scope: TaskConfigurationScope): Promise { + await this.refreshTasks(token); + return this.getCachedTask(source, taskLabel, scope); + } + /** * Finds the detected task for the given task customization. * The detected task is considered as a "match" to the task customization if it has all the `required` properties. @@ -73,7 +89,7 @@ export class ProvidedTaskConfigurations { * @param customization the task customization * @return the detected task for the given task customization. If the task customization is not found, `undefined` is returned. */ - async getTaskToCustomize(customization: TaskCustomization, scope: TaskConfigurationScope): Promise { + async getTaskToCustomize(token: number, customization: TaskCustomization, scope: TaskConfigurationScope): Promise { const definition = this.taskDefinitionRegistry.getDefinition(customization); if (!definition) { return undefined; @@ -81,7 +97,7 @@ export class ProvidedTaskConfigurations { const matchedTasks: TaskConfiguration[] = []; let highest = -1; - const tasks = await this.getTasks(); + const tasks = await this.getTasks(token); for (const task of tasks) { // find detected tasks that match the `definition` let score = 0; if (!definition.properties.required.every(requiredProp => customization[requiredProp] !== undefined)) { @@ -123,6 +139,7 @@ export class ProvidedTaskConfigurations { } protected cacheTasks(tasks: TaskConfiguration[]): void { + this.tasksMap.clear(); for (const task of tasks) { const label = task.label; const source = task._source; diff --git a/packages/task/src/browser/quick-open-task.ts b/packages/task/src/browser/quick-open-task.ts index 086fa4bc9850b..7d0aa7ae92b2c 100644 --- a/packages/task/src/browser/quick-open-task.ts +++ b/packages/task/src/browser/quick-open-task.ts @@ -44,7 +44,7 @@ export class ConfigureTaskAction extends QuickOpenBaseAction { async run(item?: QuickOpenItem): Promise { if (item instanceof TaskRunQuickOpenItem) { - this.taskService.configure(item.getTask()); + this.taskService.configure(item.getToken(), item.getTask()); } } @@ -111,25 +111,29 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { @inject(LabelProvider) protected readonly labelProvider: LabelProvider; + init(): Promise { + return this.doInit(this.taskService.startUserAction()); + } + /** Initialize this quick open model with the tasks. */ - async init(): Promise { + protected async doInit(token: number): Promise { const recentTasks = this.taskService.recentTasks; - const configuredTasks = await this.taskService.getConfiguredTasks(); - const providedTasks = await this.taskService.getProvidedTasks(); + const configuredTasks = await this.taskService.getConfiguredTasks(token); + const providedTasks = await this.taskService.getProvidedTasks(token); const { filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, providedTasks); const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened; this.items = []; this.items.push( ...filteredRecentTasks.map((task, index) => { - const item = new TaskRunQuickOpenItem(task, this.taskService, isMulti, { + const item = new TaskRunQuickOpenItem(token, task, this.taskService, isMulti, { groupLabel: index === 0 ? 'recently used tasks' : undefined, showBorder: false }, this.taskDefinitionRegistry, this.taskNameResolver, this.taskSourceResolver); return item; }), ...filteredConfiguredTasks.map((task, index) => { - const item = new TaskRunQuickOpenItem(task, this.taskService, isMulti, { + const item = new TaskRunQuickOpenItem(token, task, this.taskService, isMulti, { groupLabel: index === 0 ? 'configured tasks' : undefined, showBorder: ( filteredRecentTasks.length <= 0 @@ -140,7 +144,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { return item; }), ...filteredProvidedTasks.map((task, index) => { - const item = new TaskRunQuickOpenItem(task, this.taskService, isMulti, { + const item = new TaskRunQuickOpenItem(token, task, this.taskService, isMulti, { groupLabel: index === 0 ? 'detected tasks' : undefined, showBorder: ( filteredRecentTasks.length <= 0 && filteredConfiguredTasks.length <= 0 @@ -156,7 +160,8 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { } async open(): Promise { - await this.init(); + const token: number = this.taskService.startUserAction(); + await this.doInit(token); if (!this.items.length) { this.items.push(new QuickOpenItem({ label: 'No task to run found. Configure Tasks...', @@ -235,8 +240,10 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { this.actionProvider = undefined; const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened; - const configuredTasks = await this.taskService.getConfiguredTasks(); - const providedTasks = await this.taskService.getProvidedTasks(); + const token: number = this.taskService.startUserAction(); + + const configuredTasks = await this.taskService.getConfiguredTasks(token); + const providedTasks = await this.taskService.getProvidedTasks(token); // check if tasks.json exists. If not, display "Create tasks.json file from template" // If tasks.json exists and empty, display 'Open tasks.json file' @@ -248,6 +255,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { this.items.push( ...configs.map(taskConfig => { const item = new TaskConfigureQuickOpenItem( + token, taskConfig, this.taskService, this.taskNameResolver, @@ -270,6 +278,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { this.items.push( ...configs.map((taskConfig, index) => { const item = new TaskConfigureQuickOpenItem( + token, taskConfig, this.taskService, this.taskNameResolver, @@ -319,7 +328,8 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { async runBuildOrTestTask(buildOrTestType: 'build' | 'test'): Promise { const shouldRunBuildTask = buildOrTestType === 'build'; - await this.init(); + const token: number = this.taskService.startUserAction(); + await this.doInit(token); if (this.items.length > 1 || this.items.length === 1 && (this.items[0] as TaskRunQuickOpenItem).getTask !== undefined) { // the item in `this.items` is not 'No tasks found' @@ -337,9 +347,9 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { const scope = taskToRun._scope; if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(taskToRun)) { - this.taskService.run(taskToRun.source, taskToRun.label, scope); + this.taskService.run(token, taskToRun.source, taskToRun.label, scope); } else { - this.taskService.run(taskToRun._source, taskToRun.label, scope); + this.taskService.run(token, taskToRun._source, taskToRun.label, scope); } return; } @@ -356,10 +366,11 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { return false; } - this.init().then(() => { + this.doInit(token).then(() => { // update the `tasks.json` file, instead of running the task itself this.items = this.items.map((item: TaskRunQuickOpenItem) => { const newItem = new ConfigureBuildOrTestTaskQuickOpenItem( + token, item.getTask(), this.taskService, this.workspaceService.isMultiRootWorkspaceOpened, @@ -466,6 +477,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { export class TaskRunQuickOpenItem extends QuickOpenGroupItem { constructor( + protected readonly token: number, protected readonly task: TaskConfiguration, protected taskService: TaskService, protected isMulti: boolean, @@ -485,6 +497,10 @@ export class TaskRunQuickOpenItem extends QuickOpenGroupItem { return this.taskNameResolver.resolve(this.task); } + getToken(): number { + return this.token; + } + getGroupLabel(): string { return this.options.groupLabel || ''; } @@ -500,9 +516,9 @@ export class TaskRunQuickOpenItem extends QuickOpenGroupItem { const scope = this.task._scope; if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(this.task)) { - this.taskService.run(this.task.source || this.task._source, this.task.label, scope); + this.taskService.run(this.token, this.task.source || this.task._source, this.task.label, scope); } else { - this.taskService.run(this.task._source, this.task.label, scope); + this.taskService.run(this.token, this.task._source, this.task.label, scope); } return true; } @@ -510,6 +526,7 @@ export class TaskRunQuickOpenItem extends QuickOpenGroupItem { export class ConfigureBuildOrTestTaskQuickOpenItem extends TaskRunQuickOpenItem { constructor( + protected readonly token: number, protected readonly task: TaskConfiguration, protected taskService: TaskService, protected isMulti: boolean, @@ -520,14 +537,14 @@ export class ConfigureBuildOrTestTaskQuickOpenItem extends TaskRunQuickOpenItem protected readonly taskDefinitionRegistry: TaskDefinitionRegistry, protected readonly taskSourceResolver: TaskSourceResolver ) { - super(task, taskService, isMulti, options, taskDefinitionRegistry, taskNameResolver, taskSourceResolver); + super(token, task, taskService, isMulti, options, taskDefinitionRegistry, taskNameResolver, taskSourceResolver); } run(mode: QuickOpenMode): boolean { if (mode !== QuickOpenMode.OPEN) { return false; } - this.taskService.updateTaskConfiguration(this.task, { group: { kind: this.isBuildTask ? 'build' : 'test', isDefault: true } }) + this.taskService.updateTaskConfiguration(this.token, this.task, { group: { kind: this.isBuildTask ? 'build' : 'test', isDefault: true } }) .then(() => { if (this.task._scope) { this.taskConfigurationManager.openConfiguration(this.task._scope); @@ -555,6 +572,7 @@ export class TaskConfigureQuickOpenItem extends QuickOpenGroupItem { protected taskDefinitionRegistry: TaskDefinitionRegistry; constructor( + protected readonly token: number, protected readonly task: TaskConfiguration, protected readonly taskService: TaskService, protected readonly taskNameResolver: TaskNameResolver, @@ -583,7 +601,7 @@ export class TaskConfigureQuickOpenItem extends QuickOpenGroupItem { if (mode !== QuickOpenMode.OPEN) { return false; } - this.taskService.configure(this.task); + this.taskService.configure(this.token, this.task); return true; } diff --git a/packages/task/src/browser/task-configurations.ts b/packages/task/src/browser/task-configurations.ts index 0473904884af3..3af0861b0c8ab 100644 --- a/packages/task/src/browser/task-configurations.ts +++ b/packages/task/src/browser/task-configurations.ts @@ -136,13 +136,13 @@ export class TaskConfigurations implements Disposable { * * The invalid task configs are not returned. */ - async getTasks(): Promise { + async getTasks(token: number): Promise { const configuredTasks = Array.from(this.tasksMap.values()).reduce((acc, labelConfigMap) => acc.concat(Array.from(labelConfigMap.values())), [] as TaskConfiguration[]); const detectedTasksAsConfigured: TaskConfiguration[] = []; for (const [rootFolder, customizations] of Array.from(this.taskCustomizationMap.entries())) { for (const cus of customizations) { // TODO: getTasksToCustomize() will ask all task providers to contribute tasks. Doing this in a loop is bad. - const detected = await this.providedTaskConfigurations.getTaskToCustomize(cus, rootFolder); + const detected = await this.providedTaskConfigurations.getTaskToCustomize(token, cus, rootFolder); if (detected) { // there might be a provided task that has a different scope from the task we're inspecting detectedTasksAsConfigured.push({ ...detected, ...cus }); @@ -193,12 +193,12 @@ export class TaskConfigurations implements Disposable { } /** returns the customized task for a given label or undefined if none */ - async getCustomizedTask(scope: TaskConfigurationScope, taskLabel: string): Promise { + async getCustomizedTask(token: number, scope: TaskConfigurationScope, taskLabel: string): Promise { const customizations = this.taskCustomizationMap.get(this.getKeyFromScope(scope)); if (customizations) { const customization = customizations.find(cus => cus.label === taskLabel); if (customization) { - const detected = await this.providedTaskConfigurations.getTaskToCustomize(customization, scope); + const detected = await this.providedTaskConfigurations.getTaskToCustomize(token, customization, scope); if (detected) { return { ...detected, @@ -307,7 +307,7 @@ export class TaskConfigurations implements Disposable { } /** Adds given task to a config file and opens the file to provide ability to edit task configuration. */ - async configure(task: TaskConfiguration): Promise { + async configure(token: number, task: TaskConfiguration): Promise { const scope = task._scope; if (scope === TaskScope.Global) { return this.openUserTasks(); @@ -322,7 +322,7 @@ export class TaskConfigurations implements Disposable { return; } - const configuredAndCustomizedTasks = await this.getTasks(); + const configuredAndCustomizedTasks = await this.getTasks(token); if (!configuredAndCustomizedTasks.some(t => this.taskDefinitionRegistry.compareTasks(t, task))) { await this.saveTask(scope, { ...task, problemMatcher: [] }); } @@ -458,9 +458,9 @@ export class TaskConfigurations implements Disposable { * @param update the updates to be applied */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - async updateTaskConfig(task: TaskConfiguration, update: { [name: string]: any }): Promise { + async updateTaskConfig(token: number, task: TaskConfiguration, update: { [name: string]: any }): Promise { const scope = task._scope; - const configuredAndCustomizedTasks = await this.getTasks(); + const configuredAndCustomizedTasks = await this.getTasks(token); if (configuredAndCustomizedTasks.some(t => this.taskDefinitionRegistry.compareTasks(t, task))) { // task is already in `tasks.json` const jsonTasks = this.taskConfigurationManager.getTasks(scope); if (jsonTasks) { diff --git a/packages/task/src/browser/task-frontend-contribution.ts b/packages/task/src/browser/task-frontend-contribution.ts index f1dc751d7dd0d..893fa296c2c62 100644 --- a/packages/task/src/browser/task-frontend-contribution.ts +++ b/packages/task/src/browser/task-frontend-contribution.ts @@ -218,7 +218,7 @@ export class TaskFrontendContribution implements CommandContribution, MenuContri { isEnabled: () => true, execute: async (label: string) => { - const didExecute = await this.taskService.runTaskByLabel(label); + const didExecute = await this.taskService.runTaskByLabel(this.taskService.startUserAction(), label); if (!didExecute) { this.quickOpenTask.open(); } @@ -234,7 +234,7 @@ export class TaskFrontendContribution implements CommandContribution, MenuContri execute: (...args: any[]) => { const [source, label, scope] = args; if (source && label) { - return this.taskService.run(source, label, scope); + return this.taskService.run(this.taskService.startUserAction(), source, label, scope); } return this.quickOpenTask.open(); } @@ -269,7 +269,7 @@ export class TaskFrontendContribution implements CommandContribution, MenuContri TaskCommands.TASK_RUN_LAST, { execute: async () => { - if (!await this.taskService.runLastTask()) { + if (!await this.taskService.runLastTask(this.taskService.startUserAction())) { await this.quickOpenTask.open(); } } diff --git a/packages/task/src/browser/task-service.ts b/packages/task/src/browser/task-service.ts index 28781035633de..196e590bff058 100644 --- a/packages/task/src/browser/task-service.ts +++ b/packages/task/src/browser/task-service.ts @@ -332,10 +332,14 @@ export class TaskService implements TaskConfigurationClient { return `${taskName} (${this.labelProvider.getName(new URI(sourceStrUri))})`; } + startUserAction(): number { + return this.providedTaskConfigurations.startUserAction(); + } + /** Returns an array of the task configurations configured in tasks.json and provided by the extensions. */ - async getTasks(): Promise { - const configuredTasks = await this.getConfiguredTasks(); - const providedTasks = await this.getProvidedTasks(); + async getTasks(token: number): Promise { + const configuredTasks = await this.getConfiguredTasks(token); + const providedTasks = await this.getProvidedTasks(token); const notCustomizedProvidedTasks = providedTasks.filter(provided => !configuredTasks.some(configured => this.taskDefinitionRegistry.compareTasks(configured, provided)) ); @@ -343,7 +347,7 @@ export class TaskService implements TaskConfigurationClient { } /** Returns an array of the valid task configurations which are configured in tasks.json files */ - async getConfiguredTasks(): Promise { + async getConfiguredTasks(token: number): Promise { const invalidTaskConfig = this.taskConfigurations.getInvalidTaskConfigurations()[0]; if (invalidTaskConfig) { const widget = await this.widgetManager.getOrCreateWidget(PROBLEMS_WIDGET_ID); @@ -373,13 +377,13 @@ export class TaskService implements TaskConfigurationClient { } } - const validTaskConfigs = await this.taskConfigurations.getTasks(); + const validTaskConfigs = await this.taskConfigurations.getTasks(token); return validTaskConfigs; } /** Returns an array of the task configurations which are provided by the extensions. */ - getProvidedTasks(): Promise { - return this.providedTaskConfigurations.getTasks(); + getProvidedTasks(token: number): Promise { + return this.providedTaskConfigurations.getTasks(token); } addRecentTasks(tasks: TaskConfiguration | TaskConfiguration[]): void { @@ -420,8 +424,8 @@ export class TaskService implements TaskConfigurationClient { * Returns a task configuration provided by an extension by task source and label. * If there are no task configuration, returns undefined. */ - async getProvidedTask(source: string, label: string, scope: TaskConfigurationScope): Promise { - return this.providedTaskConfigurations.getTask(source, label, scope); + async getProvidedTask(token: number, source: string, label: string, scope: TaskConfigurationScope): Promise { + return this.providedTaskConfigurations.getTask(token, source, label, scope); } /** Returns an array of running tasks 'TaskInfo' objects */ @@ -447,38 +451,38 @@ export class TaskService implements TaskConfigurationClient { * Runs a task, by task configuration label. * Note, it looks for a task configured in tasks.json only. */ - async runConfiguredTask(scope: TaskConfigurationScope, taskLabel: string): Promise { + async runConfiguredTask(token: number, scope: TaskConfigurationScope, taskLabel: string): Promise { const task = this.taskConfigurations.getTask(scope, taskLabel); if (!task) { this.logger.error(`Can't get task launch configuration for label: ${taskLabel}`); return; } - this.run(task._source, taskLabel, scope); + this.run(token, task._source, taskLabel, scope); } /** * Run the last executed task. */ - async runLastTask(): Promise { + async runLastTask(token: number): Promise { if (!this.lastTask) { return; } const { source, taskLabel, scope } = this.lastTask; - return this.run(source, taskLabel, scope); + return this.run(token, source, taskLabel, scope); } /** * Runs a task, by the source and label of the task configuration. * It looks for configured and detected tasks. */ - async run(source: string, taskLabel: string, scope: TaskConfigurationScope): Promise { + async run(token: number, source: string, taskLabel: string, scope: TaskConfigurationScope): Promise { let task: TaskConfiguration | undefined; task = this.taskConfigurations.getTask(scope, taskLabel); if (!task) { // if a configured task cannot be found, search from detected tasks - task = await this.getProvidedTask(source, taskLabel, scope); + task = await this.getProvidedTask(token, source, taskLabel, scope); if (!task) { // find from the customized detected tasks - task = await this.taskConfigurations.getCustomizedTask(scope, taskLabel); + task = await this.taskConfigurations.getCustomizedTask(token, scope, taskLabel); } if (!task) { this.logger.error(`Can't get task launch configuration for label: ${taskLabel}`); @@ -504,7 +508,7 @@ export class TaskService implements TaskConfigurationClient { customizationObject.problemMatcher = matcherNames; // write the selected matcher (or the decision of "never parse") into the `tasks.json` - this.updateTaskConfiguration(task, { problemMatcher: matcherNames }); + this.updateTaskConfiguration(token, task, { problemMatcher: matcherNames }); } else if (selected.learnMore) { // user wants to learn more about parsing task output open(this.openerService, new URI('https://code.visualstudio.com/docs/editor/tasks#_processing-task-output-with-problem-matchers')); } @@ -520,7 +524,7 @@ export class TaskService implements TaskConfigurationClient { }; if (task.dependsOn) { - return this.runCompoundTask(task, runTaskOption); + return this.runCompoundTask(token, task, runTaskOption); } else { return this.runTask(task, runTaskOption).catch(error => { console.error('Error at launching task', error); @@ -529,8 +533,8 @@ export class TaskService implements TaskConfigurationClient { } } - async runCompoundTask(task: TaskConfiguration, option?: RunTaskOption): Promise { - const tasks = await this.getWorkspaceTasks(task._scope); + async runCompoundTask(token: number, task: TaskConfiguration, option?: RunTaskOption): Promise { + const tasks = await this.getWorkspaceTasks(token, task._scope); try { const rootNode = new TaskNode(task, [], []); this.detectDirectedAcyclicGraph(task, rootNode, tasks); @@ -785,8 +789,8 @@ export class TaskService implements TaskConfigurationClient { } } - async runTaskByLabel(taskLabel: string): Promise { - const tasks: TaskConfiguration[] = await this.getTasks(); + async runTaskByLabel(token: number, taskLabel: string): Promise { + const tasks: TaskConfiguration[] = await this.getTasks(token); for (const task of tasks) { if (task.label === taskLabel) { return this.runTask(task); @@ -795,8 +799,8 @@ export class TaskService implements TaskConfigurationClient { return; } - async runWorkspaceTask(workspaceFolderUri: string | undefined, taskIdentifier: string | TaskIdentifier): Promise { - const tasks = await this.getWorkspaceTasks(workspaceFolderUri); + async runWorkspaceTask(token: number, workspaceFolderUri: string | undefined, taskIdentifier: string | TaskIdentifier): Promise { + const tasks = await this.getWorkspaceTasks(token, workspaceFolderUri); const task = this.getDependentTask(taskIdentifier, tasks); if (!task) { return undefined; @@ -828,7 +832,7 @@ export class TaskService implements TaskConfigurationClient { * @param update the updates to be applied */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - async updateTaskConfiguration(task: TaskConfiguration, update: { [name: string]: any }): Promise { + async updateTaskConfiguration(token: number, task: TaskConfiguration, update: { [name: string]: any }): Promise { if (update.problemMatcher) { if (Array.isArray(update.problemMatcher)) { update.problemMatcher.forEach((name, index) => { @@ -840,11 +844,11 @@ export class TaskService implements TaskConfigurationClient { update.problemMatcher = `$${update.problemMatcher}`; } } - this.taskConfigurations.updateTaskConfig(task, update); + this.taskConfigurations.updateTaskConfig(token, task, update); } - protected async getWorkspaceTasks(restrictToFolder: TaskConfigurationScope | undefined): Promise { - const tasks = await this.getTasks(); + protected async getWorkspaceTasks(token: number, restrictToFolder: TaskConfigurationScope | undefined): Promise { + const tasks = await this.getTasks(token); // if we pass undefined, return everything, otherwise only tasks with the same uri or workspace/global scope tasks return tasks.filter(t => typeof t._scope !== 'string' || t._scope === restrictToFolder); } @@ -1049,8 +1053,8 @@ export class TaskService implements TaskConfigurationClient { } } - async configure(task: TaskConfiguration): Promise { - await this.taskConfigurations.configure(task); + async configure(token: number, task: TaskConfiguration): Promise { + await this.taskConfigurations.configure(token, task); } protected isEventForThisClient(context: string | undefined): boolean {