@@ -111,6 +111,21 @@ function getBuildRevealOption(): vscode.TaskRevealKind {
111
111
: vscode . TaskRevealKind . Never ;
112
112
}
113
113
114
+ const buildAllTaskCache = ( ( ) => {
115
+ const cache = new Map < string , vscode . Task > ( ) ;
116
+ const key = ( name : string , folderContext : FolderContext ) => {
117
+ return `${ name } :${ buildOptions ( folderContext . workspaceContext . toolchain ) . join ( "," ) } ` ;
118
+ } ;
119
+ return {
120
+ get ( name : string , folderContext : FolderContext ) : vscode . Task | undefined {
121
+ return cache . get ( key ( name , folderContext ) ) ;
122
+ } ,
123
+ set ( name : string , folderContext : FolderContext , task : vscode . Task ) {
124
+ cache . set ( key ( name , folderContext ) , task ) ;
125
+ } ,
126
+ } ;
127
+ } ) ( ) ;
128
+
114
129
/**
115
130
* Creates a {@link vscode.Task Task} to build all targets in this package.
116
131
*/
@@ -127,7 +142,16 @@ export function createBuildAllTask(folderContext: FolderContext): vscode.Task {
127
142
if ( folderContext . workspaceContext . toolchain . buildFlags . getDarwinTarget ( ) === undefined ) {
128
143
additionalArgs = [ "--build-tests" , ...additionalArgs ] ;
129
144
}
130
- return createSwiftTask (
145
+
146
+ // Create one Build All task per folder context, since this can be called multiple
147
+ // times and we want the same instance each time. Otherwise, VSCode may try and execute
148
+ // one instance while our extension code tries to listen to events on an instance created earlier/later.
149
+ const existingTask = buildAllTaskCache . get ( buildTaskName , folderContext ) ;
150
+ if ( existingTask ) {
151
+ return existingTask ;
152
+ }
153
+
154
+ const task = createSwiftTask (
131
155
[ "build" , ...additionalArgs ] ,
132
156
buildTaskName ,
133
157
{
@@ -143,6 +167,8 @@ export function createBuildAllTask(folderContext: FolderContext): vscode.Task {
143
167
} ,
144
168
folderContext . workspaceContext . toolchain
145
169
) ;
170
+ buildAllTaskCache . set ( buildTaskName , folderContext , task ) ;
171
+ return task ;
146
172
}
147
173
148
174
/**
@@ -206,10 +232,13 @@ function createBuildTasks(product: Product, folderContext: FolderContext): vscod
206
232
if ( folderContext . relativePath . length > 0 ) {
207
233
buildTaskNameSuffix = ` (${ folderContext . relativePath } )` ;
208
234
}
209
- return [
210
- createSwiftTask (
235
+
236
+ const buildDebugName = `Build Debug ${ product . name } ${ buildTaskNameSuffix } ` ;
237
+ let buildDebug = buildAllTaskCache . get ( buildDebugName , folderContext ) ;
238
+ if ( ! buildDebug ) {
239
+ buildDebug = createSwiftTask (
211
240
[ "build" , "--product" , product . name , ...buildOptions ( toolchain ) ] ,
212
- `Build Debug ${ product . name } ${ buildTaskNameSuffix } ` ,
241
+ buildDebugName ,
213
242
{
214
243
group : vscode . TaskGroup . Build ,
215
244
cwd : folderContext . folder ,
@@ -223,8 +252,14 @@ function createBuildTasks(product: Product, folderContext: FolderContext): vscod
223
252
showBuildStatus : configuration . showBuildStatus ,
224
253
} ,
225
254
folderContext . workspaceContext . toolchain
226
- ) ,
227
- createSwiftTask (
255
+ ) ;
256
+ buildAllTaskCache . set ( buildDebugName , folderContext , buildDebug ) ;
257
+ }
258
+
259
+ const buildReleaseName = `Build Release ${ product . name } ${ buildTaskNameSuffix } ` ;
260
+ let buildRelease = buildAllTaskCache . get ( buildReleaseName , folderContext ) ;
261
+ if ( ! buildRelease ) {
262
+ buildRelease = createSwiftTask (
228
263
[ "build" , "-c" , "release" , "--product" , product . name , ...configuration . buildArguments ] ,
229
264
`Build Release ${ product . name } ${ buildTaskNameSuffix } ` ,
230
265
{
@@ -240,8 +275,11 @@ function createBuildTasks(product: Product, folderContext: FolderContext): vscod
240
275
showBuildStatus : configuration . showBuildStatus ,
241
276
} ,
242
277
folderContext . workspaceContext . toolchain
243
- ) ,
244
- ] ;
278
+ ) ;
279
+ buildAllTaskCache . set ( buildReleaseName , folderContext , buildRelease ) ;
280
+ }
281
+
282
+ return [ buildDebug , buildRelease ] ;
245
283
}
246
284
247
285
/**
0 commit comments