Skip to content

Commit

Permalink
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 Jul 23, 2019
1 parent 1dc36a0 commit 7f21080
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
25 changes: 16 additions & 9 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,19 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
: { filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredProvidedTasks: 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 candidate = this.findBySourceAndLabel(recent.source, recent.label, configuredTasks) ||
[...configuredTasks, ...providedTasks].find(task => TaskConfiguration.equals(recent, task));

if (candidate && !filteredRecentTasks.some(task => TaskConfiguration.equals(candidate, task))) {
filteredRecentTasks.push(candidate);
}
});
}

const filteredProvidedTasks: TaskConfiguration[] = [];
providedTasks.forEach(provided => {
const exist = [...filteredRecentTasks, ...configuredTasks].some(t => TaskConfiguration.equals(provided, t));
const exist = filteredRecentTasks.some(task =>
TaskConfiguration.equals(provided, task)) || this.findBySourceAndLabel(provided.source, provided.label, configuredTasks);
if (!exist) {
filteredProvidedTasks.push(provided);
}
Expand All @@ -218,6 +221,10 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks
};
}

private findBySourceAndLabel(source: string, label: string, tasks: TaskConfiguration[]): TaskConfiguration | undefined {
return tasks.find(task => !!source && source === task.source && label === task.label);
}
}

export class TaskRunQuickOpenItem extends QuickOpenGroupItem {
Expand All @@ -236,8 +243,8 @@ export class TaskRunQuickOpenItem extends QuickOpenGroupItem {
}

getLabel(): string {
if (ContributedTaskConfiguration.is(this.task)) {
return `${this.task._source}: ${this.task.label}`;
if (this.task.source) {
return `${this.task.source}: ${this.task.label}`;
}
return `${this.task.type}: ${this.task.label}`;
}
Expand Down Expand Up @@ -316,7 +323,7 @@ export class TaskConfigureQuickOpenItem extends QuickOpenGroupItem {

getDescription(): string {
if (this.task._scope) {
return this.labelProvider.getLongName(new URI(this.task._scope));
return new URI(this.task._scope).displayName;
}
return this.task._source;
}
Expand Down
4 changes: 2 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,7 @@ 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(t => Object.assign(t, { _source: this.getSourceFolderFromConfigUri(uri) }));
}
} catch (err) {
console.error(`Error(s) reading config file: ${uri}`);
Expand Down Expand Up @@ -267,7 +267,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
10 changes: 5 additions & 5 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { TERMINAL_WIDGET_FACTORY_ID, TerminalWidgetFactoryOptions } from '@theia
import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
import { MessageService } from '@theia/core/lib/common/message-service';
import { TaskServer, TaskExitedEvent, TaskInfo, TaskConfiguration, ContributedTaskConfiguration } from '../common/task-protocol';
import { TaskServer, TaskExitedEvent, TaskInfo, TaskConfiguration } from '../common/task-protocol';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
import { TaskWatcher } from '../common/task-watcher';
Expand Down Expand Up @@ -114,8 +114,8 @@ export class TaskService implements TaskConfigurationClient {
const task = event.config;
const taskIdentifier =
task
? ContributedTaskConfiguration.is(task)
? `${task._source}: ${task.label}`
? task.source
? `${task.source}: ${task.label}`
: `${task.type}: ${task.label}`
: `${event.taskId}`;
this.messageService.info(`Task ${taskIdentifier} has been started`);
Expand All @@ -131,8 +131,8 @@ export class TaskService implements TaskConfigurationClient {
const taskConfiguration = event.config;
const taskIdentifier =
taskConfiguration
? ContributedTaskConfiguration.is(taskConfiguration)
? `${taskConfiguration._source}: ${taskConfiguration.label}`
? taskConfiguration.source
? `${taskConfiguration.source}: ${taskConfiguration.label}`
: `${taskConfiguration.type}: ${taskConfiguration.label}`
: `${event.taskId}`;

Expand Down

0 comments on commit 7f21080

Please sign in to comment.