about summary refs log tree commit diff
path: root/editors/code/src/debug.ts
diff options
context:
space:
mode:
authorLaurențiu Nicola <lnicola@dend.ro>2023-12-04 09:19:15 +0200
committerLaurențiu Nicola <lnicola@dend.ro>2023-12-04 09:19:15 +0200
commit30fc9329d1c1afb023bf80bea08a243e3b6ef1b2 (patch)
treeeb348153e54920a221ff44171feb88fc7f0c1eef /editors/code/src/debug.ts
parent40da288eb040ac44e6de6d670ff8155b69706080 (diff)
downloadrust-30fc9329d1c1afb023bf80bea08a243e3b6ef1b2.tar.gz
rust-30fc9329d1c1afb023bf80bea08a243e3b6ef1b2.zip
Merge commit 'e402c494b7c7d94a37c6d789a216187aaf9ccd3e' into sync-from-ra
Diffstat (limited to 'editors/code/src/debug.ts')
-rw-r--r--editors/code/src/debug.ts27
1 files changed, 18 insertions, 9 deletions
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index e817d680eae..06034e16480 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -3,7 +3,7 @@ import * as vscode from "vscode";
 import * as path from "path";
 import type * as ra from "./lsp_ext";
 
-import { Cargo, getRustcId, getSysroot } from "./toolchain";
+import { Cargo, type ExecutableInfo, getRustcId, getSysroot } from "./toolchain";
 import type { Ctx } from "./ctx";
 import { prepareEnv } from "./run";
 import { unwrapUndefinable } from "./undefinable";
@@ -12,6 +12,7 @@ const debugOutput = vscode.window.createOutputChannel("Debug");
 type DebugConfigProvider = (
     config: ra.Runnable,
     executable: string,
+    cargoWorkspace: string,
     env: Record<string, string>,
     sourceFileMap?: Record<string, string>,
 ) => vscode.DebugConfiguration;
@@ -130,7 +131,7 @@ async function getDebugConfiguration(
     }
 
     const env = prepareEnv(runnable, ctx.config.runnablesExtraEnv);
-    const executable = await getDebugExecutable(runnable, env);
+    const { executable, workspace: cargoWorkspace } = await getDebugExecutableInfo(runnable, env);
     let sourceFileMap = debugOptions.sourceFileMap;
     if (sourceFileMap === "auto") {
         // let's try to use the default toolchain
@@ -142,7 +143,13 @@ async function getDebugConfiguration(
     }
 
     const provider = unwrapUndefinable(knownEngines[debugEngine.id]);
-    const debugConfig = provider(runnable, simplifyPath(executable), env, sourceFileMap);
+    const debugConfig = provider(
+        runnable,
+        simplifyPath(executable),
+        cargoWorkspace,
+        env,
+        sourceFileMap,
+    );
     if (debugConfig.type in debugOptions.engineSettings) {
         const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type];
         for (var key in settingsMap) {
@@ -164,20 +171,21 @@ async function getDebugConfiguration(
     return debugConfig;
 }
 
-async function getDebugExecutable(
+async function getDebugExecutableInfo(
     runnable: ra.Runnable,
     env: Record<string, string>,
-): Promise<string> {
+): Promise<ExecutableInfo> {
     const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput, env);
-    const executable = await cargo.executableFromArgs(runnable.args.cargoArgs);
+    const executableInfo = await cargo.executableInfoFromArgs(runnable.args.cargoArgs);
 
     // if we are here, there were no compilation errors.
-    return executable;
+    return executableInfo;
 }
 
 function getLldbDebugConfig(
     runnable: ra.Runnable,
     executable: string,
+    cargoWorkspace: string,
     env: Record<string, string>,
     sourceFileMap?: Record<string, string>,
 ): vscode.DebugConfiguration {
@@ -187,7 +195,7 @@ function getLldbDebugConfig(
         name: runnable.label,
         program: executable,
         args: runnable.args.executableArgs,
-        cwd: runnable.args.workspaceRoot,
+        cwd: cargoWorkspace || runnable.args.workspaceRoot,
         sourceMap: sourceFileMap,
         sourceLanguages: ["rust"],
         env,
@@ -197,6 +205,7 @@ function getLldbDebugConfig(
 function getCppvsDebugConfig(
     runnable: ra.Runnable,
     executable: string,
+    cargoWorkspace: string,
     env: Record<string, string>,
     sourceFileMap?: Record<string, string>,
 ): vscode.DebugConfiguration {
@@ -206,7 +215,7 @@ function getCppvsDebugConfig(
         name: runnable.label,
         program: executable,
         args: runnable.args.executableArgs,
-        cwd: runnable.args.workspaceRoot,
+        cwd: cargoWorkspace || runnable.args.workspaceRoot,
         sourceFileMap,
         env,
     };