Skip to content

Commit 325d48f

Browse files
committed
internal: fix lldb-dap unconditionally calling rustc
1 parent e09bf4c commit 325d48f

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

  • src/tools/rust-analyzer/editors/code/src

‎src/tools/rust-analyzer/editors/code/src/debug.ts‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type * as ra from "./lsp_ext";
66
import{Cargo}from"./toolchain";
77
importtype{Ctx}from"./ctx";
88
import{createTaskFromRunnable,prepareEnv}from"./run";
9-
import{execSync}from"node:child_process";
109
import{execute,isCargoRunnableArgs,unwrapUndefinable}from"./util";
1110
importtype{Config}from"./config";
1211

@@ -152,9 +151,24 @@ async function getDebugConfiguration(
152151
constenv=prepareEnv(inheritEnv,runnable.label,runnableArgs,config.runnablesExtraEnv);
153152
constexecutable=awaitgetDebugExecutable(runnableArgs,env);
154153
letsourceFileMap=debugOptions.sourceFileMap;
154+
155155
if(sourceFileMap==="auto"){
156156
sourceFileMap={};
157-
awaitdiscoverSourceFileMap(sourceFileMap,env,wsFolder);
157+
constcomputedSourceFileMap=awaitdiscoverSourceFileMap(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
constdebugConfig=getDebugConfig(
@@ -189,11 +203,15 @@ async function getDebugConfiguration(
189203
returndebugConfig;
190204
}
191205

206+
typeSourceFileMap={
207+
source: string;
208+
destination: string;
209+
};
210+
192211
asyncfunctiondiscoverSourceFileMap(
193-
sourceFileMap: Record<string,string>,
194212
env: Record<string,string>,
195213
cwd: string,
196-
){
214+
): Promise<SourceFileMap|undefined>{
197215
constsysroot=env["RUSTC_TOOLCHAIN"];
198216
if(sysroot){
199217
// let's try to use the default toolchain
@@ -203,9 +221,11 @@ async function discoverSourceFileMap(
203221
constcommitHash=rx.exec(data)?.[1];
204222
if(commitHash){
205223
construstlib=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

211231
typePropertyFetcher<Config,Input,KeyextendskeyofConfig>=(
@@ -218,7 +238,7 @@ type DebugConfigProvider<Type extends string, DebugConfig extends BaseDebugConfi
218238
runnableArgsProperty: PropertyFetcher<DebugConfig,ra.CargoRunnableArgs,keyofDebugConfig>;
219239
sourceFileMapProperty?: keyofDebugConfig;
220240
type: Type;
221-
additional?: Record<string,unknown>;
241+
additional: Record<string,unknown>;
222242
};
223243

224244
typeKnownEnginesType=(typeofknownEngines)[keyoftypeofknownEngines];
@@ -236,16 +256,7 @@ const knownEngines: {
236256
"args",
237257
runnableArgs.executableArgs,
238258
],
239-
additional: {
240-
sourceMap: [
241-
[
242-
`/rustc/${/commit-hash:\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

Comments
 (0)