@@ -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(
152151const env = prepareEnv ( inheritEnv , runnable . label , runnableArgs , config . runnablesExtraEnv ) ;
153152const executable = await getDebugExecutable ( runnableArgs , env ) ;
154153let sourceFileMap = debugOptions . sourceFileMap ;
154+
155155if ( sourceFileMap === "auto" ) {
156156sourceFileMap = { } ;
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
160174const debugConfig = getDebugConfig (
@@ -189,11 +203,15 @@ async function getDebugConfiguration(
189203return debugConfig ;
190204}
191205
206+ type SourceFileMap = {
207+ source : string ;
208+ destination : string ;
209+ } ;
210+
192211async function discoverSourceFileMap (
193- sourceFileMap : Record < string , string > ,
194212env : Record < string , string > ,
195213cwd : string ,
196- ) {
214+ ) : Promise < SourceFileMap | undefined > {
197215const sysroot = env [ "RUSTC_TOOLCHAIN" ] ;
198216if ( sysroot ) {
199217// let's try to use the default toolchain
@@ -203,9 +221,11 @@ async function discoverSourceFileMap(
203221const commitHash = rx . exec ( data ) ?. [ 1 ] ;
204222if ( commitHash ) {
205223const 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
218238runnableArgsProperty : PropertyFetcher < DebugConfig , ra . CargoRunnableArgs , keyof DebugConfig > ;
219239sourceFileMapProperty ?: keyof DebugConfig ;
220240type : 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" ,
237257runnableArgs . 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" : {
251262type : "lldb" ,
0 commit comments