@@ -121,26 +121,44 @@ export async function makeDebugConfigurations(
121
121
}
122
122
123
123
// Return debug launch configuration for an executable in the given folder
124
- export function getLaunchConfiguration (
124
+ export async function getLaunchConfiguration (
125
125
target : string ,
126
126
folderCtx : FolderContext
127
- ) : vscode . DebugConfiguration | undefined {
127
+ ) : Promise < vscode . DebugConfiguration | undefined > {
128
128
const wsLaunchSection = vscode . workspace . workspaceFile
129
129
? vscode . workspace . getConfiguration ( "launch" )
130
130
: vscode . workspace . getConfiguration ( "launch" , folderCtx . workspaceFolder ) ;
131
131
const launchConfigs = wsLaunchSection . get < vscode . DebugConfiguration [ ] > ( "configurations" ) || [ ] ;
132
132
const { folder } = getFolderAndNameSuffix ( folderCtx ) ;
133
- const targetPath = path . join (
134
- BuildFlags . buildDirectoryFromWorkspacePath ( folder , true ) ,
135
- "debug" ,
136
- target
137
- ) ;
138
- // Users could be on different platforms with different path annotations,
139
- // so normalize before we compare.
140
- const launchConfig = launchConfigs . find (
141
- config => path . normalize ( config . program ) === path . normalize ( targetPath )
142
- ) ;
143
- return launchConfig ;
133
+
134
+ try {
135
+ // Use dynamic path resolution with --show-bin-path
136
+ const binPath = await folderCtx . toolchain . buildFlags . getBuildBinaryPath (
137
+ folderCtx . folder . fsPath ,
138
+ folder ,
139
+ "debug" ,
140
+ folderCtx . workspaceContext . logger
141
+ ) ;
142
+ const targetPath = path . join ( binPath , target ) ;
143
+
144
+ // Users could be on different platforms with different path annotations,
145
+ // so normalize before we compare.
146
+ const launchConfig = launchConfigs . find (
147
+ config => path . normalize ( config . program ) === path . normalize ( targetPath )
148
+ ) ;
149
+ return launchConfig ;
150
+ } catch ( error ) {
151
+ // Fallback to traditional path construction if dynamic resolution fails
152
+ const targetPath = path . join (
153
+ BuildFlags . buildDirectoryFromWorkspacePath ( folder , true ) ,
154
+ "debug" ,
155
+ target
156
+ ) ;
157
+ const launchConfig = launchConfigs . find (
158
+ config => path . normalize ( config . program ) === path . normalize ( targetPath )
159
+ ) ;
160
+ return launchConfig ;
161
+ }
144
162
}
145
163
146
164
// Return array of DebugConfigurations for executables based on what is in Package.swift
@@ -152,30 +170,73 @@ async function createExecutableConfigurations(
152
170
// Windows understand the forward slashes, so make the configuration unified as posix path
153
171
// to make it easier for users switching between platforms.
154
172
const { folder, nameSuffix } = getFolderAndNameSuffix ( ctx , undefined , "posix" ) ;
155
- const buildDirectory = BuildFlags . buildDirectoryFromWorkspacePath ( folder , true , "posix" ) ;
156
173
157
- return executableProducts . flatMap ( product => {
158
- const baseConfig = {
159
- type : SWIFT_LAUNCH_CONFIG_TYPE ,
160
- request : "launch" ,
161
- args : [ ] ,
162
- cwd : folder ,
163
- } ;
164
- return [
165
- {
166
- ...baseConfig ,
167
- name : `Debug ${ product . name } ${ nameSuffix } ` ,
168
- program : path . posix . join ( buildDirectory , "debug" , product . name ) ,
169
- preLaunchTask : `swift: Build Debug ${ product . name } ${ nameSuffix } ` ,
170
- } ,
171
- {
172
- ...baseConfig ,
173
- name : `Release ${ product . name } ${ nameSuffix } ` ,
174
- program : path . posix . join ( buildDirectory , "release" , product . name ) ,
175
- preLaunchTask : `swift: Build Release ${ product . name } ${ nameSuffix } ` ,
176
- } ,
177
- ] ;
178
- } ) ;
174
+ try {
175
+ // Get dynamic build paths for both debug and release configurations
176
+ const [ debugBinPath , releaseBinPath ] = await Promise . all ( [
177
+ ctx . toolchain . buildFlags . getBuildBinaryPath (
178
+ ctx . folder . fsPath ,
179
+ folder ,
180
+ "debug" ,
181
+ ctx . workspaceContext . logger
182
+ ) ,
183
+ ctx . toolchain . buildFlags . getBuildBinaryPath (
184
+ ctx . folder . fsPath ,
185
+ folder ,
186
+ "release" ,
187
+ ctx . workspaceContext . logger
188
+ ) ,
189
+ ] ) ;
190
+
191
+ return executableProducts . flatMap ( product => {
192
+ const baseConfig = {
193
+ type : SWIFT_LAUNCH_CONFIG_TYPE ,
194
+ request : "launch" ,
195
+ args : [ ] ,
196
+ cwd : folder ,
197
+ } ;
198
+ return [
199
+ {
200
+ ...baseConfig ,
201
+ name : `Debug ${ product . name } ${ nameSuffix } ` ,
202
+ program : path . posix . join ( debugBinPath , product . name ) ,
203
+ preLaunchTask : `swift: Build Debug ${ product . name } ${ nameSuffix } ` ,
204
+ } ,
205
+ {
206
+ ...baseConfig ,
207
+ name : `Release ${ product . name } ${ nameSuffix } ` ,
208
+ program : path . posix . join ( releaseBinPath , product . name ) ,
209
+ preLaunchTask : `swift: Build Release ${ product . name } ${ nameSuffix } ` ,
210
+ } ,
211
+ ] ;
212
+ } ) ;
213
+ } catch ( error ) {
214
+ // Fallback to traditional path construction if dynamic resolution fails
215
+ const buildDirectory = BuildFlags . buildDirectoryFromWorkspacePath ( folder , true , "posix" ) ;
216
+
217
+ return executableProducts . flatMap ( product => {
218
+ const baseConfig = {
219
+ type : SWIFT_LAUNCH_CONFIG_TYPE ,
220
+ request : "launch" ,
221
+ args : [ ] ,
222
+ cwd : folder ,
223
+ } ;
224
+ return [
225
+ {
226
+ ...baseConfig ,
227
+ name : `Debug ${ product . name } ${ nameSuffix } ` ,
228
+ program : path . posix . join ( buildDirectory , "debug" , product . name ) ,
229
+ preLaunchTask : `swift: Build Debug ${ product . name } ${ nameSuffix } ` ,
230
+ } ,
231
+ {
232
+ ...baseConfig ,
233
+ name : `Release ${ product . name } ${ nameSuffix } ` ,
234
+ program : path . posix . join ( buildDirectory , "release" , product . name ) ,
235
+ preLaunchTask : `swift: Build Release ${ product . name } ${ nameSuffix } ` ,
236
+ } ,
237
+ ] ;
238
+ } ) ;
239
+ }
179
240
}
180
241
181
242
/**
@@ -184,22 +245,44 @@ async function createExecutableConfigurations(
184
245
* @param ctx Folder context for project
185
246
* @returns Debug configuration for running Swift Snippet
186
247
*/
187
- export function createSnippetConfiguration (
248
+ export async function createSnippetConfiguration (
188
249
snippetName : string ,
189
250
ctx : FolderContext
190
- ) : vscode . DebugConfiguration {
251
+ ) : Promise < vscode . DebugConfiguration > {
191
252
const { folder } = getFolderAndNameSuffix ( ctx ) ;
192
- const buildDirectory = BuildFlags . buildDirectoryFromWorkspacePath ( folder , true ) ;
193
-
194
- return {
195
- type : SWIFT_LAUNCH_CONFIG_TYPE ,
196
- request : "launch" ,
197
- name : `Run ${ snippetName } ` ,
198
- program : path . posix . join ( buildDirectory , "debug" , snippetName ) ,
199
- args : [ ] ,
200
- cwd : folder ,
201
- runType : "snippet" ,
202
- } ;
253
+
254
+ try {
255
+ // Use dynamic path resolution with --show-bin-path
256
+ const binPath = await ctx . toolchain . buildFlags . getBuildBinaryPath (
257
+ ctx . folder . fsPath ,
258
+ folder ,
259
+ "debug" ,
260
+ ctx . workspaceContext . logger
261
+ ) ;
262
+
263
+ return {
264
+ type : SWIFT_LAUNCH_CONFIG_TYPE ,
265
+ request : "launch" ,
266
+ name : `Run ${ snippetName } ` ,
267
+ program : path . posix . join ( binPath , snippetName ) ,
268
+ args : [ ] ,
269
+ cwd : folder ,
270
+ runType : "snippet" ,
271
+ } ;
272
+ } catch ( error ) {
273
+ // Fallback to traditional path construction if dynamic resolution fails
274
+ const buildDirectory = BuildFlags . buildDirectoryFromWorkspacePath ( folder , true ) ;
275
+
276
+ return {
277
+ type : SWIFT_LAUNCH_CONFIG_TYPE ,
278
+ request : "launch" ,
279
+ name : `Run ${ snippetName } ` ,
280
+ program : path . posix . join ( buildDirectory , "debug" , snippetName ) ,
281
+ args : [ ] ,
282
+ cwd : folder ,
283
+ runType : "snippet" ,
284
+ } ;
285
+ }
203
286
}
204
287
205
288
/**
0 commit comments