@@ -6,7 +6,6 @@ import type * as ra from "./lsp_ext";
66import { Cargo } from "./toolchain" ;
77import type { Ctx } from "./ctx" ;
88import { createTaskFromRunnable , prepareEnv } from "./run" ;
9- import { execSync } from "node:child_process" ;
109import { execute , isCargoRunnableArgs , unwrapUndefinable } from "./util" ;
1110import type { Config } from "./config" ;
1211
@@ -152,9 +151,24 @@ async function getDebugConfiguration(
152151 const env = prepareEnv ( inheritEnv , runnable . label , runnableArgs , config . runnablesExtraEnv ) ;
153152 const executable = await getDebugExecutable ( runnableArgs , env ) ;
154153 let sourceFileMap = debugOptions . sourceFileMap ;
154+
155155 if ( sourceFileMap === "auto" ) {
156156 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+ }
158172 }
159173
160174 const debugConfig = getDebugConfig (
@@ -189,11 +203,15 @@ async function getDebugConfiguration(
189203 return debugConfig ;
190204}
191205
206+ type SourceFileMap = {
207+ source : string ;
208+ destination : string ;
209+ } ;
210+
192211async function discoverSourceFileMap (
193- sourceFileMap : Record < string , string > ,
194212 env : Record < string , string > ,
195213 cwd : string ,
196- ) {
214+ ) : Promise < SourceFileMap | undefined > {
197215 const sysroot = env [ "RUSTC_TOOLCHAIN" ] ;
198216 if ( sysroot ) {
199217 // let's try to use the default toolchain
@@ -203,9 +221,11 @@ async function discoverSourceFileMap(
203221 const commitHash = rx . exec ( data ) ?. [ 1 ] ;
204222 if ( commitHash ) {
205223 const rustlib = path . normalize ( sysroot + "/lib/rustlib/src/rust" ) ;
206- sourceFileMap [ `/rustc/ ${ commitHash } /` ] = rustlib ;
224+ return { source : rustlib , destination : rustlib } ;
207225 }
208226 }
227+
228+ return ;
209229}
210230
211231type PropertyFetcher < Config , Input , Key extends keyof Config > = (
@@ -218,7 +238,7 @@ type DebugConfigProvider<Type extends string, DebugConfig extends BaseDebugConfi
218238 runnableArgsProperty : PropertyFetcher < DebugConfig , ra . CargoRunnableArgs , keyof DebugConfig > ;
219239 sourceFileMapProperty ?: keyof DebugConfig ;
220240 type : Type ;
221- additional ? : Record < string , unknown > ;
241+ additional : Record < string , unknown > ;
222242} ;
223243
224244type KnownEnginesType = ( typeof knownEngines ) [ keyof typeof knownEngines ] ;
@@ -236,16 +256,7 @@ const knownEngines: {
236256 "args" ,
237257 runnableArgs . executableArgs ,
238258 ] ,
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 : { } ,
249260 } ,
250261 "vadimcn.vscode-lldb" : {
251262 type : "lldb" ,
0 commit comments