@@ -36,8 +36,30 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
3636 return this . computeTasks ( ) ;
3737 }
3838
39- resolveTask ( task : vscode . Task ) : vscode . ProviderResult < vscode . Task > {
40- return task ;
39+ async resolveTask ( task : vscode . Task ) : Promise < vscode . Task | undefined > {
40+ this . channel . appendLine ( '++++++++++ RESOLVE TASK ' ) ;
41+
42+ const definition = task . definition as DevfileTaskDefinition ;
43+ if ( ! definition || definition . type !== 'devfile' ) {
44+ return task ;
45+ }
46+
47+ await this . computeTasks ( ) ;
48+
49+ if ( definition . isComposite ) {
50+ const commandId = definition . commandId || this . getCompositeIdFromCommand ( definition . command ) ;
51+ if ( commandId ) {
52+ return this . createCompositeTask ( task . name , commandId ) ;
53+ }
54+ } else if ( definition . commandId ) {
55+ const entry = this . commandById . get ( definition . commandId ) ;
56+ if ( entry ?. kind === 'exec' ) {
57+ return entry . task ;
58+ }
59+ }
60+
61+ const cached = this . tasksCache ?. find ( candidate => candidate . name === task . name ) ;
62+ return cached ?? task ;
4163 }
4264
4365 private async computeTasks ( ) : Promise < vscode . Task [ ] > {
@@ -77,7 +99,7 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
7799 const commandIds = composite ?. commands || [ ] ;
78100 const parallel = Boolean ( composite ?. parallel ) ;
79101 this . commandById . set ( command . id , { kind : 'composite' , name, commandIds, parallel } ) ;
80- return this . createCompositeTask ( name , commandIds , parallel , command . id ) ;
102+ return this . createCompositeTask ( name , command . id ) ;
81103 } ) ;
82104
83105 this . tasksCache = [ ...execTasks , ...compositeTasks ] ;
@@ -139,7 +161,7 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
139161 return task ;
140162 }
141163
142- private createCompositeTask ( name : string , _commandIds : string [ ] , _parallel : boolean , commandId : string ) : vscode . Task {
164+ private createCompositeTask ( name : string , commandId : string ) : vscode . Task {
143165 const kind : DevfileTaskDefinition = {
144166 type : 'devfile' ,
145167 command : `composite:${ commandId } ` ,
@@ -206,6 +228,9 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
206228 activeExecutions : vscode . TaskExecution [ ] ,
207229 write : ( message : string ) => void
208230 ) : Promise < { failed : boolean } > {
231+ if ( this . commandById . size === 0 ) {
232+ await this . computeTasks ( ) ;
233+ }
209234 const entry = this . commandById . get ( commandId ) ;
210235 if ( ! entry || entry . kind !== 'composite' ) {
211236 const message = `Composite task not found: ${ commandId } ` ;
@@ -288,4 +313,11 @@ export class DevfileTaskProvider implements vscode.TaskProvider {
288313 } ) ;
289314 } ) ;
290315 }
316+
317+ private getCompositeIdFromCommand ( command ?: string ) : string | undefined {
318+ if ( ! command ) {
319+ return undefined ;
320+ }
321+ return command . startsWith ( 'composite:' ) ? command . slice ( 'composite:' . length ) : undefined ;
322+ }
291323}
0 commit comments