Skip to content

Commit 57775aa

Browse files
fix rerun, add logs
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent a029c72 commit 57775aa

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

code/extensions/che-commands/src/taskProvider.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface DevfileTaskDefinition extends vscode.TaskDefinition {
2121
}
2222

2323
export class DevfileTaskProvider implements vscode.TaskProvider {
24+
private cachedTaskMap: Map<string, vscode.Task> | undefined;
2425

2526
constructor(private channel: vscode.OutputChannel, private cheAPI: any, private terminalExtAPI: any) {
2627
}
@@ -63,7 +64,9 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
6364
command.id
6465
));
6566

66-
return [...execTasks, ...compositeTasks];
67+
const tasks = [...execTasks, ...compositeTasks];
68+
this.cachedTaskMap = this.buildTaskMap(tasks);
69+
return tasks;
6770
}
6871

6972
private async fetchDevfileCommands(): Promise<V1alpha2DevWorkspaceSpecTemplateCommands[]> {
@@ -171,20 +174,18 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
171174
writeEmitter: vscode.EventEmitter<string>,
172175
activeExecutions: vscode.TaskExecution[]
173176
): Promise<{ failed: boolean }> {
174-
const tasks = await vscode.tasks.fetchTasks({ type: 'devfile' });
175-
const taskMap = new Map<string, vscode.Task>();
176-
177-
for (const task of tasks) {
178-
const def = task.definition as DevfileTaskDefinition;
179-
if (def?.commandId && !def.command.startsWith('composite:')) {
180-
taskMap.set(def.commandId, task);
181-
}
182-
taskMap.set(task.name, task);
183-
}
177+
const taskMap = await this.getTaskMap();
178+
const availableKeys = Array.from(taskMap.keys()).sort();
179+
writeEmitter.fire(`Composite diagnostics: available tasks: ${availableKeys.join(', ')}\r\n`);
180+
this.channel.appendLine(`Composite diagnostics: available tasks: ${availableKeys.join(', ')}`);
181+
writeEmitter.fire(`Composite diagnostics: requested commands: ${commandIds.join(', ')}\r\n`);
182+
this.channel.appendLine(`Composite diagnostics: requested commands: ${commandIds.join(', ')}`);
184183

185184
const targetTasks = commandIds
186185
.map(id => taskMap.get(id))
187186
.filter((task): task is vscode.Task => Boolean(task));
187+
writeEmitter.fire(`Composite diagnostics: resolved tasks: ${targetTasks.map(task => task.name).join(', ') || '(none)'}\r\n`);
188+
this.channel.appendLine(`Composite diagnostics: resolved tasks: ${targetTasks.map(task => task.name).join(', ') || '(none)'}`);
188189

189190
const missing = commandIds.filter(id => !taskMap.has(id));
190191
if (missing.length) {
@@ -267,4 +268,25 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
267268
});
268269
});
269270
}
271+
272+
private buildTaskMap(tasks: vscode.Task[]): Map<string, vscode.Task> {
273+
const taskMap = new Map<string, vscode.Task>();
274+
for (const task of tasks) {
275+
const def = task.definition as DevfileTaskDefinition;
276+
if (def?.commandId && !def.command.startsWith('composite:')) {
277+
taskMap.set(def.commandId, task);
278+
}
279+
taskMap.set(task.name, task);
280+
}
281+
return taskMap;
282+
}
283+
284+
private async getTaskMap(): Promise<Map<string, vscode.Task>> {
285+
if (this.cachedTaskMap) {
286+
return this.cachedTaskMap;
287+
}
288+
const tasks = await vscode.tasks.fetchTasks({ type: 'devfile' });
289+
this.cachedTaskMap = this.buildTaskMap(tasks);
290+
return this.cachedTaskMap;
291+
}
270292
}

0 commit comments

Comments
 (0)