Skip to content

Commit

Permalink
[tasks] Fix execution of Configured tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Jun 27, 2019
1 parent deec2c4 commit e08f734
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
42 changes: 23 additions & 19 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
async init(): Promise<void> {
const recentTasks = this.taskService.recentTasks;
const configuredTasks = this.taskService.getConfiguredTasks();
const providedTasks = await this.taskService.getProvidedTasks();
const detectedTasks = await this.taskService.getProvidedTasks();

const { filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, providedTasks);
const { filteredRecentTasks, filteredConfiguredTasks, filteredDetectedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, detectedTasks);
const stat = this.workspaceService.workspace;
const isMulti = stat ? !stat.isDirectory : false;
this.items = [];
Expand All @@ -84,7 +84,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
: index === 0 ? true : false
)
})),
...filteredProvidedTasks.map((task, index) =>
...filteredDetectedTasks.map((task, index) =>
new TaskRunQuickOpenItem(task, this.taskService, isMulti, {
groupLabel: index === 0 ? 'detected tasks' : undefined,
showBorder: (
Expand Down Expand Up @@ -187,36 +187,40 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
return `Task id: ${task.taskId}, label: ${task.config.label}`;
}

private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], providedTasks: TaskConfiguration[])
: { filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredProvidedTasks: TaskConfiguration[] } {
private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], detectedTasks: TaskConfiguration[])
: { filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredDetectedTasks: TaskConfiguration[] } {

const filteredRecentTasks: TaskConfiguration[] = [];
recentTasks.forEach(recent => {
const exist = [...configuredTasks, ...providedTasks].some(t => TaskConfiguration.equals(recent, t));
if (exist) {
filteredRecentTasks.push(recent);
for (const recent of recentTasks) {
const taskConfig = configuredTasks.find(task => recent.label === task.label) || detectedTasks.find(task => TaskConfiguration.equals(task, recent));
if (!taskConfig) {
continue;
}
});

const filteredProvidedTasks: TaskConfiguration[] = [];
providedTasks.forEach(provided => {
const exist = [...filteredRecentTasks, ...configuredTasks].some(t => TaskConfiguration.equals(provided, t));
const exist = filteredRecentTasks.some(task => TaskConfiguration.equals(task, taskConfig));
if (!exist) {
filteredProvidedTasks.push(provided);
filteredRecentTasks.push(taskConfig);
}
});
}

const filteredConfiguredTasks: TaskConfiguration[] = [];
configuredTasks.forEach(configured => {
const exist = filteredRecentTasks.some(t => TaskConfiguration.equals(configured, t));
const exist = filteredRecentTasks.some(recent => TaskConfiguration.equals(configured, recent));
if (!exist) {
filteredConfiguredTasks.push(configured);
}
});

return {
filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks
};
const filteredDetectedTasks: TaskConfiguration[] = [];
detectedTasks.forEach(detected => {
const exist = filteredRecentTasks.some(recent => TaskConfiguration.equals(detected, recent)) ||
configuredTasks.some(configured => configured.label === detected.label);
if (!exist) {
filteredDetectedTasks.push(detected);
}
});

return { filteredRecentTasks, filteredConfiguredTasks, filteredDetectedTasks };
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/task/src/browser/task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ export class TaskConfigurations implements Disposable {
console.error(`Error parsing ${uri}: error: ${e.error}, length: ${e.length}, offset: ${e.offset}`);
}
} else {
return this.filterDuplicates(tasks['tasks']).map(t => Object.assign(t, { _source: t.source || this.getSourceFolderFromConfigUri(uri) }));
return this.filterDuplicates(tasks['tasks']).map(task => {
const { _source, _scope, ...configuration } = task;
return { ...configuration, _source: this.getSourceFolderFromConfigUri(uri) };
});
}
} catch (err) {
console.error(`Error(s) reading config file: ${uri}`);
Expand Down Expand Up @@ -267,7 +270,7 @@ export class TaskConfigurations implements Disposable {
await this.fileSystem.createFile(configFileUri);
}

const { _source, $ident, ...preparedTask } = task;
const { _source, _scope, $ident, ...preparedTask } = task;
try {
const response = await this.fileSystem.resolveContent(configFileUri);
const content = response.content;
Expand Down

0 comments on commit e08f734

Please sign in to comment.