@@ -6,7 +6,6 @@ import type * as ra from "./lsp_ext";
6
6
import { Cargo } from "./toolchain" ;
7
7
import type { Ctx } from "./ctx" ;
8
8
import { createTaskFromRunnable , prepareEnv } from "./run" ;
9
- import { execSync } from "node:child_process" ;
10
9
import { execute , isCargoRunnableArgs , unwrapUndefinable } from "./util" ;
11
10
import type { Config } from "./config" ;
12
11
@@ -152,9 +151,24 @@ async function getDebugConfiguration(
152
151
const env = prepareEnv ( inheritEnv , runnable . label , runnableArgs , config . runnablesExtraEnv ) ;
153
152
const executable = await getDebugExecutable ( runnableArgs , env ) ;
154
153
let sourceFileMap = debugOptions . sourceFileMap ;
154
+
155
155
if ( sourceFileMap === "auto" ) {
156
156
sourceFileMap = { } ;
157
- await discoverSourceFileMap ( sourceFileMap , env , wsFolder ) ;
157
+ const computedSourceFileMap = await discoverSourceFileMap ( env , wsFolder ) ;
158
+
159
+ if ( computedSourceFileMap ) {
160
+ // lldb-dap requires passing the source map as an array of two element arrays.
161
+ // the two element array contains a source and destination pathname.
162
+ // TODO: remove lldb-dap-specific post-processing once
163
+ // https://github.com/llvm/llvm-project/pull/106919/ is released in the extension.
164
+ if ( provider . type === "lldb-dap" ) {
165
+ provider . additional [ "sourceMap" ] = [
166
+ [ computedSourceFileMap ?. source , computedSourceFileMap ?. destination ] ,
167
+ ] ;
168
+ } else {
169
+ sourceFileMap [ computedSourceFileMap . source ] = computedSourceFileMap . destination ;
170
+ }
171
+ }
158
172
}
159
173
160
174
const debugConfig = getDebugConfig (
@@ -189,11 +203,15 @@ async function getDebugConfiguration(
189
203
return debugConfig ;
190
204
}
191
205
206
+ type SourceFileMap = {
207
+ source : string ;
208
+ destination : string ;
209
+ } ;
210
+
192
211
async function discoverSourceFileMap (
193
- sourceFileMap : Record < string , string > ,
194
212
env : Record < string , string > ,
195
213
cwd : string ,
196
- ) {
214
+ ) : Promise < SourceFileMap | undefined > {
197
215
const sysroot = env [ "RUSTC_TOOLCHAIN" ] ;
198
216
if ( sysroot ) {
199
217
// let's try to use the default toolchain
@@ -203,9 +221,11 @@ async function discoverSourceFileMap(
203
221
const commitHash = rx . exec ( data ) ?. [ 1 ] ;
204
222
if ( commitHash ) {
205
223
const rustlib = path . normalize ( sysroot + "/lib/rustlib/src/rust" ) ;
206
- sourceFileMap [ `/rustc/ ${ commitHash } /` ] = rustlib ;
224
+ return { source : rustlib , destination : rustlib } ;
207
225
}
208
226
}
227
+
228
+ return ;
209
229
}
210
230
211
231
type PropertyFetcher < Config , Input , Key extends keyof Config > = (
@@ -218,7 +238,7 @@ type DebugConfigProvider<Type extends string, DebugConfig extends BaseDebugConfi
218
238
runnableArgsProperty : PropertyFetcher < DebugConfig , ra . CargoRunnableArgs , keyof DebugConfig > ;
219
239
sourceFileMapProperty ?: keyof DebugConfig ;
220
240
type : Type ;
221
- additional ? : Record < string , unknown > ;
241
+ additional : Record < string , unknown > ;
222
242
} ;
223
243
224
244
type KnownEnginesType = ( typeof knownEngines ) [ keyof typeof knownEngines ] ;
@@ -236,16 +256,7 @@ const knownEngines: {
236
256
"args" ,
237
257
runnableArgs . executableArgs ,
238
258
] ,
239
- additional : {
240
- sourceMap : [
241
- [
242
- `/rustc/${ / c o m m i t - h a s h : \s ( .* ) $ / m. exec (
243
- execSync ( "rustc -V -v" , { } ) . toString ( ) ,
244
- ) ?. [ 1 ] } /library`,
245
- "${config:rust-analyzer.cargo.sysroot}/lib/rustlib/src/rust/library" ,
246
- ] ,
247
- ] ,
248
- } ,
259
+ additional : { } ,
249
260
} ,
250
261
"vadimcn.vscode-lldb" : {
251
262
type : "lldb" ,
0 commit comments